def about_me(update: Update, context: CallbackContext): bot, args = context.bot, context.args message = update.effective_message user_id = extract_user(message, args) if user_id: user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_me_info(user.id) if info: update.effective_message.reply_text( f"*{user.first_name}*:\n{escape_markdown(info)}", parse_mode=ParseMode.MARKDOWN, ) elif message.reply_to_message: username = message.reply_to_message.from_user.first_name update.effective_message.reply_text( f"{username} aún no ha puesto un mensaje sobre él!") else: update.effective_message.reply_text( "No tienes uno, usa `/setme` para configurar uno.", parse_mode=ParseMode.MARKDOWN, )
def warns(update: Update, context: CallbackContext): args = context.args message: Optional[Message] = update.effective_message chat: Optional[Chat] = update.effective_chat user_id = extract_user(message, args) or update.effective_user.id result = sql.get_warns(user_id, chat.id) if result and result[0] != 0: num_warns, reasons = result limit, soft_warn = sql.get_warn_setting(chat.id) if reasons: text = f"Este usuario tiene {num_warns}/{limit} advertencias, por los siguientes motivos:" for reason in reasons: text += f"\n • {reason}" msgs = split_message(text) for msg in msgs: update.effective_message.reply_text(msg) else: update.effective_message.reply_text( f"El usuario tiene {num_warns}/{limit} advertencias, pero no hay motivos para ninguna de ellas." ) else: update.effective_message.reply_text( "Este usuario no tiene advertencias!")
def about_bio(update: Update, context: CallbackContext): bot, args = context.bot, context.args message = update.effective_message user_id = extract_user(message, args) if user_id: user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_bio(user.id) if info: update.effective_message.reply_text( "*{}*:\n{}".format(user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN, ) elif message.reply_to_message: username = user.first_name update.effective_message.reply_text( f"{username} aún no ha establecido un mensaje sobre sí mismo!\nEstablezca uno usando `/setbio`", parse_mode=ParseMode.MARKDOWN, ) else: update.effective_message.reply_text( "Aún no tienes una biografía sobre ti!")
def get_user_common_chats(update: Update, context: CallbackContext): bot, args = context.bot, context.args msg = update.effective_message user = extract_user(msg, args) if not user: msg.reply_text("Pásame un ID, alias o responde a un usuario.") return common_list = get_user_com_chats(user) if not common_list: msg.reply_text("No tengo chats en comun con este usuario!") return name = bot.get_chat(user).first_name text = f"<b>Chats en común con {name}:</b>\n" for chat in common_list: try: chat_name = bot.get_chat(chat).title sleep(0.3) text += f"• <code>{chat_name}</code>\n" except BadRequest: pass except Unauthorized: pass except RetryAfter as e: sleep(e.retry_after) if len(text) < 4096: msg.reply_text(text, parse_mode="HTML") else: with open("common_chats.txt", "w") as f: f.write(text) with open("common_chats.txt", "rb") as f: msg.reply_document(f) os.remove("common_chats.txt")
def disapprove(update, context): message = update.effective_message chat_title = message.chat.title chat = update.effective_chat args = context.args user = update.effective_user user_id = extract_user(message, args) if not user_id: message.reply_text("No conozco a ese usuario!") return "" try: member = chat.get_member(user_id) except BadRequest: return "" if member.status == "administrator" or member.status == "creator": message.reply_text( "Este usuario es un administrador, no se puede quitar la libertad." ) return "" if not sql.is_approved(message.chat_id, user_id): message.reply_text(f"{member.user['first_name']} isn't approved yet!") return "" sql.disapprove(message.chat_id, user_id) message.reply_text( f"{member.user['first_name']} is no longer approved in {chat_title}.") log_message = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#QuitaLibre\n" f"<b>Administrador:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Usuario:</b> {mention_html(member.user.id, member.user.first_name)}" ) return log_message
def addfrog(update: Update, context: CallbackContext) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat bot, args = context.bot, context.args user_id = extract_user(message, args) user_member = bot.getChat(user_id) rt = "" reply = check_user_id(user_id, bot) if reply: message.reply_text(reply) return "" with open(ELEVATED_USERS_FILE, "r") as infile: data = json.load(infile) if user_id in SUDO_USERS: rt += "Este miembro ya no es un Destroyer, rebajado a Rana Gigante." data["sudos"].remove(user_id) SUDO_USERS.remove(user_id) if user_id in SUPPORT_USERS: rt += "Este usuario ya no es un demonio, rebajado a Rana Gigante." data["supports"].remove(user_id) SUPPORT_USERS.remove(user_id) if user_id in WHITELIST_USERS: rt += "Este usuario ya no es un Sapo Gigante, rebajado a Rana Gigante." data["whitelists"].remove(user_id) WHITELIST_USERS.remove(user_id) if user_id in FROG_USERS: message.reply_text("Este usuario ya es una Rana Gigante.") return "" data["frogs"].append(user_id) FROG_USERS.append(user_id) with open(ELEVATED_USERS_FILE, "w") as outfile: json.dump(data, outfile, indent=4) update.effective_message.reply_text( rt + f"\n{user_member.first_name} ascendió con éxito a Rana Gigante!" ) log_message = ( f"#Rana\n" f"<b>Administrador:</b> {mention_html(user.id, user.first_name)} \n" f"<b>Usuario:</b> {mention_html(user_member.id, user_member.first_name)}" ) if chat.type != "private": log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message
def addsudo(update: Update, context: CallbackContext) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat bot, args = context.bot, context.args user_id = extract_user(message, args) user_member = bot.getChat(user_id) rt = "" reply = check_user_id(user_id, bot) if reply: message.reply_text(reply) return "" with open(ELEVATED_USERS_FILE, "r") as infile: data = json.load(infile) if user_id in SUDO_USERS: message.reply_text("Este miembro ya es un Destroyer") return "" if user_id in SUPPORT_USERS: rt += "Promoví un Demonio a Destroyer." data["supports"].remove(user_id) SUPPORT_USERS.remove(user_id) if user_id in WHITELIST_USERS: rt += "Promoví un Sapo Gigante a Destroyer." data["whitelists"].remove(user_id) WHITELIST_USERS.remove(user_id) data["sudos"].append(user_id) SUDO_USERS.append(user_id) with open(ELEVATED_USERS_FILE, "w") as outfile: json.dump(data, outfile, indent=4) update.effective_message.reply_text( rt + "\nSe estableció correctamente el nivel de {} en Destroyer!".format( user_member.first_name ) ) log_message = ( f"#SuperUsuario\n" f"<b>Administrador:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Usuario:</b> {mention_html(user_member.id, user_member.first_name)}" ) if chat.type != "private": log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message
def slap(update: Update, context: CallbackContext): bot, args = context.bot, context.args message = update.effective_message chat = update.effective_chat reply_text = (message.reply_to_message.reply_text if message.reply_to_message else message.reply_text) curr_user = html.escape(message.from_user.first_name) user_id = extract_user(message, args) if user_id == bot.id: temp = random.choice(fun_strings.SLAP_MEGU_TEMPLATES) if isinstance(temp, list): if temp[2] == "tmute": if is_user_admin(chat, message.from_user.id): reply_text(temp[1]) return mutetime = int(time.time() + 60) bot.restrict_chat_member( chat.id, message.from_user.id, until_date=mutetime, permissions=ChatPermissions(can_send_messages=False), ) reply_text(temp[0]) else: reply_text(temp) return if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user user2 = html.escape(slapped_user.first_name) else: user1 = bot.first_name user2 = curr_user temp = random.choice(fun_strings.SLAP_TEMPLATES) item = random.choice(fun_strings.ITEMS) hit = random.choice(fun_strings.HIT) throw = random.choice(fun_strings.THROW) reply = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) reply_text(reply, parse_mode=ParseMode.HTML)
def unmute(update: Update, context: CallbackContext) -> str: bot, args = context.bot, context.args chat = update.effective_chat user = update.effective_user message = update.effective_message user_id = extract_user(message, args) if not user_id: message.reply_text( "Debe darme un nombre de usuario o responder a alguien para des-silenciarlo." ) return "" member = chat.get_member(int(user_id)) if member.status != "kicked" and member.status != "left": 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 está desilenciado.") else: chat_permissions = ChatPermissions( can_send_messages=True, can_invite_users=True, can_pin_messages=True, can_send_polls=True, can_change_info=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True, ) bot.restrict_chat_member(chat.id, int(user_id), chat_permissions) bot.sendMessage( chat.id, f"<b>{html.escape(member.user.first_name)}</b> desilenciado!", parse_mode=ParseMode.HTML, ) return ( f"<b>{html.escape(chat.title)}:</b>\n" f"#Des-silenciado\n" f"<b>Administrador:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Usuario:</b> {mention_html(member.user.id, member.user.first_name)}" ) else: message.reply_text( "Este usuario ni siquiera está en el chat, dejar de silenciarlo no hablara más de lo que puede." ) return ""
def approval(update, context): message = update.effective_message chat = update.effective_chat args = context.args user_id = extract_user(message, args) member = chat.get_member(int(user_id)) if not user_id: message.reply_text("No conozco a ese usuario!") return "" if sql.is_approved(message.chat_id, user_id): message.reply_text( f"{member.user['first_name']} es un usuario libre. No se les aplicarán bloqueos, antiflood ni listas negras." ) else: message.reply_text( f"{member.user['first_name']} no es un usuario libre. Se verá afectado por los comandos." )
def reset_warns(update: Update, context: CallbackContext) -> str: args = context.args message: Optional[Message] = update.effective_message chat: Optional[Chat] = update.effective_chat user: Optional[User] = update.effective_user user_id = extract_user(message, args) if user_id: sql.reset_warns(user_id, chat.id) message.reply_text("Las advertencias se han restablecido!") warned = chat.get_member(user_id).user return ( f"<b>{html.escape(chat.title)}:</b>\n" f"#ReinicioAdvertencias\n" f"<b>Administrador:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Usuario:</b> {mention_html(warned.id, warned.first_name)}") else: message.reply_text("Ningún usuario ha sido designado!") return ""
def get_id(update: Update, context: CallbackContext): bot, args = context.bot, context.args message = update.effective_message chat = update.effective_chat msg = update.effective_message user_id = extract_user(msg, args) if user_id: if msg.reply_to_message and msg.reply_to_message.forward_from: user1 = message.reply_to_message.from_user user2 = message.reply_to_message.forward_from msg.reply_text( f"<b>Telegram IDs:</b>\n" f"• {html.escape(user2.first_name)} - <code>{user2.id}</code>.\n" f"• {html.escape(user1.first_name)} - <code>{user1.id}</code>.", parse_mode=ParseMode.HTML, ) else: user = bot.get_chat(user_id) msg.reply_text( f"<b>El ID de {html.escape(user.first_name)} es:</b> <code>{user.id}</code>.", parse_mode=ParseMode.HTML, ) else: if chat.type == "private": msg.reply_text(f"<b>Tu ID es:</b> <code>{chat.id}</code>.", parse_mode=ParseMode.HTML) else: msg.reply_text( f"<b>El ID de este grupo es:</b> <code>{chat.id}</code>.", parse_mode=ParseMode.HTML, )
def removesudo(update: Update, context: CallbackContext) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat bot, args = context.bot, context.args user_id = extract_user(message, args) user_member = bot.getChat(user_id) reply = check_user_id(user_id, bot) if reply: message.reply_text(reply) return "" with open(ELEVATED_USERS_FILE, "r") as infile: data = json.load(infile) if user_id in SUDO_USERS: message.reply_text("Rebajé a este usuario a Humano") SUDO_USERS.remove(user_id) data["sudos"].remove(user_id) with open(ELEVATED_USERS_FILE, "w") as outfile: json.dump(data, outfile, indent=4) log_message = ( f"#QuitaSuperusuario\n" f"<b>Administrador:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Usuario:</b> {mention_html(user_member.id, user_member.first_name)}" ) if chat.type != "private": log_message = "<b>{}:</b>\n".format(html.escape( chat.title)) + log_message return log_message else: message.reply_text("Este usuario no es un Destroyer!") return ""
def approve(update, context): message = update.effective_message chat_title = message.chat.title chat = update.effective_chat args = context.args user = update.effective_user user_id = extract_user(message, args) if not user_id: message.reply_text("No conozco a ese usuario!") return "" try: member = chat.get_member(user_id) except BadRequest: return "" if member.status == "administrator" or member.status == "creator": message.reply_text( "El usuario ya es administrador: los bloqueos, las listas de bloqueo y el antiflood ya no se aplican a ellos." ) return "" if sql.is_approved(message.chat_id, user_id): message.reply_text( f"[{member.user['first_name']}](tg://user?id={member.user['id']}) ya está libre en {chat_title}", parse_mode=ParseMode.MARKDOWN, ) return "" sql.approve(message.chat_id, user_id) message.reply_text( f"[{member.user['first_name']}](tg://user?id={member.user['id']}) ha sido liberado en {chat_title}. Ahora será ignorado por acciones de administración automatizadas como bloqueode la lista negra y anti-flood.", parse_mode=ParseMode.MARKDOWN, ) log_message = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#Libre\n" f"<b>Administrador:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Usuario:</b> {mention_html(member.user.id, member.user.first_name)}" ) return log_message
def unbl_user(update: Update, context: CallbackContext) -> str: message = update.effective_message user = update.effective_user bot, args = context.bot, context.args user_id = extract_user(message, args) if not user_id: message.reply_text("Dudo que sea un usuario.") return "" if user_id == bot.id: message.reply_text("Siempre me doy cuenta de mi misma.") return "" try: target_user = bot.get_chat(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 sql.is_user_blacklisted(user_id): sql.unblacklist_user(user_id) message.reply_text("Usuario quitado de la lista negra") log_message = ( f"#QuitaListaNegra\n" f"<b>Administrador:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Usuario:</b> {mention_html(target_user.id, target_user.first_name)}" ) return log_message else: message.reply_text("Sin embargo, no lo estoy ignorando en absoluto!") return ""
def removefrog(update: Update, context: CallbackContext) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat bot, args = context.bot, context.args user_id = extract_user(message, args) user_member = bot.getChat(user_id) reply = check_user_id(user_id, bot) if reply: message.reply_text(reply) return "" with open(ELEVATED_USERS_FILE, "r") as infile: data = json.load(infile) if user_id in FROG_USERS: message.reply_text("Rebajado a usuario normal") FROG_USERS.remove(user_id) data["frogs"].remove(user_id) with open(ELEVATED_USERS_FILE, "w") as outfile: json.dump(data, outfile, indent=4) log_message = ( f"#QuitaRana\n" f"<b>Administrador:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Usuario:</b> {mention_html(user_member.id, user_member.first_name)}" ) if chat.type != "private": log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message else: message.reply_text("Este usuario no es una Rana Gigante!") return ""
def demote(update: Update, context: CallbackContext) -> str: bot = context.bot args = context.args chat = update.effective_chat message = update.effective_message user = update.effective_user user_id = extract_user(message, args) if not user_id: message.reply_text( "No parece que se refiera a un usuario o el ID especificado es incorrecto." ) return try: user_member = chat.get_member(user_id) except: return if user_member.status == "creator": message.reply_text("Esta persona CREÓ el chat ¿Cómo la rebajaría?") return if not user_member.status == "administrator": message.reply_text("No puedo rebajar a alguien que no se ascendió!") return if user_id == bot.id: message.reply_text( "No puedo rebajarme! Necesito a un administrador para que lo haga por mí." ) return try: bot.promoteChatMember( chat.id, user_id, can_change_info=False, can_post_messages=False, can_edit_messages=False, can_delete_messages=False, can_invite_users=False, can_restrict_members=False, can_pin_messages=False, can_promote_members=False, ) bot.sendMessage( chat.id, f"<b>{user_member.user.first_name or user_id}</b> rebajado existosamente!", parse_mode=ParseMode.HTML, ) log_message = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#Rebajado\n" f"<b>Administrador:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Usuario:</b> {mention_html(user_member.user.id, user_member.user.first_name)}" ) return log_message except BadRequest: message.reply_text( "No lo puedo rebajar. Puede que no sea administrador o que el estado de administrador fue designado por otro" "administrador, por lo que no puedo actuar sobre ellos!") return
def info(update: Update, context: CallbackContext): bot, args = context.bot, context.args message = update.effective_message chat = update.effective_chat user_id = extract_user(update.effective_message, args) if user_id: user = bot.get_chat(user_id) elif not message.reply_to_message and not args: user = message.from_user elif not message.reply_to_message and ( not args or (len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not message.parse_entities([MessageEntity.TEXT_MENTION]))): message.reply_text("No puedo extraer un usuario de esto.") return else: return rep = message.reply_text("Buscando...") text = (f"<b>Información:</b>\n\n" f"<b>ID:</b> <code>{user.id}</code>\n" f"<b>Nombre:</b> {mention_html(user.id, user.first_name)} ") if user.last_name: text += f"{mention_html(user.id, user.last_name)}" if user.username: text += f"\n<b>Alías:</b> <code>{html.escape(user.username)}</code>" if chat.type != "private" and user_id != bot.id: _stext = "\n<b>Presencia:</b> <code>{}</code>" afk_st = is_afk(user.id) if afk_st: text += _stext.format("AFK") else: status = status = bot.get_chat_member(chat.id, user.id).status if status: if status in {"left", "kicked"}: text += _stext.format("Ausente") elif status == "member": text += _stext.format("Presente") elif status in {"administrator"}: text += _stext.format("Administrador") elif status in {"creator"}: text += _stext.format("Propietario") if user_id != bot.id: userhp = hpmanager(user) text += f"\n\n<b>Vida:</b> <code>{userhp['earnedhp']}/{userhp['totalhp']}</code>\n »{make_bar(int(userhp['percentage']))}« " text += f"[{userhp['percentage']}%] " text += '» [<a href="https://t.me/MeguRobotChannel/7">Info</a>]' try: spamwtc = sw.get_ban(int(user.id)) if spamwtc: text += "\n\n<b>Esta persona está vigilada por Spam!</b>" text += f"\n<b>Razón:</b> \n<pre>{spamwtc.reason}</pre>" text += "\n<b>Apelar en @SpamWatchSupport</b>" else: pass except: pass # don't crash if api is down somehow... disaster_level_present = False if user.id == OWNER_ID: text += "\n\n<b>Es Kazuma.</b>" disaster_level_present = True elif user.id in DEV_USERS: text += "\n\nEste usuario es un <b>Demonio Carmesí</b>." disaster_level_present = True elif user.id in SUDO_USERS: text += "\n\nEste usuario es un <b>Destroyer</b>." disaster_level_present = True elif user.id in SUPPORT_USERS: text += "\n\nEste usuario es un <b>Demonio</b>." disaster_level_present = True elif user.id in FROG_USERS: text += "\n\nEste usuario es una <b>Rana Gigante</b>." disaster_level_present = True elif user.id in WHITELIST_USERS: text += "\n\nEste usuario es un <b>Sapo Gigante</b>." disaster_level_present = True if disaster_level_present: text += '\n » [<a href="https://t.me/{}?start=adventurers">Info</a>]'.format( bot.username) try: user_member = chat.get_member(user.id) if user_member.status == "administrator": result = requests.post( f"https://api.telegram.org/bot{TOKEN}/getChatMember?chat_id={chat.id}&user_id={user.id}" ) result = result.json()["result"] if "custom_title" in result.keys(): custom_title = result["custom_title"] text += f"\n\n<b>Título:</b> <code>{custom_title}</code>" except BadRequest: pass for mod in USER_INFO: try: mod_info = mod.__user_info__(user.id).strip() except TypeError: mod_info = mod.__user_info__(user.id, chat.id).strip() if mod_info: text += "\n\n" + mod_info if INFOPIC: try: profile = bot.get_user_profile_photos(user.id).photos[0][-1] _file = bot.get_file(profile["file_id"]) _file.download(f"temp/{user.id}.png") message.reply_document( document=open(f"temp/{user.id}.png", "rb"), caption=(text), parse_mode=ParseMode.HTML, ) os.remove(f"temp/{user.id}.png") except BadRequest as e: if str(e) == "Reply message not found": message.reply_document( document=open(f"temp/{user.id}.png", "rb"), caption=text, parse_mode=ParseMode.HTML, quote=False, ) os.remove(f"temp/{user.id}.png") # Incase user don't have profile pic, send normal text except IndexError: message.reply_text(text, parse_mode=ParseMode.HTML, disable_web_page_preview=True) else: message.reply_text(text, parse_mode=ParseMode.HTML, disable_web_page_preview=True) rep.delete()
def promote(update: Update, context: CallbackContext) -> str: bot = context.bot args = context.args message = update.effective_message chat = update.effective_chat user = update.effective_user promoter = chat.get_member(user.id) if (not (promoter.can_promote_members or promoter.status == "creator") and not user.id in SUDO_USERS): message.reply_text("No tienes los derechos necesarios para hacer eso!") return user_id = extract_user(message, args) if not user_id: message.reply_text( "No parece que se refiera a un usuario o el ID especificado es incorrecto." ) return try: user_member = chat.get_member(user_id) except: return if user_member.status == "administrator" or user_member.status == "creator": message.reply_text( "¿Cómo se supone que debo ascender a alguien que ya es administrador?" ) return if user_id == bot.id: message.reply_text( "No puedo ascenderme! Necesito a un administrador para que lo haga por mí." ) return # set same perms as bot - bot can't assign higher perms than itself! bot_member = chat.get_member(bot.id) try: bot.promoteChatMember( chat.id, user_id, can_change_info=bot_member.can_change_info, can_post_messages=bot_member.can_post_messages, can_edit_messages=bot_member.can_edit_messages, can_delete_messages=bot_member.can_delete_messages, can_invite_users=bot_member.can_invite_users, # can_promote_members=bot_member.can_promote_members, can_restrict_members=bot_member.can_restrict_members, can_pin_messages=bot_member.can_pin_messages, ) except BadRequest as err: if err.message == "User_not_mutual_contact": message.reply_text( "No puedo ascender a alguien que no está en el grupo.") else: message.reply_text("Ocurrió un error al ascender.") return bot.sendMessage( chat.id, f"<b>{user_member.user.first_name or user_id}</b> ascendido exitosamente!", parse_mode=ParseMode.HTML, ) log_message = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#Asendido\n" f"<b>Administrador:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Usuario:</b> {mention_html(user_member.user.id, user_member.user.first_name)}" ) return log_message
def ungban(update: Update, context: CallbackContext): bot, args = context.bot, context.args message = update.effective_message user = update.effective_user chat = update.effective_chat log_message = "" user_id = extract_user(message, args) if not user_id: message.reply_text( "No parece que se refiera a un usuario o el ID especificado es incorrecto." ) return user_chat = bot.get_chat(user_id) if user_chat.type != "private": message.reply_text("Eso no es un usuario!") return if not sql.is_user_gbanned(user_id): message.reply_text("Este usuario no está globalmente baneado!") return message.reply_text( f"Le daré a {user_chat.first_name} una segunda oportunidad, a nivel global." ) start_time = time.time() datetime_fmt = "%Y-%m-%dT%H:%M" current_time = datetime.utcnow().strftime(datetime_fmt) if chat.type != "private": chat_origin = f"<b>{html.escape(chat.title)} ({chat.id})</b>\n" else: chat_origin = f"<b>{chat.id}</b>\n" log_message = ( f"#DesbaneoGlobal\n" f"<b>Originado desde:</b> <code>{chat_origin}</code>\n" f"<b>Administrador:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Usuario desbaneado:</b> {mention_html(user_chat.id, user_chat.first_name)}\n" f"<b>ID de Usuario desbaneado:</b> <code>{user_chat.id}</code>\n" f"<b>Evento Registrado:</b> <code>{current_time}</code>") if GLOBAL_LOGS: try: log = bot.send_message(GLOBAL_LOGS, log_message, parse_mode=ParseMode.HTML) except BadRequest as excp: log = bot.send_message( GLOBAL_LOGS, log_message + "\n\nEl formateo se ha deshabilitado debido a un error inesperado.", ) else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS, log_message, html=True) chats = get_all_chats() ungbanned_chats = 0 for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gbans if not sql.does_chat_gban(chat_id): continue try: member = bot.get_chat_member(chat_id, user_id) if member.status == "kicked": bot.unban_chat_member(chat_id, user_id) ungbanned_chats += 1 except BadRequest as excp: if excp.message in UNGBAN_ERRORS: pass else: message.reply_text( f"No se pudo cancelar el desbaneo global debido a: {excp.message}" ) if GLOBAL_LOGS: bot.send_message( GLOBAL_LOGS, f"No se pudo cancelar el desbaneo global debido a: {excp.message}", parse_mode=ParseMode.HTML, ) else: bot.send_message( OWNER_ID, f"No se pudo cancelar el desbaneo global debido a: {excp.message}", ) return except TelegramError: pass sql.ungban_user(user_id) if GLOBAL_LOGS: log.edit_text( log_message + f"\n<b>Chats afectados:</b> {ungbanned_chats}", parse_mode=ParseMode.HTML, ) else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Desbaneo global completado!") end_time = time.time() ungban_time = round((end_time - start_time), 2) if ungban_time > 60: ungban_time = round((ungban_time / 60), 2) message.reply_text( f"La persona ha sido desbaneada globalmente. Tomó {ungban_time} minuto's" ) else: message.reply_text( f"La persona ha sido desbaneada globalmente. Tomó {ungban_time} minuto's" )