Add FlanaBot._on_help antiflood
This commit is contained in:
@@ -3,6 +3,7 @@ __all__ = ['FlanaBot']
|
|||||||
import asyncio
|
import asyncio
|
||||||
import datetime
|
import datetime
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ class FlanaBot(Connect4Bot, PenaltyBot, PollBot, ScraperBot, UberEatsBot, Weathe
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.tunnel_chat = None
|
self.tunnel_chat = None
|
||||||
self.owner_chat = None
|
self.owner_chat = None
|
||||||
|
self.help_calls = {}
|
||||||
|
|
||||||
# -------------------------------------------------------- #
|
# -------------------------------------------------------- #
|
||||||
# ------------------- PROTECTED METHODS ------------------ #
|
# ------------------- PROTECTED METHODS ------------------ #
|
||||||
@@ -257,9 +259,20 @@ class FlanaBot(Connect4Bot, PenaltyBot, PollBot, ScraperBot, UberEatsBot, Weathe
|
|||||||
await self.send_hello(message)
|
await self.send_hello(message)
|
||||||
|
|
||||||
async def _on_help(self, message: 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
|
return
|
||||||
|
|
||||||
|
self.help_calls[message.chat.id] = now
|
||||||
|
|
||||||
if not self.owner_chat:
|
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))
|
self.owner_chat = await self.get_chat(self.owner_id) or await self.get_chat(await self.get_user(self.owner_id))
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ CONNECT_4_N_ROWS = 6
|
|||||||
FLOOD_2s_LIMIT = 2
|
FLOOD_2s_LIMIT = 2
|
||||||
FLOOD_7s_LIMIT = 4
|
FLOOD_7s_LIMIT = 4
|
||||||
HEAT_PERIOD_SECONDS = datetime.timedelta(minutes=15).total_seconds()
|
HEAT_PERIOD_SECONDS = datetime.timedelta(minutes=15).total_seconds()
|
||||||
|
HELP_MINUTES_LIMIT = 1
|
||||||
INSULT_PROBABILITY = 0.00166666667
|
INSULT_PROBABILITY = 0.00166666667
|
||||||
MAX_PLACE_QUERY_LENGTH = 50
|
MAX_PLACE_QUERY_LENGTH = 50
|
||||||
PUNISHMENT_INCREMENT_EXPONENT = 6
|
PUNISHMENT_INCREMENT_EXPONENT = 6
|
||||||
|
|||||||
Reference in New Issue
Block a user