def kick(bot: telegram.Bot, update: telegram.Update) -> None: message = update.message chat_id = message.chat_id user_id = message.from_user.id text = 'Ты и сам можешь.' if check_admin(bot, chat_id, user_id) else 'Анус себе покикай.' bot.send_message(chat_id, text, reply_to_message_id=message.message_id)
def alllove(bot: telegram.Bot, update: telegram.Update) -> None: chat_id = update.message.chat_id user_id = update.message.from_user.id if not check_admin(bot, chat_id, user_id): bot.sendMessage(chat_id, 'Хуй тебе, а не страсти смотреть.', reply_to_message_id=update.message.message_id) return bot.sendChatAction(chat_id, ChatAction.TYPING) bot.send_message(chat_id, ReplyLove.get_all_love(chat_id), parse_mode=telegram.ParseMode.HTML)
def can_manage_music_users(bot: telegram.Bot, chat_id: int, uid: int) -> bool: """ Может ли пользователь uid добавлять/удалять участников музкружка? """ if check_admin(bot, chat_id, uid): return True if is_music_user(chat_id, uid): return True return False
def welcome(bot: telegram.Bot, update: telegram.Update) -> None: chat_id = update.message.chat_id user_id = update.message.from_user.id msg_id = update.message.message_id cmd_name = 'welcome' if not check_admin(bot, chat_id, user_id): if is_cmd_delayed(chat_id, cmd_name): return bot.send_message(chat_id, 'Только админы могут вызвать', reply_to_message_id=msg_id) return send_welcome(bot, chat_id, user_id, show_errors=True, msg_id=msg_id)
def stats(bot, update): # Get stats for group msg_id = update.message.message_id chat_id = update.message.chat_id user_id = update.message.from_user.id if not check_admin(bot, chat_id, user_id): bot.sendMessage(chat_id, 'Хуй тебе, а не статистику', reply_to_message_id=msg_id) return bot.sendChatAction(chat_id, ChatAction.TYPING) command = get_command_name(update.message.text) send_stats(bot, chat_id, update.message.chat.title, command, update.message.date)
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 pomogite(bot, update): def __get_commands(chat_id, section_name): return [ f"/{cmd['name']} — {cmd['description']}\n" for key, cmd in CMDS[section_name].items() if is_command_enabled_for_chat(chat_id, cmd['name']) ] chat_id = update.message.chat_id msg = "Общие:\n" commands = __get_commands(chat_id, 'common') msg += ''.join(sorted(commands)) user_id = update.message.from_user.id if check_admin(bot, chat_id, user_id): msg += "\nАдминские:\n" commands = __get_commands(chat_id, 'admins') msg += ''.join(sorted(commands)) bot.sendMessage(chat_id, msg)
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 ban_handler(bot: telegram.Bot, update: telegram.Update) -> None: message: telegram.Message = update.message chat_id = message.chat_id user_id = message.from_user.id msg_id = message.message_id if not check_admin(bot, chat_id, user_id): bot.send_message(chat_id, 'Хуй тебе, а не бан.', reply_to_message_id=msg_id) return splitted = message.text.split() if len(splitted) == 2: user_id = User.get_id_by_name(splitted[1]) else: bot.send_message(chat_id, 'Укажи юзернейм, сестра', reply_to_message_id=msg_id) return ban(bot, chat_id, user_id, msg_id=msg_id)
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} теперь работает')
def off_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 # вычисляем название команды cmd_name = None words = update.message.text.split() reply_to_msg = update.message.reply_to_message if len(words) < 2: if not reply_to_msg: bot.sendMessage(chat_id, 'Ты забыл указать команду.', reply_to_message_id=msg_id) return for entity, entity_text in reply_to_msg.parse_entities().items(): if entity.type == 'bot_command': cmd_name = entity_text break else: cmd_name = words[1] valid_cmd_name = is_valid_command(cmd_name) if not valid_cmd_name: bot.sendMessage(chat_id, f'Нет такой команды: {cmd_name}.', reply_to_message_id=msg_id) return # вычисляем кому отключать if reply_to_msg: plohish_id = reply_to_msg.from_user.id plohish_name = '@' + reply_to_msg.from_user.username else: # если не указали кому, то отключаем для всех if len(words) < 3: off_cmd(bot, update) return plohish_name = words[2] plohish_id = User.get_id_by_name(plohish_name) if not plohish_id: bot.sendMessage(chat_id, f'Нет такого плохиша: {words[2]}', reply_to_message_id=msg_id) return plohish_cmd_cache_key = f'plohish_cmd:{chat_id}:{plohish_id}:{valid_cmd_name}' disabled = cache.get(plohish_cmd_cache_key) if disabled: bot.sendMessage( chat_id, f'Команда /{valid_cmd_name} у плохиша {plohish_name} уже не работает' ) return cache.set(plohish_cmd_cache_key, True, time=MONTH) if reply_to_msg: data = { "name": '/off', "bot_command": cmd_name, "plohish_id": plohish_id, "valid_cmd_name": valid_cmd_name } keyboard = [[ InlineKeyboardButton("Отключить у всех", callback_data=(get_callback_data(data))) ]] reply_markup = InlineKeyboardMarkup(keyboard) bot.sendMessage( chat_id, f'Команда /{valid_cmd_name} у плохиша {plohish_name} теперь не работает.', reply_to_message_id=msg_id, reply_markup=reply_markup) return bot.sendMessage( chat_id, f'Команда /{valid_cmd_name} у плохиша {plohish_name} теперь не работает' )
def is_can_use(bot: telegram.Bot, chat_id: int, uid: int) -> bool: if check_admin(bot, chat_id, uid): return True music_users = get_music_users(chat_id) return uid in music_users