async def antiflood_expire_proc(message: Message, chat: dict, strings: dict, state, **_): try: if (time := message.text) not in (0, "0"): # just call for making sure its valid parsed_time = convert_time(time) else:
def insert_flood(self, data: CacheModel, message: Message, database: dict): ex = ( convert_time(database['time']) if database.get('time') is not None else None ) return bredis.set(self.cache_key(message), pickle.dumps(data), ex=ex)
if message.get_args().lower() in ('off', '0', 'no'): await db.antiflood.delete_one({"chat_id": chat['chat_id']}) await get_data.reset_cache(chat['chat_id']) return await message.reply( strings['turned_off'].format(chat_title=chat['chat_title'])) if data.get("time", None) is None: return await message.reply(strings['configuration_info'].format( action=strings[data['action']] if 'action' in data else strings['ban'], count=data['count'])) return await message.reply(strings['configuration_info:with_time'].format( action=strings[data['action']] if 'action' in data else strings['ban'], count=data['count'], time=format_timedelta(convert_time(data['time']), locale=strings['language_info']['babel']))) @register(cmds=['setfloodaction'], user_can_restrict_members=True) @need_args_dec() @chat_connection(admin=True) @get_strings_dec('antiflood') async def setfloodaction(message: Message, chat: dict, strings: dict): SUPPORTED_ACTIONS = ['kick', 'ban', 'mute'] # noqa if (action := message.get_args().lower()) not in SUPPORTED_ACTIONS: return await message.reply(strings['invalid_args'].format( supported_actions=", ".join(SUPPORTED_ACTIONS))) await db.antiflood.update_one({"chat_id": chat['chat_id']}, {"$set": {
async def do_action(cls, message: Message, database: dict): action = database.get('action', 'ban') if action == 'ban': return await ban_user(message.chat.id, message.from_user.id) if action == 'kick': return await kick_user(message.chat.id, message.from_user.id) if action == 'mute': return await mute_user(message.chat.id, message.from_user.id) if action.startswith('t'): time = database.get('ttime') if not time: return False if action == "tmute": return await mute_user(message.chat.id, message.from_user.id, until_date=convert_time(time)) if action == 'tban': return await ban_user(message.chat.id, message.from_user.id, until_date=convert_time(time)) else: return False
if data.get("time", None) is None: return await message.reply( strings['configuration_info'].format( action=strings[data['action'] ] if 'action' in data else strings['ban'], count=data['count'] ) ) return await message.reply( strings['configuration_info:with_time'].format( action=strings[data['action'] ] if 'action' in data else strings['ban'], count=data['count'], time=format_timedelta( convert_time(data['time']), locale=strings['language_info']['babel'] ) ) ) @register(cmds=['setfloodaction'], is_admin=True, user_can_restrict_members=True) @need_args_dec() @chat_connection(admin=True) @get_strings_dec('antiflood') async def setfloodaction(message: Message, chat: dict, strings: dict): SUPPORTED_ACTIONS = ['kick', 'ban', 'mute', 'tmute', 'tban'] # noqa if (action := message.get_args().lower()) not in SUPPORTED_ACTIONS: return await message.reply(strings['invalid_args'].format(supported_actions=", ".join(SUPPORTED_ACTIONS))) if action.startswith('t'):