Refactor new models import

This commit is contained in:
AlberLC
2022-10-29 06:15:32 +02:00
parent 16a009fe9a
commit 496b4e0898

View File

@@ -25,8 +25,8 @@ from flanabot.models import Chat, Message, Punishment, WeatherChart
# --------------------------------------------- FLANA_BOT --------------------------------------------- # # --------------------------------------------- FLANA_BOT --------------------------------------------- #
# ----------------------------------------------------------------------------------------------------- # # ----------------------------------------------------------------------------------------------------- #
class FlanaBot(MultiBot, ABC): class FlanaBot(MultiBot, ABC):
_Chat = Chat Chat = Chat
_Message = Message Message = Message
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@@ -112,13 +112,13 @@ class FlanaBot(MultiBot, ABC):
if await self.is_punished(message.author, message.chat): if await self.is_punished(message.author, message.chat):
return return
last_2s_messages = self._Message.find({ last_2s_messages = self.Message.find({
'platform': self.platform.value, 'platform': self.platform.value,
'author': message.author.object_id, 'author': message.author.object_id,
'chat': message.chat.object_id, 'chat': message.chat.object_id,
'date': {'$gte': datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(seconds=2)} 'date': {'$gte': datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(seconds=2)}
}) })
last_7s_messages = self._Message.find({ last_7s_messages = self.Message.find({
'platform': self.platform.value, 'platform': self.platform.value,
'author': message.author.object_id, 'author': message.author.object_id,
'chat': message.chat.object_id, 'chat': message.chat.object_id,
@@ -165,7 +165,7 @@ class FlanaBot(MultiBot, ABC):
and and
flanautils.cartesian_product_string_matching(message.text, constants.KEYWORDS['poll'], min_ratio=multibot_constants.PARSE_CALLBACKS_MIN_RATIO_DEFAULT) flanautils.cartesian_product_string_matching(message.text, constants.KEYWORDS['poll'], min_ratio=multibot_constants.PARSE_CALLBACKS_MIN_RATIO_DEFAULT)
and and
(poll_message := self._Message.find_one({'contents.poll.is_active': True}, sort_keys=(('date', pymongo.DESCENDING),))) (poll_message := self.Message.find_one({'contents.poll.is_active': True}, sort_keys=(('date', pymongo.DESCENDING),)))
): ):
return await self.get_message(poll_message.chat.id, poll_message.id) return await self.get_message(poll_message.chat.id, poll_message.id)
else: else:
@@ -550,7 +550,7 @@ class FlanaBot(MultiBot, ABC):
return return
affected_object_ids = [affected_message_object_id for affected_message_object_id in message_deleted_bot_action.affected_objects] affected_object_ids = [affected_message_object_id for affected_message_object_id in message_deleted_bot_action.affected_objects]
deleted_messages: list[Message] = [affected_message for affected_object_id in affected_object_ids if (affected_message := self._Message.find_one({'platform': self.platform.value, '_id': affected_object_id})).author.id != self.id] deleted_messages: list[Message] = [affected_message for affected_object_id in affected_object_ids if (affected_message := self.Message.find_one({'platform': self.platform.value, '_id': affected_object_id})).author.id != self.id]
for deleted_message in deleted_messages: for deleted_message in deleted_messages:
await self.send(deleted_message.text, message) await self.send(deleted_message.text, message)