Add PenaltyBot._check_message_spam

This commit is contained in:
AlberLC
2025-03-17 10:05:27 +01:00
parent aa6642ea26
commit 37db1b3590
2 changed files with 45 additions and 26 deletions

View File

@@ -86,14 +86,33 @@ class PenaltyBot(MultiBot, ABC):
'text': message.text,
'platform': self.platform.value,
'author': message.author.object_id,
'date': {'$gte': datetime.datetime.now(datetime.timezone.utc) - constants.SPAM_TIME_RANGE}
'date': {'$gte': datetime.datetime.now(datetime.timezone.utc) - constants.SPAM_TIME_RANGE},
})
chats = {message.chat for message in spam_messages}
if len(chats) > constants.SPAM_CHANNELS_LIMIT:
if len(chats) <= constants.SPAM_CHANNELS_LIMIT:
return False
await self.punish(message.author.id, message.chat.group_id)
await asyncio.sleep(constants.SPAM_DELETION_DELAY.total_seconds()) # We make sure to also delete any messages they may have sent before the punishment
spam_messages = self.Message.find({
'text': message.text,
'platform': self.platform.value,
'author': message.author.object_id,
'date': {
'$gte': datetime.datetime.now(datetime.timezone.utc)
-
constants.SPAM_TIME_RANGE
-
constants.SPAM_DELETION_DELAY
},
'is_deleted': False
})
chats = {message.chat for message in spam_messages}
for message in spam_messages:
await self.delete_message(await self.get_message(message.id, message.chat.id))
await self.punish(message.author.id, message.chat.group_id)
groups_data = {chat.group_id: chat.group_name for chat in chats}
owner_message_parts = [
'<b>Spammer castigado:</b>',
@@ -113,9 +132,8 @@ class PenaltyBot(MultiBot, ABC):
)
]
await self.send('\n'.join(owner_message_parts), await self.owner_chat)
return True
return False
return True
async def _punish(self, user: int | str | User, group_: int | str | Chat | Message, message: Message = None):
pass

View File

@@ -24,6 +24,7 @@ PUNISHMENTS_RESET_TIME = datetime.timedelta(weeks=2)
RECOVERY_DELETED_MESSAGE_BEFORE = datetime.timedelta(hours=1)
SCRAPING_TIMEOUT_SECONDS = 10
SPAM_CHANNELS_LIMIT = 2
SPAM_DELETION_DELAY = datetime.timedelta(seconds=5)
SPAM_TIME_RANGE = datetime.timedelta(hours=1)
STEAM_ALL_APPS_ENDPOINT = 'https://api.steampowered.com/ISteamApps/GetAppList/v2'
STEAM_APP_ENDPOINT_TEMPLATE = 'https://store.steampowered.com/api/appdetails?appids={ids}&cc={country_code}&filters=price_overview'