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)
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) elif action == "kick": return await kick_user(message.chat.id, message.from_user.id) elif action == "mute": return await mute_user(message.chat.id, message.from_user.id) elif action.startswith("t"): time = database.get("time") if not time: return False if action == "tmute": return await mute_user( message.chat.id, message.from_user.id, until_date=convert_time(time) ) elif action == "tban": return await ban_user( message.chat.id, message.from_user.id, until_date=convert_time(time) ) else: return False
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"]},
strings["turned_off"].format(chat_title=chat["chat_title"]) ) if data["time"] 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", "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 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(