diff --git a/flanabot/bots/flana_bot.py b/flanabot/bots/flana_bot.py index 1c7ffdc..52c1a83 100644 --- a/flanabot/bots/flana_bot.py +++ b/flanabot/bots/flana_bot.py @@ -3,6 +3,7 @@ __all__ = ['FlanaBot'] import asyncio import datetime import random +import time from abc import ABC from typing import Iterable @@ -34,6 +35,7 @@ class FlanaBot(Connect4Bot, PenaltyBot, PollBot, ScraperBot, UberEatsBot, Weathe super().__init__(*args, **kwargs) self.tunnel_chat = None self.owner_chat = None + self.help_calls = {} # -------------------------------------------------------- # # ------------------- PROTECTED METHODS ------------------ # @@ -257,9 +259,20 @@ class FlanaBot(Connect4Bot, PenaltyBot, PollBot, ScraperBot, UberEatsBot, Weathe await self.send_hello(message) async def _on_help(self, message: Message): - if message.chat.is_group and not self.is_bot_mentioned(message): + now = datetime.timedelta(seconds=time.time()) + if ( + message.chat.is_group + and + not self.is_bot_mentioned(message) + or + self.help_calls.get(message.chat.id) + and + now - self.help_calls[message.chat.id] <= datetime.timedelta(minutes=1) + ): return + self.help_calls[message.chat.id] = now + if not self.owner_chat: self.owner_chat = await self.get_chat(self.owner_id) or await self.get_chat(await self.get_user(self.owner_id)) diff --git a/flanabot/constants.py b/flanabot/constants.py index 2ea17b0..39c006a 100644 --- a/flanabot/constants.py +++ b/flanabot/constants.py @@ -14,6 +14,7 @@ CONNECT_4_N_ROWS = 6 FLOOD_2s_LIMIT = 2 FLOOD_7s_LIMIT = 4 HEAT_PERIOD_SECONDS = datetime.timedelta(minutes=15).total_seconds() +HELP_MINUTES_LIMIT = 1 INSULT_PROBABILITY = 0.00166666667 MAX_PLACE_QUERY_LENGTH = 50 PUNISHMENT_INCREMENT_EXPONENT = 6