From aa6642ea26355556fef5a99d539a12512fea8845 Mon Sep 17 00:00:00 2001 From: AlberLC Date: Mon, 17 Mar 2025 09:05:01 +0100 Subject: [PATCH] Add PenaltyBot._check_message_spam --- flanabot/bots/penalty_bot.py | 17 +++++++++-------- flanabot/constants.py | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/flanabot/bots/penalty_bot.py b/flanabot/bots/penalty_bot.py index 3cdce46..cc81d85 100644 --- a/flanabot/bots/penalty_bot.py +++ b/flanabot/bots/penalty_bot.py @@ -86,7 +86,7 @@ class PenaltyBot(MultiBot, ABC): 'text': message.text, 'platform': self.platform.value, 'author': message.author.object_id, - 'date': {'$gte': datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(hours=1)} + 'date': {'$gte': datetime.datetime.now(datetime.timezone.utc) - constants.SPAM_TIME_RANGE} }) chats = {message.chat for message in spam_messages} @@ -94,21 +94,22 @@ class PenaltyBot(MultiBot, ABC): 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 = [ - 'Castigado spammer:', + 'Spammer castigado:', 'User:', f' id: {message.author.id}', f' name: {message.author.name}', f' is_admin: {message.author.is_admin}', f' is_bot: {message.author.is_bot}', '', - 'Chats:', + f'Chats: {len(chats)}', + '', + 'Groups:', '\n\n'.join( - f' id: {chat.id}\n' - f' name: {chat.name}\n' - f' group_id: {chat.group_id}\n' - f' group_name: {chat.group_name}' - for chat in chats + f' group_id: {group_id}\n' + f' group_name: {group_name}' + for group_id, group_name in groups_data.items() ) ] await self.send('\n'.join(owner_message_parts), await self.owner_chat) diff --git a/flanabot/constants.py b/flanabot/constants.py index 75c219b..63cf891 100644 --- a/flanabot/constants.py +++ b/flanabot/constants.py @@ -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_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' STEAM_APP_IDS_FOR_SCRAPE_COUNTRIES = (400, 620, 730, 210970, 252490, 292030, 427520, 1712350)