def decorator(bot, update): chat_id = update.message.chat_id cmd_name = get_command_name(update.message.text) if not is_command_enabled_for_chat(chat_id, cmd_name): return if check_user_is_plohish(update): return if check_command_is_off(chat_id, cmd_name): return return func(bot, update)
def callback_off(bot, update, query, data): chat_id = query.message.chat_id user_id = query.from_user.id if not check_admin(bot, chat_id, user_id): return bot_command = data['bot_command'] cmd_name = is_valid_command(bot_command) if cmd_name: remove_inline_keyboard(bot, chat_id, query.message.message_id) if check_command_is_off(chat_id, cmd_name): bot.sendMessage( chat_id, f'Команда {bot_command} уже выключена. Ты тоже уймись.') return _off_cmd(bot, bot_command, chat_id, cmd_name)
def on_cmd(bot, update): chat_id = update.message.chat_id user_id = update.message.from_user.id msg_id = update.message.message_id if not check_admin(bot, chat_id, user_id): bot.sendMessage(chat_id, 'Хуй тебе, а не команды включать', reply_to_message_id=msg_id) return text = update.message.text.split() if len(text) < 2: if update.message.reply_to_message is not None: text = update.message.reply_to_message.text.split(' ') bot_command = text[0] else: bot.sendMessage(chat_id, 'Ты забыл указать, что включать, пидор', reply_to_message_id=msg_id) return else: bot_command = text[1] if bot_command == 'all' or bot_command == '/all': cache.delete(f'all_cmd_disabled:{chat_id}') bot.sendMessage(chat_id, 'Все команды снова работают.') return cmd_name = get_command_name(bot_command) if not cmd_name: bot.sendMessage(chat_id, f'Нет такой команды: {bot_command}', reply_to_message_id=msg_id) return logger.info( f'check={check_command_is_off(chat_id, cmd_name)}; command={cmd_name}') if not check_command_is_off(chat_id, cmd_name): bot.sendMessage(chat_id, f'Команда {bot_command} уже включена. Все хорошо.', reply_to_message_id=msg_id) return cache.delete(f'cmd_disabled:{chat_id}:{cmd_name}') bot.sendMessage( chat_id, f'Команда {bot_command} снова работает. На твой страх и риск.', reply_to_message_id=msg_id)
def message_reactions(bot: telegram.Bot, update: telegram.Update) -> None: """ Реакция на текст в сообщении """ msg = update.message.text if msg is None: return chat_id = update.message.chat_id msg_lower = msg.lower() msg_id = update.message.message_id user_id = update.message.from_user.id if msg_lower == 'сы': send_random_sticker(bot, chat_id, [ 'BQADAgADpAADbUmmAAGH7b4k7tGlngI', 'BQADAgADoAADbUmmAAF4FOlT87nh6wI', ]) return if msg_lower == 'без': send_random_sticker(bot, chat_id, [ 'BQADAgADXgADRd4ECHiiriOI0A51Ag', 'BQADAgADWgADRd4ECHfSw52J6tn5Ag', 'BQADAgADXAADRd4ECC4HwcwErfUcAg', 'BQADAgADzQADRd4ECNFByeY4RuioAg', ]) return if msg_lower == 'кек': send_random_sticker_from_stickerset(bot, chat_id, 'Kekopack') return if is_command_enabled_for_chat(chat_id, 'suicide') and re_suicide.search(msg_lower): bot.send_sticker(chat_id, 'CAADAgAD3wEAAsBnlArDbqe-dxMlpgI') return if is_command_enabled_for_chat(chat_id, CMDS['common']['orzik']['name']) \ and not check_command_is_off(chat_id, CMDS['common']['orzik']['name']) \ and 'орзик' in msg_lower: orzik_correction(bot, update) if is_command_enabled_for_chat(chat_id, CMDS['common']['gdeleha']['name']) \ and re_gdeleha.search(msg_lower): send_gdeleha(bot, chat_id, msg_id, user_id) return words_lower = msg_lower.split() if 'пидор' in words_lower and is_command_enabled_for_chat( chat_id, 'пидор'): send_pidor(bot, update)
def off_cmd(bot, update): chat_id = update.message.chat_id text = update.message.text.split(' ') user_id = update.message.from_user.id msg_id = update.message.message_id if not check_admin(bot, chat_id, user_id): bot.sendMessage(chat_id, 'Хуй тебе, а не команды выключать.', reply_to_message_id=msg_id) return if len(text) < 2: if update.message.reply_to_message is not None: text = update.message.reply_to_message.text.split(' ') bot_command = text[0] else: bot.sendMessage(chat_id, 'Ты забыл указать, что выключать, пидор.', reply_to_message_id=msg_id) return else: bot_command = text[1] if bot_command == 'all' or bot_command == '/all': off_all_cmds(bot, update) return cmd_name = is_valid_command(bot_command) if not cmd_name: bot.sendMessage(chat_id, f'Нет такой команды: {bot_command}.', reply_to_message_id=msg_id) return if check_command_is_off(chat_id, cmd_name): bot.sendMessage( chat_id, f'Команда {bot_command} уже выключена. Ты тоже уймись.', reply_to_message_id=msg_id) return _off_cmd(bot, bot_command, chat_id, cmd_name)
def on_cmd_for_user(bot, update): chat_id = update.message.chat_id user_id = update.message.from_user.id msg_id = update.message.message_id if not check_admin(bot, chat_id, user_id): bot.sendMessage(chat_id, 'Хуй тебе, а не плохишам команды включать.', reply_to_message_id=msg_id) return text = update.message.text.split() if len(text) < 2: if update.message.reply_to_message is None: bot.sendMessage(chat_id, 'Ты забыл указать команду.', reply_to_message_id=msg_id) return text = update.message.reply_to_message.text.split(' ') bot_command = text[0] else: bot_command = text[1] cmd_name = is_valid_command(bot_command) if not cmd_name: bot.sendMessage(chat_id, f'Нет такой команды: {bot_command}.', reply_to_message_id=msg_id) return reply_to_msg = update.message.reply_to_message if reply_to_msg: plohish_id = reply_to_msg.from_user.id plohish_name = '@' + reply_to_msg.from_user.username else: if len(text) < 3: on_cmd(bot, update) return plohish_name = text[2] plohish_id = User.get_id_by_name(plohish_name) if not plohish_id: bot.sendMessage(chat_id, f'Нет такого плохиша: {text[2]}', reply_to_message_id=msg_id) if check_command_is_off(chat_id, cmd_name): bot.sendMessage( chat_id, f'Команда {cmd_name} отключена у всех, без исключений') return plohish_cmd_cache_key = f'plohish_cmd:{chat_id}:{plohish_id}:{cmd_name}' disabled = cache.get(plohish_cmd_cache_key) if not disabled: bot.sendMessage( chat_id, f'Команда {cmd_name} у плохиша {plohish_name} и так работает') return cache.delete(plohish_cmd_cache_key) bot.sendMessage( chat_id, f'Команда {cmd_name} у плохиша {plohish_name} теперь работает')