def add_news(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): return if args is None or len(args)!=1: return output = "❌ No he reconocido este canal como proveedor de noticias." if news_sql.is_news_provider(args[0]) and not news_sql.is_news_subscribed(chat_id, args[0]): news_sql.set_news_subscription(chat_id, args[0]) output = "✅ ¡Suscripción realizada correctamente!" bot.sendMessage(chat_id=chat_id, text=output)
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): 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): 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): 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): 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 get_settings_keyboard(chat_id, keyboard="main"): if keyboard == "main": settings_keyboard = [ [ InlineKeyboardButton("👷♂️ Administración »", callback_data='settings_goto_ladmin') ], [ InlineKeyboardButton("🛠 Ajustes »", callback_data='settings_goto_general') ], [ InlineKeyboardButton("👋 Bienvenida »", callback_data='settings_goto_welcome') ], [ InlineKeyboardButton("🚪 Entrada »", callback_data='settings_goto_join') ], [ InlineKeyboardButton("📯 Noticias »", callback_data='settings_goto_news') ], [ InlineKeyboardButton("🏫 Modo biblioteca »", callback_data='settings_goto_nanny') ], [InlineKeyboardButton("Terminado", callback_data='settings_done')] ] #2.GROUP SETTINGS elif keyboard == "general": group = get_group_settings(chat_id) if group.games == 1: games_text = "✅ Juegos" else: games_text = "▪️ Juegos" if group.hard == 1: hard_text = "✅ Ban (Warns)" else: hard_text = "▪️ Kick (Warns)" if group.reply_on_group == 1: reply_on_group_text = "✅ Respuestas en el grupo" else: reply_on_group_text = "▪️ Respuestas al privado" if group.warn is model.WarnLimit.SO_EXTRICT.value: warn_text = "Limite de warns: 3" elif group.warn is model.WarnLimit.EXTRICT.value: warn_text = "Limite de warns: 5" elif group.warn is model.WarnLimit.LOW_PERMISIVE.value: warn_text = "Limite de warns: 10" elif group.warn is model.WarnLimit.MED_PERMISIVE.value: warn_text = "Limite de warns: 25" elif group.warn is model.WarnLimit.HIGH_PERMISIVE.value: warn_text = "Limite de warns: 50" elif group.warn is model.WarnLimit.SO_TOLERANT.value: warn_text = "Limite de warns: 100" settings_keyboard = [ [ InlineKeyboardButton(games_text, callback_data='settings_general_games') ], [ InlineKeyboardButton(hard_text, callback_data='settings_general_hard') ], [ InlineKeyboardButton(reply_on_group_text, callback_data='settings_general_reply') ], [ InlineKeyboardButton(warn_text, callback_data='settings_general_warn') ], [ InlineKeyboardButton("« Menú principal", callback_data='settings_goto_main') ] ] #3.JOIN SETTINGS elif keyboard == "join": join = get_join_settings(chat_id) if join.requirment is model.ValidationRequiered.NO_VALIDATION.value: validationrequired_text = "▪️ Grupo abierto" elif join.requirment is model.ValidationRequiered.VALIDATION.value: validationrequired_text = "✅ Validación obligatoria" elif join.requirment is model.ValidationRequiered.PROFESSOR.value: validationrequired_text = "📚 Profesor" elif join.requirment is model.ValidationRequiered.MAGIZOOLOGIST.value: validationrequired_text = "🐾 Magizoologo" elif join.requirment is model.ValidationRequiered.AUROR.value: validationrequired_text = "⚔ Auror" elif join.requirment is model.ValidationRequiered.GRYFFINDOR.value: validationrequired_text = "🦁 Gryffindor" elif join.requirment is model.ValidationRequiered.HUFFLEPUFF.value: validationrequired_text = "🦡 Hufflepuff" elif join.requirment is model.ValidationRequiered.RAVENCLAW.value: validationrequired_text = "🦅 Ravenclaw" elif join.requirment is model.ValidationRequiered.SLYTHERIN.value: validationrequired_text = "🐍 Slytherin" if join.val_alert is True: mute_text = "✅ Expulsiones silenciosas" else: mute_text = "▪️ Expulsiones notificadas" if join.delete_header is True: silence_text = "✅ Borrar -> entró al grupo" else: silence_text = "▪️ Borrar -> entró al grupo" settings_keyboard = [ [ InlineKeyboardButton(mute_text, callback_data='settings_join_mute') ], [ InlineKeyboardButton(silence_text, callback_data='settings_join_silence') ], [ InlineKeyboardButton(validationrequired_text, callback_data='settings_join_val') ], [ InlineKeyboardButton("« Menú principal", callback_data='settings_goto_main') ] ] #5.NEWS SETTINGS elif keyboard == "news": providers = get_verified_providers() settings_keyboard = [] for k in providers: if is_news_subscribed(chat_id, k.id): status = "✅ @" else: status = "▪️ @" text = status + k.alias settings_keyboard.append([ InlineKeyboardButton(text, callback_data='settings_news_{}'.format( k.id)) ]) settings_keyboard.append([ InlineKeyboardButton("« Menú principal", callback_data='settings_goto_main') ]) #6.WELCOME SETTINGS elif keyboard == "welcome": welcome = get_welcome_settings(chat_id) if welcome.should_welcome == 1: welcome_text = "✅ Bienvenida" else: welcome_text = "▪️ Bienvenida" settings_keyboard = [[ InlineKeyboardButton(welcome_text, callback_data='settings_welcome_welcome') ], [ InlineKeyboardButton( "« Menú principal", callback_data='settings_goto_main') ]] #7.NANNY SETTINGS elif keyboard == "nanny": nanny = get_nanny_settings(chat_id) if nanny is None: set_nanny(chat_id) nanny = get_nanny_settings(chat_id) if nanny.voice == 1: voice_text = "✅ Audio y Voz" else: voice_text = "▪️ Audio y Voz" if nanny.command == 1: comandos_text = "✅ Comandos" else: comandos_text = "▪️ Comandos" if nanny.contact == 1: contact_text = "✅ Contactos" else: contact_text = "▪️ Contactos" if nanny.animation == 1: animation_text = "✅ GIFs y Documentos" else: animation_text = "▪️ GIFs y Documentos" if nanny.photo == 1: photo_text = "✅ Imagenes" else: photo_text = "▪️ Imagenes" if nanny.games == 1: games_text = "✅ Juegos" else: games_text = "▪️ Juegos" if nanny.text == 1: text_text = "✅ Mensajes" else: text_text = "▪️ Mensajes" if nanny.sticker == 1: sticker_text = "✅ Stickers" else: sticker_text = "▪️ Stickers" if nanny.location == 1: location_text = "✅ Ubicaciones" else: location_text = "▪️ Ubicaciones" if nanny.urls == 1: url_text = "✅ URLs" else: url_text = "▪️ URLs" if nanny.video == 1: video_text = "✅ Video" else: video_text = "▪️ Video" if nanny.warn == 1: warn_text = "✅ Warns" else: warn_text = "▪️ Warns" if nanny.admin_too == 1: admin_too_text = "️✅ Mensajes de administradores" else: admin_too_text = "️️️▪️ Mensajes de administradores" settings_keyboard = [ [ InlineKeyboardButton(voice_text, callback_data='settings_nanny_voice') ], [ InlineKeyboardButton(comandos_text, callback_data='settings_nanny_command') ], [ InlineKeyboardButton(contact_text, callback_data='settings_nanny_contact') ], [ InlineKeyboardButton(animation_text, callback_data='settings_nanny_animation') ], [ InlineKeyboardButton(photo_text, callback_data='settings_nanny_photo') ], [ InlineKeyboardButton(games_text, callback_data='settings_nanny_games') ], [ InlineKeyboardButton(text_text, callback_data='settings_nanny_text') ], [ InlineKeyboardButton(sticker_text, callback_data='settings_nanny_sticker') ], [ InlineKeyboardButton(location_text, callback_data='settings_nanny_location') ], [ InlineKeyboardButton(url_text, callback_data='settings_nanny_url') ], [ InlineKeyboardButton(video_text, callback_data='settings_nanny_video') ], [ InlineKeyboardButton(warn_text, callback_data='settings_nanny_warn') ], [ InlineKeyboardButton(admin_too_text, callback_data='settings_nanny_admin_too') ], [ InlineKeyboardButton("« Menú principal", callback_data='settings_goto_main') ] ] #8. LOCAL ADMIN elif keyboard == "ladmin": adgroup = get_particular_admin(chat_id) if adgroup.admin == 1: admin_text = "✅ @admin" else: admin_text = "▪️ @admin" if adgroup.welcome == 1: welcome_text = "✅ Entrada de usuarios" else: welcome_text = "▪️ Entrada de usuarios" if adgroup.ejections == 1: ejections_text = "✅ Expulsiones" else: ejections_text = "▪️ Expulsiones" settings_keyboard = [ [ InlineKeyboardButton(admin_text, callback_data='settings_ladmin_admin') ], [ InlineKeyboardButton(welcome_text, callback_data='settings_ladmin_welcome') ], [ InlineKeyboardButton(ejections_text, callback_data='settings_ladmin_ejections') ], [ InlineKeyboardButton("« Menú principal", callback_data='settings_goto_main') ] ] #0. ADMIN elif keyboard == "admin": adgroup = get_admin(chat_id) if adgroup.admin == 1: admin_text = "✅ @admin" else: admin_text = "▪️ @admin" if adgroup.welcome == 1: welcome_text = "✅ Entrada de usuarios" else: welcome_text = "▪️ Entrada de usuarios" if adgroup.ejections == 1: ejections_text = "✅ Expulsiones" else: ejections_text = "▪️ Expulsiones" spy_mode = "🦅 Fawkes" settings_keyboard = [ [ InlineKeyboardButton(admin_text, callback_data='settings_admin_admin') ], [ InlineKeyboardButton(welcome_text, callback_data='settings_admin_welcome') ], [ InlineKeyboardButton(ejections_text, callback_data='settings_admin_ejections') ], [ InlineKeyboardButton(spy_mode, callback_data='settings_admin_spy') ], [InlineKeyboardButton("Terminado", callback_data='settings_done')] ] settings_markup = InlineKeyboardMarkup(settings_keyboard) return settings_markup