def add_ghost_cmd(bot, update, args=None): (chat_id, chat_type, user_id, text, message) = support.extract_update_info(update) support.delete_message(chat_id, message.message_id, bot) if not is_staff(user_id): return if len(args) == 0: return user = get_user(user_id) if user is not None: set_ghost(args[0], True) add_flag(args[0], "👻") else: bot.sendMessage( chat_id=chat_id, text="❌ Ese usuario no existe.", parse_mode=telegram.ParseMode.MARKDOWN) return bot.sendMessage( chat_id=chat_id, text="👌 El usuario ahora es un fantasma 👻", parse_mode=telegram.ParseMode.MARKDOWN)
def game_spawn_cmd(bot, update, args=None): (chat_id, chat_type, user_id, text, message) = support.extract_update_info(update) support.delete_message(chat_id, message.message_id, bot) if not is_staff(user_id): return games = {"grageas":grag_cmd, "quién dijo":whosaid_cmd} if args == None or len(args) == 0: game_list = games.keys() game_list = '\n'.join(game_list) bot.sendMessage( chat_id=chat_id, text='Estos son los juegos disponibles:\n' + game_list, disable_notification=True) return args = " ".join(args) if games[args] != None: games[args](bot, update)
def rm_staff_cmd(bot, update, args=None): (chat_id, chat_type, user_id, text, message) = support.extract_update_info(update) support.delete_message(chat_id, message.message_id, bot) if not is_staff(user_id): return if len(args) == 0: return if get_user(user_id) is not None: set_staff(args[0], False) else: bot.sendMessage(chat_id=chat_id, text="❌ Ese usuario no existe.", parse_mode=telegram.ParseMode.MARKDOWN) return bot.sendMessage(chat_id=chat_id, text="👌 El usuario ya no forma parte del Staff", parse_mode=telegram.ParseMode.MARKDOWN)
def joined_chat(bot, update, job_queue): chat_id, chat_type, user_id, text, message = support.extract_update_info( update) new_chat_member = message.new_chat_members[ 0] if message.new_chat_members else None config = get_config() bot_alias = config['telegram']['bot_alias'] if new_chat_member.username == bot_alias: if are_banned(user_id, chat_id): bot.leaveChat(chat_id=chat_id) return chat_title = message.chat.title chat_id = message.chat.id group = group_sql.get_real_group(chat_id) if group is None: group_sql.set_group(chat_id, message.chat.title) message_text = ("Si necesitais ayuda podéis lanzar chispas rojas c" "on vuestra varita o utilizando el comando `/help`" " para conocer todas las funciones. Aseguraos de v" "er la ayuda para prefectos de los grupos, donde s" "e explica en detalle todos los pasos que se deben" " seguir.".format(escape_markdown(chat_title))) admin = get_admin(chat_id) if admin is not None and admin.admin_bot is True: set_admin_settings(chat_id, "admin_bot") message_text = message_text + "\n\n*Fawkes emprendió el vuelo.*" bot.sendMessage(chat_id=chat_id, text=message_text, parse_mode=telegram.ParseMode.MARKDOWN) elif new_chat_member.username != bot_alias: chat_id = message.chat.id user_id = update.effective_message.new_chat_members[0].id group = get_join_settings(chat_id) if group is not None: if group.delete_header: support.delete_message(chat_id, message.message_id, bot) if are_banned(user_id, user_id): bot.kickChatMember(chat_id, user_id) return user = get_user(user_id) staff = is_staff(user_id) ghost = is_ghost(user_id) if user is None and group.requirment is not ValidationRequiered.NO_VALIDATION.value and staff is False: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago sin registrarse expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") return elif ghost is True: if group.requirment is ValidationRequiered.GRYFFINDOR.value or ValidationRequiered.HUFFLEPUFF.value or ValidationRequiered.SLYTHERIN.value or ValidationRequiered.RAVENCLAW.value and user.house is group.requirment: if group.val_alert is False: output = "👻 Peeves ha entrado en la casa a hacer de las suyas, estad atentos." bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) elif group.requirment is ValidationRequiered.VALIDATION.value and user.level is None and staff is False: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.PROFESSOR.value and user.profession is not Professions.PROFESSOR.value and staff is False: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.MAGIZOOLOGIST.value and user.profession is not Professions.MAGIZOOLOGIST.value and staff is False: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.AUROR.value and user.profession is not Professions.AUROR.value and staff is False: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.GRYFFINDOR.value and user.house is not Houses.GRYFFINDOR.value and staff is False: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.HUFFLEPUFF.value and user.house is not Houses.HUFFLEPUFF.value and staff is False: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.RAVENCLAW.value and user.house is not Houses.RAVENCLAW.value and staff is False: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.SLYTHERIN.value and user.house is not Houses.SLYTHERIN.value and staff is False: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return if group.max_members is not None and group.max_members > 0 and bot.get_chat_members_count( chat_id) >= group.max_members and staff is False: if group.val_alert is False: output = "❌ El número máximo de integrantes en el grupo ha sido alcanzado" sent = bot.sendMessage( chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) delete_object = support.DeleteContext( chat_id, sent.message_id) job_queue.run_once(support.callback_delete, 10, context=delete_object) time.sleep(2) bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) return if (not exists_user_group(user_id, chat_id)): set_user_group(user_id, chat_id) else: join_group(user_id, chat_id) if has_rules(chat_id) and staff is False: bot.restrict_chat_member(chat_id, user_id, until_date=0, can_send_messages=False, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False) if get_welc_pref(chat_id): sent = send_welcome(bot, update) if sent is not None and group.delete_cooldown is not None and group.delete_cooldown > 0: delete_object = support.DeleteContext( chat_id, sent.message_id) job_queue.run_once(support.callback_delete, group.delete_cooldown, context=delete_object) ''' if group.val_alert and (user is None or user.level is None): sent = bot.sendMessage( chat_id=chat_id, text="", parse_mode=telegram.ParseMode.MARKDOWN ) if sent is not None: delete_object = support.DeleteContext(chat_id, sent.message_id) job_queue.run_once( support.callback_delete, group.delete_cooldown or 60, context=delete_object ) ''' ladmin = get_particular_admin(chat_id) if ladmin is not None and ladmin.welcome: admin = get_admin_from_linked(chat_id) if admin is not None and admin.welcome and admin.admin_bot: config = get_config() adm_bot = Bot(token=config["telegram"]["admin_token"]) replace_pogo = support.replace( user_id, message.from_user.first_name, admin=True) message_text = ( "ℹ️ {}\n👤 {} ha entrado en el grupo").format( message.chat.title, replace_pogo) adm_bot.sendMessage(chat_id=admin.id, text=message_text, parse_mode=telegram.ParseMode.MARKDOWN) elif admin is not None and admin.welcome: replace_pogo = support.replace( user_id, message.from_user.first_name, admin=True) message_text = ( "ℹ️ {}\n👤 {} ha entrado en el grupo").format( message.chat.title, replace_pogo) bot.sendMessage(chat_id=admin.id, text=message_text, parse_mode=telegram.ParseMode.MARKDOWN)
def staff_register_cmd(bot, update, args=None): (chat_id, chat_type, user_id, text, message) = support.extract_update_info(update) support.delete_message(chat_id, message.message_id, bot) if not is_staff(user_id): return if len(args) == 0: return if message.reply_to_message is not None: replied_userid = message.reply_to_message.from_user.id if message.reply_to_message.from_user.username is None: replied_username = "******" else: replied_username = support.ensure_escaped(message.reply_to_message.from_user.username) user_username = message.from_user.username else: return if args == None or len(args)>5: logging.debug("%s", len(args)) bot.sendMessage( chat_id=chat_id, text="Has puesto demasiadas opciones, o ninguna.", parse_mode=telegram.ParseMode.MARKDOWN) return output="🧙 [{0}](tg://user?id={1}) made changes to [{2}](tg://user?id={3}):".format( message.from_user.first_name, message.from_user.id, replied_username, replied_userid ) user = get_real_user(replied_userid) if user is None: set_user(replied_userid) alias = None level = None profession = None house = None team = None validation = None for arg in args: if arg=="v": validation = True change="\n- Validation set to *validated*" elif arg.lower() in ["p","m","a","bot"]: if arg=="p": profession = model.Professions.PROFESSOR.value change="\n- Profession set to *Professor*" elif arg=="m": profession = model.Professions.MAGIZOOLOGIST.value change="\n- Profession set to *Magizoologist*" elif arg=="a": profession = model.Professions.AUROR.value change="\n- Profession set to *Auror*" elif arg=="bot": profession = model.Professions.BOT.value change="\n- Profession set to *Bot*" elif arg.lower() in ["n","g","h","r","s","bothouse"]: if arg=="n": house = model.Houses.NONE.value change="\n- House set to *None*" elif arg=="g": house = model.Houses.GRYFFINDOR.value change="\n- House set to *Gryffindor*" elif arg=="h": house = model.Houses.HUFFLEPUFF.value change="\n- House set to *Hufflepuff*" elif arg=="r": house = model.Houses.RAVENCLAW.value change="\n- House set to *Ravenclaw*" elif arg=="s": house = model.Houses.SLYTHERIN.value change="\n- House set to *Slytherin*" elif arg=="bothouse": house = model.Houses.BOTS.value change="\n- House set to *Bots*" elif arg.isdigit() and int(arg) >= 1 and int(arg) <= 60: level = int(arg) change="\n- Level set to *{}*".format(level) elif re.match(r'[a-zA-Z0-9]{3,30}$', arg) is not None: alias = arg change="\n- Alias set to *{}*".format(alias) else: change="\n- *{}* was not a valid argument and was skipped.".format(arg) output="{}{}".format(output,change) try: commit_user(user_id=replied_userid, alias=alias, level=level, profession=profession, house=house, team=team, validation=validation) except: output="Huh... Se ha roto algo en el proceso @Sarayalth" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN)
def rps_user_cmd(bot, update, job_queue, args=None): (chat_id, chat_type, user_id, text, message) = support.extract_update_info(update) username = update.effective_user.username support.delete_message(chat_id, message.message_id, bot) if update.effective_user.username is None: return if not is_staff(user_id): return if args is not None and len(args) > 0: if message.reply_to_message is not None: vs_user = message.reply_to_message.from_user if vs_user.username is None: sent = bot.sendMessage( chat_id=chat_id, text='Ese usuario no tiene una @.', disable_notification=True) delete_object = support.DeleteContext(chat_id, sent.message_id) job_queue.run_once( support.callback_delete, 10, context=delete_object) return if vs_user.id == user_id: bot.sendMessage( chat_id=chat_id, text='Necesitas a alguien más para jugar.', disable_notification=True) return if vs_user.is_bot == True: bot.sendMessage( chat_id=chat_id, text='No puedes jugar contra un bot.', disable_notification=True) return if args[0].lower() == "piedra": b1 = "g*rps_us_r_r_" + str(user_id) b2 = "g*rps_us_p_r_" + str(user_id) b3 = "g*rps_us_s_r_" + str(user_id) elif args[0].lower() == "papel": b1 = "g*rps_us_r_p_" + str(user_id) b2 = "g*rps_us_p_p_" + str(user_id) b3 = "g*rps_us_s_p_" + str(user_id) elif args[0].lower() == "tijera": b1 = "g*rps_us_r_s_" + str(user_id) b2 = "g*rps_us_p_s_" + str(user_id) b3 = "g*rps_us_s_s_" + str(user_id) else: sent = bot.sendMessage( chat_id=chat_id, text='No has escrito una de las opciones posibles (piedra, papel, tijera).', disable_notification=True) delete_object = support.DeleteContext(chat_id, sent.message_id) job_queue.run_once( support.callback_delete, 10, context=delete_object) return markup = [ [InlineKeyboardButton(text="Piedra", callback_data=b1)], [InlineKeyboardButton(text="Papel", callback_data=b2)], [InlineKeyboardButton(text="Tijera", callback_data=b3)]] bot.sendMessage( chat_id=chat_id, text='@' + username + ' ha retado a @' + vs_user.username + ' a Piedra, Papel o Tijera! \n ¿Qué eliges?', disable_notification=True, reply_markup=InlineKeyboardMarkup(markup)) else: bot.sendMessage( chat_id=chat_id, text='Tienes que responder al mensaje de otro usuario para poder retarlo.', disable_notification=True) else: bot.sendMessage( chat_id=chat_id, text='No has escrito una de las opciones posibles (piedra, papel, tijera).', disable_notification=True)
def set_zone(bot, update, args=None): chat_id, chat_type, user_id, text, message = support.extract_update_info(update) support.delete_message(chat_id, message.message_id, bot) if (not support.is_admin(chat_id, user_id, bot) or are_banned(user_id, chat_id)) and is_staff(user_id) is False: return group = get_group(chat_id) if group is None: bot.sendMessage( chat_id=chat_id, text="❌ No puedo reconocer este grupo. Si estaba funcionando hasta ahora, pregunta en @profesordumbledoreayuda.", parse_mode=telegram.ParseMode.MARKDOWN ) return if args is None or len(args) != 1 or len(args[0]) < 3 or len(args[0]) > 60: bot.sendMessage( chat_id=chat_id, text=("❌ Me siento un poco perdido ahora mismo. Debes pasarme un nombre de zona horaria en inglés, por ejemplo, `America/Montevideo` o `Europe/Madrid`."), parse_mode=telegram.ParseMode.MARKDOWN ) return tz = support.get_unified_timezone(args[0]) if len(tz) == 1: commit_group(chat_id, timezone=tz[0]) bot.sendMessage( chat_id=chat_id, text="👌 Perfecto! Zona horaria cambiada de *{0}* a *{1}*.".format(group.timezone, tz[0]), parse_mode=telegram.ParseMode.MARKDOWN ) now = datetime.now(timezone(tz[0])).strftime("%H:%M") bot.sendMessage( chat_id=chat_id, text="🕒 Por favor, comprueba que la hora sea correcta: {}".format(now)) elif len(tz) == 0: bot.sendMessage( chat_id=chat_id, text="❌ Uy, no he encontrado ninguna zona horaria con ese nombre") else: bot.sendMessage( chat_id=chat_id, text="❌ Has sido demasiado genérico con el nombre de la zona horaria. Intenta concretar más.")
def set_welcome(bot, update): chat_id, chat_type, user_id, text, message = support.extract_update_info(update) text, data_type, content, buttons = support.get_welcome_type(message) if (not support.is_admin(chat_id, user_id, bot) or are_banned(user_id, chat_id)) and is_staff(user_id) is False: return group = get_group(chat_id) if group is None: bot.sendMessage( chat_id=chat_id, text="❌ No puedo reconocer este grupo. Si estaba funcionando hasta ahora, pregunta en @profesordumbledoreayuda.", parse_mode=telegram.ParseMode.MARKDOWN ) return if data_type is None: set_welc_preference(chat_id, False) bot.sendMessage(chat_id=chat_id, text="👌 Mensaje de bienvenida desactivado correctamente") return set_welc_preference(chat_id, True) set_custom_welcome(chat_id, content or text, data_type, buttons) bot.sendMessage(chat_id=chat_id, text="👌 Mensaje de bienvenida guardado correctamente")
def settings(bot, update, args=None): chat_id, chat_type, user_id, text, message = support.extract_update_info(update) support.delete_message(chat_id, message.message_id, bot) if (not support.is_admin(chat_id, user_id, bot) or are_banned(user_id, chat_id)) and is_staff(user_id) is False: return group = get_group(chat_id) if group is None: bot.sendMessage( chat_id=chat_id, text="❌ No puedo reconocer este grupo. Si estaba funcionando hasta ahora, pregunta en @profesordumbledoreayuda.", parse_mode=telegram.ParseMode.MARKDOWN ) return message = bot.sendMessage(chat_id=chat_id, text="Oído cocina!...") support.update_settings_message(chat_id, bot, message.message_id, keyboard="main")
def settingsbutton(bot, update): logging.debug("%s %s", bot, update) query = update.callback_query data = query.data user = update.effective_user user_id = query.from_user.id user_username = query.from_user.username chat_id = query.message.chat.id message_id = query.message.message_id are_banned(user_id, chat_id) settings_goto = { "settings_goto_general": "general", "settings_goto_join": "join", "settings_goto_news": "news", "settings_goto_welcome": "welcome", "settings_goto_nanny": "nanny", "settings_goto_ladmin": "ladmin", "settings_goto_main": "main" } settings_general = { "settings_general_games": "games", "settings_general_hard": "hard", "settings_general_reply": "reply", "settings_general_warn": "warn" } settings_join = { "settings_join_mute": "silence", "settings_join_silence": "mute", "settings_join_val": "val" } settings_welcome = { "settings_welcome_welcome": "should_welcome" } settings_nanny = { "settings_nanny_command": "cmd", "settings_nanny_animation": "animation", "settings_nanny_contact": "contact", "settings_nanny_photo": "photo", "settings_nanny_games": "games", "settings_nanny_text": "text", "settings_nanny_sticker": "sticker", "settings_nanny_location": "location", "settings_nanny_url": "url", "settings_nanny_video": "video", "settings_nanny_warn": "warn", "settings_nanny_admin_too": "admin_too", "settings_nanny_voice":"voice" } settings_ladmin = { "settings_ladmin_welcome": "welcome", "settings_ladmin_admin": "admin", "settings_ladmin_ejections": "ejections" } settings_admin = { "settings_admin_welcome": "welcome", "settings_admin_goodbye": "goodbye", "settings_admin_admin": "admin", "settings_admin_ejections": "ejections" } if re.match("^settings_.+$", data) is not None: match = re.match(r"settings_news_([-0-9]*)", query.data) if not support.is_admin(chat_id, user_id, bot) and is_staff(user_id) is False: bot.answerCallbackQuery( text="Solo los administradores del grupo pueden configurar el bot.", callback_query_id=update.callback_query.id, show_alert="true" ) return if data in settings_goto: support.update_settings_message(chat_id, bot, message_id, keyboard=settings_goto[data]) elif data == "settings_done": support.delete_message(chat_id, message_id, bot) elif data in settings_general: set_general_settings(chat_id, settings_general[data]) support.update_settings_message(chat_id, bot, message_id, keyboard="general") elif data in settings_join: set_join_settings(chat_id, settings_join[data]) support.update_settings_message(chat_id, bot, message_id, keyboard="join") elif data in settings_welcome: set_welcome_settings(chat_id, settings_welcome[data]) support.update_settings_message(chat_id, bot, message_id, keyboard="welcome") elif data in settings_nanny: set_nanny_settings(chat_id, settings_nanny[data]) support.update_settings_message(chat_id, bot, message_id, keyboard="nanny") elif data in settings_admin: set_admin_settings(chat_id, settings_admin[data]) support.update_settings_message(chat_id, bot, message_id, keyboard="admin") elif data in settings_ladmin: set_ladmin_settings(chat_id, settings_ladmin[data]) support.update_settings_message(chat_id, bot, message_id, keyboard="ladmin") elif data == "settings_admin_spy": set_ladmin_settings(chat_id, "admin_bot") support.delete_message(chat_id, message_id, bot) output = "Antes de nada administradores quiero daros las gracias. Debeis haber demostrado verdadera lealtad hacia mi en el grupo, y solo eso ha podido lograr que acuda Fawkes a vuestro grupo.\nÉl no puede leer nada de lo que suceda en el grupo, simplemente enviará las alertas que hayais configurado. Si necesitais configurar de nuevo las alertas o quereis usar los comandos, invitadme de nuevo al grupo y cuando acabeis volved a activar a Fawkes." bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) bot.leaveChat(chat_id=chat_id) elif match: news_id = match.group(1) if is_news_subscribed(chat_id, news_id): rm_news_subscription(chat_id, news_id) else: set_news_subscription(chat_id, news_id) support.update_settings_message(chat_id, bot, message_id, keyboard="news") return match = re.match(r"rm_warn\((.+?)\)", query.data) if match: if not support.is_admin(chat_id, user_id, bot) and is_staff(user_id) is False: bot.answerCallbackQuery( text="Solo los administradores del grupo pueden retirar warns.", callback_query_id=update.callback_query.id, show_alert="true" ) return user_id = match.group(1) res = remove_warn(user_id, chat_id) if res: text = "Aviso eliminado por @{}.".format(user_username) bot.answerCallbackQuery( text="Has eliminado un warn.", callback_query_id=update.callback_query.id, show_alert="true") else: bot.answerCallbackQuery( text="En estos momentos no puedo eliminar el warn, prueba mas tarde.", callback_query_id=update.callback_query.id, show_alert="true" ) return bot.edit_message_text( text=text, chat_id=chat_id, message_id=message_id, parse_mode=telegram.ParseMode.HTML, disable_web_page_preview=True ) return match = re.match(r"rm_ban\((.+?)\)", query.data) if match: if not support.is_admin(chat_id, user_id, bot) and is_staff(user_id) is False: bot.answerCallbackQuery( text="Solo los administradores del grupo pueden retirar bans.", callback_query_id=update.callback_query.id, show_alert="true" ) return us_id = match.group(1) bot.unbanChatMember(chat_id, us_id) bot.answerCallbackQuery( text="Has eliminado un ban.", callback_query_id=update.callback_query.id, show_alert="true") text="Ban retirado por @{}.".format(user_username) bot.edit_message_text( text=text, chat_id=chat_id, message_id=message_id, parse_mode=telegram.ParseMode.HTML, disable_web_page_preview=True ) return match = re.match(r"rm_mute\((.+?)\)", query.data) if match: if not support.is_admin(chat_id, user_id, bot) and is_staff(user_id) is False: bot.answerCallbackQuery( text="Solo los administradores del grupo pueden desmutear usuarios.", callback_query_id=update.callback_query.id, show_alert="true" ) return us_id = match.group(1) bot.restrict_chat_member(chat_id, us_id, can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True) bot.answerCallbackQuery( text="El usuario ha sido desmuteado.", callback_query_id=update.callback_query.id, show_alert="true") text="Usuario desmuteado por @{}.".format(user_username) bot.edit_message_text( text=text, chat_id=chat_id, message_id=message_id, parse_mode=telegram.ParseMode.HTML, disable_web_page_preview=True ) return else: logging.error('settingsbutton:%s is not a expected settings command', data)
def set_cooldown(bot, update, args=None): chat_id, chat_type, user_id, text, message = support.extract_update_info(update) support.delete_message(chat_id, message.message_id, bot) if (not support.is_admin(chat_id, user_id, bot) or are_banned(user_id, chat_id)) and is_staff(user_id) is False: return group = get_group(chat_id) if group is None: bot.sendMessage( chat_id=chat_id, text="❌ No puedo reconocer este grupo. Si estaba funcionando hasta ahora, pregunta en @profesordumbledoreayuda.", parse_mode=telegram.ParseMode.MARKDOWN ) return if args is None or len(args) != 1 or not args[0].isdigit() or int(args[0])<0: bot.sendMessage( chat_id=chat_id, text="❌ No he reconocido el parámetro introducido. Por favor, revisa el comando e intenta de nuevo.") return if int(args[0]) is 0: set_welcome_cooldown(chat_id, None) output = "👌 El mensaje de bienvenida no se eliminará automáticamente." else: set_welcome_cooldown(chat_id, int(args[0])) output = "👌 El mensaje de bienvenida se eliminará automáticamente en {} segundos".format(args[0]) bot.sendMessage( chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) return
def set_maxmembers(bot, update, args=None): chat_id, chat_type, user_id, text, message = support.extract_update_info(update) support.delete_message(chat_id, message.message_id, bot) if (not support.is_admin(chat_id, user_id, bot) or are_banned(user_id, chat_id)) and is_staff(user_id) is False: return group = get_group(chat_id) if group is None: bot.sendMessage( chat_id=chat_id, text="❌ No puedo reconocer este grupo. Si estaba funcionando hasta ahora, pregunta en @profesordumbledoreayuda.", parse_mode=telegram.ParseMode.MARKDOWN ) return if args is None or len(args) != 1 or not args[0].isdigit() or int(args[0])<0: bot.sendMessage( chat_id=chat_id, text="❌ No he reconocido el parámetro introducido. Por favor, revisa el comando e intenta de nuevo.") return if int(args[0]) is 0: set_max_members(chat_id, None) output = "👌 Número máximo de miembros en el grupo desactivado correctamente." else: set_max_members(chat_id, int(args[0])) output = "👌 Número máximo de miembros en el grupo establecido a {}".format(args[0]) bot.sendMessage( chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) return