def del_lockables(update, context): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] for lockable, filter in LOCK_TYPES.items(): if lockable == "rtl": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message.caption: check = ad.detect_alphabet(u"{}".format(message.caption)) if "ARABIC" in check: try: message.delete() except BadRequest as excp: if excp.message == "Mensaje para eliminar no encontrado": pass else: LOGGER.exception("ERROR en bloqueables") break if message.text: check = ad.detect_alphabet(u"{}".format(message.text)) if "ARABIC" in check: try: message.delete() except BadRequest as excp: if excp.message == "Mensaje para eliminar no encontrado": pass else: LOGGER.exception("ERROR en bloqueables") break continue if lockable == "button": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message.reply_markup and message.reply_markup.inline_keyboard: try: message.delete() except BadRequest as excp: if excp.message == "Mensaje para eliminar no encontrado": pass else: LOGGER.exception("ERROR en bloqueables") break continue if lockable == "inline": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message and message.via_bot: try: message.delete() except BadRequest as excp: if excp.message == "Mensaje para eliminar no encontrado": pass else: LOGGER.exception("ERROR en bloqueables") break continue if (filter(update) and sql.is_locked(chat.id, lockable) and can_delete(chat, context.bot.id)): if lockable == "bots": new_members = update.effective_message.new_chat_members for new_mem in new_members: if new_mem.is_bot: if not is_bot_admin(chat, context.bot.id): send_message( update.effective_message, "Veo un bot y me han dicho que evite que se unan..." "Pero no tengo admin! :(", ) return chat.kick_member(new_mem.id) send_message( update.effective_message, "Solo los admins pueden agregar bots en este chat! Fuera de aquí.", ) break else: try: message.delete() except BadRequest as excp: if excp.message == "Mensaje para eliminar no encontrado": pass else: LOGGER.exception("ERROR en bloqueables") break
def runmute(update: Update, context: CallbackContext): bot, args = context.bot, context.args message = update.effective_message if not args: message.reply_text("Parece que no te refieres a un grupo/suario.") return user_id, chat_id = extract_user_and_text(message, args) if not user_id: message.reply_text( "No parece que se refiera a un usuario o el ID especificado es incorrecto." ) return elif not chat_id: message.reply_text("Parece que no te refieres a un grupo.") return try: chat = bot.get_chat(chat_id.split()[0]) except BadRequest as excp: if excp.message == "Chat not found": message.reply_text( "Chat no encontrado! Asegúrese de haber ingresado una ID de chat válida y yo sea parte de ese chat." ) return else: raise if chat.type == "private": message.reply_text("Lo siento, pero es un chat privado!") return if (not is_bot_admin(chat, bot.id) or not chat.get_member(bot.id).can_restrict_members): message.reply_text( "No puedo dejar de restringir a la gente! Asegúrate de que sea administradora y pueda desbloquear usuarios." ) return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "Usuario no encontrado": message.reply_text("Parece que no puedo encontrar a este usuario") return else: raise if is_user_in_chat(chat, user_id): if (member.can_send_messages and member.can_send_media_messages and member.can_send_other_messages and member.can_add_web_page_previews): message.reply_text( "Este usuario ya tiene derecho a hablar en ese chat.") return if user_id == bot.id: message.reply_text("No voy a DESMUTARME, soy un administradora allí!") return try: bot.restrict_chat_member( chat.id, int(user_id), permissions=ChatPermissions( can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True, ), ) message.reply_text("Ok, este usuario puede hablar en ese chat!") except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text("Desmuteado!", quote=False) elif excp.message in RUNMUTE_ERRORS: message.reply_text(excp.message) else: LOGGER.warning(update) LOGGER.exception( "ERROR unmnuting user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message, ) message.reply_text( "Bueno maldita sea, no puedo silenciar a ese usuario.")
def rban(update: Update, context: CallbackContext): bot, args = context.bot, context.args message = update.effective_message if not args: message.reply_text("Parece que no te refieres a un grupo/usuario.") return user_id, chat_id = extract_user_and_text(message, args) if not user_id: message.reply_text( "No parece que se refiera a un usuario o el ID especificado es incorrecto" ) return elif not chat_id: message.reply_text("Parece que no te refieres a un chat.") return try: chat = bot.get_chat(chat_id.split()[0]) except BadRequest as excp: if excp.message == "Chat not found": message.reply_text( "Chat no encontrado! Asegúrese de haber ingresado una ID de chat válida y yo sea parte de ese chat." ) return else: raise if chat.type == "private": message.reply_text("Lo siento, pero es un chat privado!") return if (not is_bot_admin(chat, bot.id) or not chat.get_member(bot.id).can_restrict_members): message.reply_text( "No puedo restringir a la gente allí! Asegúrate de que soy administradora y pueda bloquear usuarios." ) return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "Usuario no encontrado": message.reply_text("Parece que no puedo encontrar a este usuario") return else: raise if is_user_ban_protected(chat, user_id, member): message.reply_text( "Realmente desearía poder banear a los administradores...") return if user_id == bot.id: message.reply_text("Yo no voy a BANEAR, estás loco?") return try: chat.kick_member(user_id) message.reply_text("Baneado del chat!") except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text("Banned!", quote=False) elif excp.message in RBAN_ERRORS: message.reply_text(excp.message) else: LOGGER.warning(update) LOGGER.exception( "ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message, ) message.reply_text( "Bueno maldita sea, no puedo prohibir a ese usuario.")
def runban(update: Update, context: CallbackContext): bot, args = context.bot, context.args message = update.effective_message if not args: message.reply_text("Parece que no te refieres a un grupo/usuario.") return user_id, chat_id = extract_user_and_text(message, args) if not user_id: message.reply_text( "No parece que se refiera a un usuario o el ID especificado es incorrecto." ) return elif not chat_id: message.reply_text("Parece que no te refieres a un chat.") return try: chat = bot.get_chat(chat_id.split()[0]) except BadRequest as excp: if excp.message == "Chat not found": message.reply_text( "Chat no encontrado! Asegúrese de haber ingresado una ID de chat válida y yo sea parte de ese chat." ) return else: raise if chat.type == "private": message.reply_text("Lo siento, pero es un chat privado!") return if (not is_bot_admin(chat, bot.id) or not chat.get_member(bot.id).can_restrict_members): message.reply_text( "¡No puedo dejar de restringir a la gente! Asegúrate de que soy administrador y puedo desbloquear usuarios." ) return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "Usuario no encontrado": message.reply_text( "Parece que no puedo encontrar a este usuario there") return else: raise if is_user_in_chat(chat, user_id): message.reply_text( "Por qué intentas desbanear de forma remota a alguien que ya está en ese chat?" ) return if user_id == bot.id: message.reply_text("No voy a DESBANEARME, soy administradora allí!") return try: chat.unban_member(user_id) message.reply_text("Ok, este usuario puede unirse a ese chat!") except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text("Desbaneado!", quote=False) elif excp.message in RUNBAN_ERRORS: message.reply_text(excp.message) else: LOGGER.warning(update) LOGGER.exception( "ERROR unbanning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message, ) message.reply_text("Well damn, I can't unban that user.")