def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("നിങ്ങൾ ഒരു ഉപഭോക്താവിനെ സൂചിപ്പിക്കുന്നതായി തോന്നുന്നില്ല.....") return if int(user_id) in SUDO_USERS: message.reply_text("ഞാൻ എന്താണീ കാണുന്നത്... SUDO USERS തമ്മിലുള്ള യുദ്ധമോ.... നിങ്ങൾ എന്താണ് ഇങ്ങനെ ചെറിയ കുട്ടികളെപ്പോലെ....") return if int(user_id) in SUPPORT_USERS: message.reply_text("ഇതെന്ത് മറിമായം.... SUPPORT USERനെ GBAN ചെയ്യാൻ നോക്കുന്നോ.... നടക്കില്ല മോനെ....") return if user_id == bot.id: message.reply_text("ഇതെന്ത് ഞാൻ എന്നെ GBAN ചെയ്യാനോ.... ഇങ്ങളെന്താ തമാശയാക്കാണ്... ") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("അങ്ങനെ ഒരാൾ ഇല്ല സർ..... >‿<") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text("ഇയാളെ പണ്ടെന്തോ ചെയ്തതിന് GBAN ആകിയിട്ടുള്ളതാണ്.... എന്തായാലും വേണ്ടില്ല നിങ്ങൾ പറഞ്ഞ ഈ പുതിയ കാരണം ഞാൻ ഓർത്ത് വയ്ക്കുന്നതാണ്.....") return old_reason = sql.update_gban_reason(user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text("ഇയാളെ മുൻപ് GBAN ചെയ്ത കാരണം..:\n" "<code>{}</code>\n" "നിങ്ങൾ ഇപ്പോൾ പറഞ്ഞ കാരണം ഞാൻ ഓർത്ത് വയ്ക്കുന്നതാണ്...".format(html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text("മുൻപ് GBAN ചെയ്തപ്പോൾ കാരണം ഒന്നും രേഖപെടുത്തിയിട്ടില്ലാരുന്നു... എന്തായാലും നിങ്ങൾ ഇപ്പോൾ പറഞ്ഞ കാരണം ഞാൻ ഓർമ്മിച്ച് വെക്കുന്നതാണ്....!") return message.reply_text("ഇതൊക്കെ എന്ത്.... ഇത് ചെറുത്... ◕‿↼ ") banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} is gbanning user {} " "because:\n{}".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), reason or "No reason given"), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() 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: bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text("Could not gban due to: {}".format(excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "gban complete!") message.reply_text("GBAN ചെയ്തിട്ടുണ്ട് ഇനി ഞാനുള്ള ഗ്രൂപ്പിന്റെ പരിസരത്തുകൂടി പോലും മൂപ്പർക്ക് വരാൻ പറ്റൂല്ല.... (๑◕︵◕๑) ")
def unfban(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] fed_id = sql.get_fed_id(chat.id) if not fed_id: update.effective_message.reply_text(tld(chat.id, "This group is not in any federation!")) return info = sql.get_fed_info(fed_id) if is_user_fed_admin(fed_id, user.id) == False: update.effective_message.reply_text(tld(chat.id, "Only fed admins can do this!")) return user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "You don't seem to be referring to a user.")) return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text(tld(chat.id, "That's not a user!")) return if sql.get_fban_user(fed_id, user_id) == False: message.reply_text(tld(chat.id, "This user is not fbanned!")) return banner = update.effective_user # type: Optional[User] message.reply_text(tld(chat.id, "I'll give {} a second chance in this federation.").format(user_chat.first_name)) h = sql.all_fed_chats(fed_id) for O in h: try: member = bot.get_chat_member(O, user_id) if member.status == 'kicked': bot.unban_chat_member(O, user_id) except BadRequest as excp: if excp.message in UNFBAN_ERRORS: pass else: message.reply_text(tld(chat.id, "Could not un-fban due to: {}").format(excp.message)) return except TelegramError: pass try: x = sql.un_fban_user(fed_id, user_id) if not x: message.reply_text(tld(chat.id, "Failed to fban, This user is probably fbanned!")) return except: pass message.reply_text(tld(chat.id, "Person has been un-fbanned.")) OW = bot.get_chat(info.owner_id) HAHA = OW.id FEDADMIN = sql.all_fed_users(fed_id) FEDADMIN.append(int(HAHA)) send_to_list(bot, FEDADMIN, "<b>Un-FedBan</b>" \ "\n<b>Fed:</b> {}" \ "\n<b>FedAdmin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>".format(info.fed_name, mention_html(user.id, user.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id), html=True)
def gmute(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text( "You don't seem to be referring to a user or the ID specified is incorrect.." ) return if int(user_id) in SUDO_USERS: message.reply_text( "I spy, with my little eye... a sudo user war! Why are you guys turning on each other?" ) return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH someone's trying to gmute a support user! *grabs popcorn*") return if user_id == bot.id: message.reply_text( "-_- So funny, lets gmute myself why don't I? Nice try.") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if sql.is_user_gmuted(user_id): if not reason: message.reply_text( "This user is already gmuted; I'd change the reason, but you haven't given me one..." ) return success = sql.update_gmute_reason( user_id, user_chat.username or user_chat.first_name, reason) if success: message.reply_text( "This user is already gmuted; I've gone and updated the gmute reason though!" ) else: message.reply_text( "Do you mind trying again? I thought this person was gmuted, but then they weren't? " "Am very confused") return message.reply_text("*Gets duct tape ready* 😉") muter = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Global Mute</b>" \ "\n#GMUTE" \ "\n<b>Status:</b> <code>Enforcing</code>" \ "\n<b>Sudo Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(mention_html(muter.id, muter.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason or "No reason given"), html=True) sql.gmute_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gmutes if not sql.does_chat_gmute(chat_id): continue try: bot.restrict_chat_member(chat_id, user_id, can_send_messages=False) except BadRequest as excp: if excp.message == "User is an administrator of the chat": pass elif excp.message == "Chat not found": pass elif excp.message == "Not enough rights to restrict/unrestrict chat member": pass elif excp.message == "User_not_participant": pass elif excp.message == "Peer_id_invalid": # Suspect this happens when a group is suspended by telegram. pass elif excp.message == "Group chat was deactivated": pass elif excp.message == "Need to be inviter of a user to kick it from a basic group": pass elif excp.message == "Chat_admin_required": pass elif excp.message == "Only the creator of a basic group can kick group administrators": pass elif excp.message == "Method is available only for supergroups": pass elif excp.message == "Can't demote chat creator": pass else: message.reply_text("Could not gmute due to: {}".format( excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Could not gmute due to: {}".format(excp.message)) sql.ungmute_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} has been successfully gmuted!".format( mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("They won't be talking again anytime soon.")
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return if int(user_id) in SUDO_USERS: message.reply_text("Now kiss each other!") return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH someone's trying to gban a support user! *grabs popcorn*") return if user_id == bot.id: message.reply_text("Lets gban myself why don't I? Good one.") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "This user is already gbanned; I'd change the reason, but you haven't given me one..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text( "This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text( "This user is already gbanned, but had no reason set; I've gone and updated it!" ) return message.reply_text("<i>Grabbing the banhammer and some popcorn</i>", parse_mode=ParseMode.HTML) banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} is globally banning user {} " "because:\n{}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), reason or "No reason given"), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() 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: bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text("Could not gban due to: {}".format( excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "gban complete!") message.reply_text("Person has been globally banned.")
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return if int(user_id) in SUDO_USERS: message.reply_text("I cant't Gban Sudo Users :V") return if user_id == OWNER_ID: message.reply_text("Nice try -_- but I'm never gonna gban him.") return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH someone's trying to gban a support user! *grabs popcorn*") return if user_id == bot.id: message.reply_text("What you are expecting? 😗") return if int(user_id) in (777000, 1087968824): message.reply_text("I can't GBAN Telegram bots!") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if user_chat.first_name == '': message.reply_text("That's a deleted account, no need to gban them!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "This user is already gbanned; I'd change the reason, but you haven't given me one..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if old_reason: if old_reason == reason: message.reply_text( "This user is already gbanned for the exact same reason!") else: message.reply_text( "This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text( "This user is already gbanned, but had no reason set; I've gone and updated it!" ) return message.reply_text("Initiating global ban for {}".format( mention_html(user_chat.id, user_chat.first_name)), parse_mode=ParseMode.HTML) banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Global Ban</b>" \ "\n#GBAN" \ "\n<b>Status:</b> <code>Enforcing</code>" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name or "Deleted Account"), user_chat.id, reason or "No reason given"), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() 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: bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message not in GBAN_ERRORS: message.reply_text("Could not gban due to: {}".format( excp.message)) send_to_list(bot, SUDO_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS, "Gban complete!") message.reply_text("Done! {} has been globally banned.".format( mention_html(user_chat.id, user_chat.first_name)), parse_mode=ParseMode.HTML) try: bot.send_message( user_id, "You've been globally banned from all groups where I am admin. If this is a mistake, you can appeal your Gban @CtrlSupport", parse_mode=ParseMode.HTML) except: pass #Bot either blocked or never started by user
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( "You don't seem to be referring to a user or the ID specified is incorrect.." ) return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("That's not a user!") return if not sql.is_user_gbanned(user_id): message.reply_text("This user is not gbanned!") return message.reply_text( f"I'll give {user_chat.first_name} a second chance, globally.") 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"#UNGBANNED\n" f"<b>Originated from:</b> <code>{chat_origin}</code>\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Unbanned User:</b> {mention_html(user_chat.id, user_chat.first_name)}\n" f"<b>Unbanned User ID:</b> <code>{user_chat.id}</code>\n" f"<b>Event Stamp:</b> <code>{current_time}</code>") if EVENT_LOGS: try: log = bot.send_message(EVENT_LOGS, log_message, parse_mode=ParseMode.HTML) except BadRequest as excp: log = bot.send_message( EVENT_LOGS, log_message + "\n\nFormatting has been disabled due to an unexpected error.") else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS, log_message, html=True) chats = get_user_com_chats(user_id) ungbanned_chats = 0 for chat in chats: chat_id = int(chat) # 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"Could not un-gban due to: {excp.message}") if EVENT_LOGS: bot.send_message( EVENT_LOGS, f"Could not un-gban due to: {excp.message}", parse_mode=ParseMode.HTML) else: bot.send_message( OWNER_ID, f"Could not un-gban due to: {excp.message}") return except TelegramError: pass sql.ungban_user(user_id) if EVENT_LOGS: log.edit_text(log_message + f"\n<b>Chats affected:</b> {ungbanned_chats}", parse_mode=ParseMode.HTML) else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "un-gban complete!") 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"Person has been un-gbanned. Took {ungban_time} min") else: message.reply_text( f"Person has been un-gbanned. Took {ungban_time} sec")
def ungban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if not user_id: message.reply_text("لا يبدو أنك تشير إلى مستخدم.") return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("هذا ليس المستخدم!") return if not sql.is_user_gbanned(user_id): message.reply_text("هذا المستخدم ليس gbanned!") return banner = update.effective_user # type: Optional[User] message.reply_text("أنا عفوا {}، عالميا مع فرصة ثانية.".format( user_chat.first_name)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>انحدار الحظر العالمي</b>" \ "\n#الغاء_الحظر" \ "\n<b>الحالة:</b> <code>Ceased</code>" \ "\n<b>بواسطة المشرف:</b> {}" \ "\n<b>للمستخدم:</b> {}" \ "\n<b>ID:</b> <code>{}</code>".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id), html=True) chats = get_all_chats() 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) except BadRequest as excp: if excp.message in UNGBAN_ERRORS: pass else: message.reply_text( "لا يمكن الأمم المتحدة غيابان بسبب: {}".format( excp.message)) bot.send_message( OWNER_ID, "لا يمكن الأمم المتحدة غيابان بسبب: {}".format( excp.message)) return except TelegramError: pass sql.ungban_user(user_id) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} وقد عفو عن الحظر!".format( mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("لقد تم منح هذا الشخص غير غالبون ومكفوا!")
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message user = update.effective_user chat = update.effective_chat log_message = "" user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("Anda sepertinya tidak mengacu pada pengguna.") return if int(user_id) in DEV_USERS: message.reply_text( "Pengguna itu adalah bagian dari Serikat\nSaya tidak bisa bertindak melawan kita sendiri." ) return if int(user_id) in SUDO_USERS: message.reply_text( "Aku memata-matai, dengan mata kecilku ...! Mengapa kalian saling menyerang?" ) return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH seseorang mencoba memberi Negara Sakura! *meraih popcorn*") return if int(user_id) in SARDEGNA_USERS: message.reply_text("Itu Sardegna! Mereka tidak bisa dilarang!") return if int(user_id) in WHITELIST_USERS: message.reply_text("Itu adalah Neptunia! Mereka tidak bisa dilarang!") return if int(user_id) in (777000, 1087968824): message.reply_text("Hah, kenapa saya gban Telegram bot?") return if user_id == bot.id: message.reply_text("Kamu uhh ... ingin aku bunuh diri?") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: if excp.message == "Pengguna tidak ditemukan": message.reply_text( "Sepertinya saya tidak dapat menemukan pengguna ini.") return "" else: return if user_chat.type != "private": message.reply_text("Itu bukan pengguna!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "Pengguna ini sudah diblokir; Saya akan mengubah alasannya, tetapi Anda belum memberi saya satu pun..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text( "Pengguna ini sudah diblokir, karena alasan berikut:\n" "<code>{}</code>\n" "Saya telah pergi dan memperbaruinya dengan alasan baru Anda!". format(html.escape(old_reason)), parse_mode=ParseMode.HTML, ) else: message.reply_text( "Pengguna ini sudah diblokir, tetapi tidak ada alasan yang ditetapkan; Saya telah pergi dan memperbaruinya!" ) return message.reply_text("On it!") start_time = time.time() datetime_fmt = "%H:%M - %d-%m-%Y" current_time = datetime.utcnow().strftime(datetime_fmt) if chat.type != "private": chat_origin = "<b>{} ({})</b>\n".format(html.escape(chat.title), chat.id) else: chat_origin = "<b>{}</b>\n".format(chat.id) log_message = ( f"#GBANNED\n" f"<b>Berasal dari:</b> {chat_origin}\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Pengguna yang Dilarang:</b> {mention_html(user_chat.id, user_chat.first_name)}\n" f"<b>ID Pengguna yang Dilarang:</b> {user_chat.id}\n" f"<b>Event Stamp:</b> {current_time}") if reason: if chat.type == chat.SUPERGROUP and chat.username: log_message += f'\n<b>Alasan:</b> <a href="http://telegram.me/{chat.username}/{message.message_id}">{reason}</a>' else: log_message += f"\n<b>Alasan:</b> {reason}" if GBAN_LOGS: try: log = bot.send_message(GBAN_LOGS, log_message, parse_mode=ParseMode.HTML) except BadRequest as excp: log = bot.send_message( GBAN_LOGS, log_message + "\n\nPemformatan telah dinonaktifkan karena kesalahan yang tidak terduga.", ) else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS, log_message, html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() gbanned_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: bot.kick_chat_member(chat_id, user_id) gbanned_chats += 1 except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text( f"Tidak bisa memberi karena: {excp.message}") if GBAN_LOGS: bot.send_message( GBAN_LOGS, f"Tidak bisa memberi karena {excp.message}", parse_mode=ParseMode.HTML, ) else: send_to_list( bot, SUDO_USERS + SUPPORT_USERS, f"Tidak bisa memberi karena: {excp.message}", ) sql.ungban_user(user_id) return except TelegramError: pass if GBAN_LOGS: log.edit_text( log_message + f"\n<b>Obrolan terpengaruh:</b> {gbanned_chats}", parse_mode=ParseMode.HTML, ) else: send_to_list( bot, SUDO_USERS + SUPPORT_USERS, f"Gban selesai! (Pengguna dilarang masuk {gbanned_chats} obrolan)", ) end_time = time.time() gban_time = round((end_time - start_time), 2) if gban_time > 60: gban_time = round((gban_time / 60), 2) message.reply_text( f"Selesai! Gban ini terpengaruh {gbanned_chats} obrolan, Lihat {gban_time} menit" ) else: message.reply_text( f"Selesai! Gban ini terpengaruh {gbanned_chats} obrolan, Lihat {gban_time} detik" ) try: bot.send_message( user_id, "Anda telah diblokir secara global dari semua grup di mana saya memiliki izin administratif." "Jika menurut Anda ini adalah kesalahan, Anda dapat mengajukan banding di master saya.", parse_mode=ParseMode.HTML, ) except: pass # bot probably blocked by user
def fed_ban(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) if not fed_id: update.effective_message.reply_text("This group is not a part of any federation!") return info = sql.get_fed_info(fed_id) OW = bot.get_chat(info['owner']) HAHA = OW.id FEDADMIN = sql.all_fed_users(fed_id) FEDADMIN.append(int(HAHA)) if is_user_fed_admin(fed_id, user.id) == False: update.effective_message.reply_text("Only federation admins can do this!") return message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) fban, fbanreason = sql.get_fban_user(fed_id, user_id) if not user_id: message.reply_text("You don't seem to be referring to a user.") return if user_id == bot.id: message.reply_text("Nice try!") return if is_user_fed_owner(fed_id, user_id) == True: message.reply_text("You can't ban the federation owner!") return if is_user_fed_admin(fed_id, user_id) == True: message.reply_text("Why are you trying to ban a federation admin?") return if user_id == OWNER_ID: message.reply_text("I'm not gonna ban my owner!") return if int(user_id) in SUDO_USERS: message.reply_text("This person is sudo so I won't ban them!") return if int(user_id) in WHITELIST_USERS: message.reply_text("This person is whitelisted so I can't ban them!") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if fban: user_target = mention_html(user_chat.id, user_chat.first_name) fed_name = info['fname'] starting = "Starting FedBan for {} in the Federation <b>{}</b>is for\n".format(user_target, fed_name) update.effective_message.reply_text(starting, parse_mode=ParseMode.HTML) if reason == "": reason = "No reason given." temp = sql.un_fban_user(fed_id, user_id) if not temp: message.reply_text("Failed to update fban reason!") return x = sql.fban_user(fed_id, user_id, user_chat.first_name, user_chat.last_name, user_chat.username, reason) if not x: message.reply_text("Failed to ban from the federation! If this problem persists, reach out to us @CtrlSupport.") return fed_chats = sql.all_fed_chats(fed_id) for chat in fed_chats: try: bot.kick_chat_member(chat, user_id) except BadRequest as excp: if excp.message in FBAN_ERRORS: pass else: LOGGER.warning("Could not fban in {} because: {}".format(chat, excp.message)) except TelegramError: pass send_to_list(bot, FEDADMIN, "<b>FedBan reason updated</b>" \ "\n<b>Federation:</b> {}" \ "\n<b>Federation Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(fed_name, mention_html(user.id, user.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason), html=True) message.reply_text("I've updated the FedBan reason!") return user_target = mention_html(user_chat.id, user_chat.first_name) fed_name = info['fname'] starting = "Starting a federation ban for {} in the Federation <b>{}</b>.".format(user_target, fed_name) update.effective_message.reply_text(starting, parse_mode=ParseMode.HTML) if reason == "": reason = "No reason given." x = sql.fban_user(fed_id, user_id, user_chat.first_name, user_chat.last_name, user_chat.username, reason) if not x: message.reply_text("Failed to ban from the federation! If this problem persists, reach out to us @PhoenixSupport.") return fed_chats = sql.all_fed_chats(fed_id) for chat in fed_chats: try: bot.kick_chat_member(chat, user_id) except BadRequest as excp: if excp.message in FBAN_ERRORS: try: dispatcher.bot.getChat(chat) except Unauthorized: sql.chat_leave_fed(chat) LOGGER.info("Chat {} has left fed {} because bot has been kicked.".format(chat, info['fname'])) continue else: LOGGER.warning("Cannot fban in {} because: {}".format(chat, excp.message)) except TelegramError: pass send_to_list(bot, FEDADMIN, "<b>New FedBan</b>" \ "\n<b>Federation:</b> {}" \ "\n<b>Federation Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(fed_name, mention_html(user.id, user.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason), html=True) message.reply_text("{} has been fbanned.".format(mention_html(user_chat.id, user_chat.first_name)), parse_mode=ParseMode.HTML)
def gban(update: Update, context: CallbackContext): bot = context.bot args = context.args message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] user_id, reason = extract_user_and_text(message, args) if not user_id or int(user_id) == 777000 or int(user_id) == 1087968824: message.reply_text("You don't seem to be referring to a user.") return if int(user_id) in SUDO_USERS: message.reply_text("Now kiss each other!") return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH someone's trying to gban a support user! *grabs popcorn*") return if user_id == bot.id: message.reply_text("Lets gban myself why don't I? Good one.") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return try: update.effective_chat.kick_member(user_id) except: pass if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "This user is already gbanned; I'd change the reason, but you haven't given me one..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) user_id, new_reason = extract_user_and_text(message, args) if old_reason: banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Emendation of Global Ban</b>" \ "\n#GBAN" \ "\n<b>Status:</b> <code>Amended</code>" \ "\n<b>Sudo Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>ID:</b> <code>{}</code>" \ "\n<b>Previous Reason:</b> {}" \ "\n<b>Amended Reason:</b> {}".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name or "Deleted Account"), user_chat.id, old_reason, new_reason), html=True) message.reply_text( "This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML) else: banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Emendation of Global Ban</b>" \ "\n#GBAN" \ "\n<b>Status:</b> <code>New reason</code>" \ "\n<b>Sudo Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>ID:</b> <code>{}</code>" \ "\n<b>New Reason:</b> {}".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name or "Deleted Account"), user_chat.id, new_reason), html=True) message.reply_text( "This user is already gbanned, but had no reason set; I've gone and updated it!" ) return starting = "Initiating global ban for {}...".format( mention_html(user_chat.id, user_chat.first_name or "Deleted Account")) keyboard = [] # message.reply_text(starting, reply_markup=keyboard, parse_mode=ParseMode.HTML) banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Global Ban</b>" \ "\n#GBAN" \ "\n<b>Status:</b> <code>Enforcing</code>" \ "\n<b>Sudo Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name or "Deleted Account"), user_chat.id, reason or "No reason given"), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() 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: bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text("Could not gban due to: {}".format( excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} has been successfully gbanned!".format( mention_html(user_chat.id, user_chat.first_name or "Deleted Account")), html=True) message.reply_text("Person has been gbanned.")
def ungban(bot: Bot, update: Update, args: List[str]): 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("Anda sepertinya tidak mengacu pada pengguna.") return user_chat = bot.get_chat(user_id) if user_chat.type != "private": message.reply_text("Itu bukan pengguna!") return if not sql.is_user_gbanned(user_id): message.reply_text("Pengguna ini tidak dilarang!") return message.reply_text( f"Saya akan memberi {user_chat.first_name} kesempatan kedua, secara global." ) start_time = time.time() datetime_fmt = "%H:%M - %d-%m-%Y" 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"#UNGBANNED\n" f"<b>Berasal dari:</b> {chat_origin}\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Pengguna yang Tidak Dicekal:</b> {mention_html(user_chat.id, user_chat.first_name)}\n" f"<b>ID Pengguna yang Tidak Dicekal:</b> {user_chat.id}\n" f"<b>Event Stamp:</b> {current_time}") if GBAN_LOGS: try: log = bot.send_message(GBAN_LOGS, log_message, parse_mode=ParseMode.HTML) except BadRequest as excp: log = bot.send_message( GBAN_LOGS, log_message + "\n\nPemformatan telah dinonaktifkan karena kesalahan yang tidak terduga.", ) 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"Tidak dapat membatalkan gban karena: {excp.message}") if GBAN_LOGS: bot.send_message( GBAN_LOGS, f"Tidak dapat membatalkan gban karena: {excp.message}", parse_mode=ParseMode.HTML, ) else: bot.send_message( OWNER_ID, f"Tidak dapat membatalkan gban karena: {excp.message}") return except TelegramError: pass sql.ungban_user(user_id) if GBAN_LOGS: log.edit_text( log_message + f"\n<b>Obrolan terpengaruh:</b> {ungbanned_chats}", parse_mode=ParseMode.HTML, ) else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "un-gban selesai!") 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"Blokir orang telah dibatalkan. Lihat {ungban_time} menit") else: message.reply_text( f"Blokir orang telah dibatalkan. Lihat {ungban_time} detik")
def gmute(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("Gelecek sefer birisini hedef almaya çalış.") return if int(user_id) in SUDO_USERS: message.reply_text("Sakin ol adamım, böyle bir şey olmayacak!") return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH Birisi destek kullanıcımı gmutelemeye çalışıyor.") return if user_id == bot.id: message.reply_text( "-_- Çok eğlenceli. Kendimi küresel olarak susturmalıyım, neden olmasın? Güzel deneme." ) return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("Bu bir kullanıcı değil!") return if sql.is_user_gmuted(user_id): if not reason: message.reply_text( "Bu kullanıcı zaten gmuteli; Sebebini değiştirebilirdim ama, ama bana sebep vermedin..." ) return success = sql.update_gmute_reason( user_id, user_chat.username or user_chat.first_name, reason) if success: message.reply_text( "Bu kullanıcı zaten gmuteli. Sebebini gittim ve güncelledim!") else: message.reply_text( "Yeniden düşünmeme izin ver. Bu kullanıcı zaten gmuteliydi. Yoksa değilmiydi? " "Kafam karıştı") return message.reply_text("Kapa çeneni 🤐") muter = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Global Mute</b>" \ "\n#GMUTE" \ "\n<b>Durum:</b> <code>Etkin</code>" \ "\n<b>Sudo Admin:</b> {}" \ "\n<b>Kullanıcı:</b> {}" \ "\n<b>ID:</b> <code>{}</code>" \ "\n<b>Sebep:</b> {}".format(mention_html(muter.id, muter.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason or "Sebep belirtmedi"), html=True) sql.gmute_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gmutes if not sql.does_chat_gmute(chat_id): continue try: bot.restrict_chat_member(chat_id, user_id, can_send_messages=False) except BadRequest as excp: if excp.message == "User is an administrator of the chat": pass elif excp.message == "Chat not found": pass elif excp.message == "Not enough rights to restrict/unrestrict chat member": pass elif excp.message == "User_not_participant": pass elif excp.message == "Peer_id_invalid": # Suspect this happens when a group is suspended by telegram. pass elif excp.message == "Group chat was deactivated": pass elif excp.message == "Need to be inviter of a user to kick it from a basic group": pass elif excp.message == "Chat_admin_required": pass elif excp.message == "Only the creator of a basic group can kick group administrators": pass elif excp.message == "Method is available only for supergroups": pass elif excp.message == "Can't demote chat creator": pass else: message.reply_text( "Şu sebepten dolayı gmuteleyemedim: {}".format( excp.message)) send_to_list( bot, SUDO_USERS + SUPPORT_USERS, "Şu sebepten dolayı gmuteleyemedim: {}".format( excp.message)) sql.ungmute_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} Küresel olarak susturuldu!".format( mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("Yakın bir zamanda bir daha konuşamayacaksın.")
def ungmute(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if not user_id: message.reply_text("Gelecek sefer birisini hedef almaya çalış.") return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("Bu bir kullanıcı değil!") return if not sql.is_user_gmuted(user_id): message.reply_text("Bu kullanıcı küresel olarak susturulmuş değil!") return muter = update.effective_user # type: Optional[User] message.reply_text( "{} Kullanıcısına konuşma hakkını geri veriyorum.".format( user_chat.first_name)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Regression of Global Mute</b>" \ "\n#UNGMUTE" \ "\n<b>Durum:</b> <code>Devre dışı</code>" \ "\n<b>Sudo Admin:</b> {}" \ "\n<b>Kullanıcı:</b> {}" \ "\n<b>ID:</b> <code>{}</code>".format(mention_html(muter.id, muter.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id), html=True) chats = get_all_chats() for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gmutes if not sql.does_chat_gmute(chat_id): continue try: member = bot.get_chat_member(chat_id, user_id) if member.status == 'restricted': bot.restrict_chat_member(chat_id, int(user_id), can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True) except BadRequest as excp: if excp.message == "User is an administrator of the chat": pass elif excp.message == "Chat not found": pass elif excp.message == "Not enough rights to restrict/unrestrict chat member": pass elif excp.message == "User_not_participant": pass elif excp.message == "Method is available for supergroup and channel chats only": pass elif excp.message == "Not in the chat": pass elif excp.message == "Channel_private": pass elif excp.message == "Chat_admin_required": pass else: message.reply_text( "Şu sebepten dolayı küresel olarak susturmayı kaldıramadım: {}" .format(excp.message)) bot.send_message( OWNER_ID, "Şu sebepten dolayı küresel olarak susturmayı kaldıramadım: {}" .format(excp.message)) return except TelegramError: pass sql.ungmute_user(user_id) send_to_list( bot, SUDO_USERS + SUPPORT_USERS, "{} kullanıcısının başarıyla küresel susturulması kaldırıldı!".format( mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("Küresel susturma kaldırıldı.")
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You should refer a user first.") return if int(user_id) in SUDO_USERS: message.reply_text("I think this is a Sudo war, am i right?") return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH someone's trying to gban a support user! *grabs popcorn*") return if user_id == bot.id: message.reply_text( "-_- So funny, lets gban myself why don't I? Nice try.") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "This user is already gbanned; I'd change the reason, but you haven't given me one..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text( "This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text( "This user is already gbanned, but had no reason set; I've gone and updated it!" ) return message.reply_text("*Wait a Sec, Doing My work* 😉") banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} is gbanning user {} " "Reason:\n{}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), reason or "No reason given"), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() 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: bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text("Could not gban due to: {}".format( excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Gbanned 😅!") message.reply_text("The User Is Now Gbanned 😒!!!.")
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("사용자를 지칭하는 것 같지 않아요.") return if int(user_id) in SUDO_USERS: message.reply_text("전 제 작은 눈으로 관리자 전쟁을 봤어요... 왜 서로 등을 돌리세요?") return if int(user_id) in SUPPORT_USERS: message.reply_text("어머... 누군가가 SUPPORT 유저를 글로벌 밴하려고 하고 있네요!") return if user_id == bot.id: message.reply_text("-_- 저를 GBAN 하려고 한 거예요...? ㅠㅠ") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("유저가 아니에요!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "이 사용자는 이미 글로벌 밴 당했어요; 제가 이유를 바꾸긴 할 거지만 당신은 저에게 아무 이유도 알려주지 않았어요!!! ㅠㅠ" ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text("이 유저는 이미 이 이유에 따라 글로벌 밴 당했어요:\n" "<code>{}</code>\n" "제가 가서 새로운 이유로 업데이트했어요!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text( "이 유저는 이미 글로벌 밴 당했지만, 이유를 나타내지 않았어요; 제가 가서 업데이트했어요!") return message.reply_text("*GBAN 예정이에요! 안녕히가세요!* ;)") banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} is gbanning user {} " "because:\n{}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), reason or "No reason given"), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() 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: bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text("다음 이유로 인해 GBAN 할 수 없어요 : {}".format( excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "다음 이유로 인해 GBAN 할 수 없어요: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "GBAN 완료!") message.reply_text("그 사람은 GBAN 되었어요.")
def gban(update, context): message = update.effective_message # type: Optional[Message] args = context.args user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return if user_id == OWNER_ID: message.reply_text("I'm not gonna Gban my master nice try -_-") return if int(user_id) in SUDO_USERS: message.reply_text("I spy, with my little eye... a sudo user war! Why are you guys turning on each other?") return if int(user_id) in SUPPORT_USERS: message.reply_text("OOOH someone's trying to gban a support user! *grabs popcorn*") return if user_id == context.bot.id: message.reply_text("-_- So funny, lets gban myself why don't I? Nice try.") return try: user_chat = context.bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text("This user is already gbanned; I'd change the reason, but you haven't given me one...") return old_reason = sql.update_gban_reason(user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text("This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format(html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text("This user is already gbanned, but had no reason set; I've gone and updated it!") return message.reply_text("*Blows dust off of banhammer* 😉") banner = update.effective_user # type: Optional[User] send_to_list(context.bot, SUDO_USERS + SUPPORT_USERS, "{} is gbanning user {} " "because:\n{}".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), reason or "No reason given"), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() 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: context.bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text("Could not gban due to: {}".format(excp.message)) send_to_list(context.bot, SUDO_USERS + SUPPORT_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(context.bot, SUDO_USERS + SUPPORT_USERS, "gban complete!") message.reply_text("Person has been gbanned.")
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message user = update.effective_user chat = update.effective_chat log_message = "" user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return if int(user_id) in DEV_USERS: message.reply_text("There is no way I can gban this user.") return if int(user_id) in SUDO_USERS: message.reply_text("This user is my SUDO so pls F**K OFF!") return if int(user_id) in SUPPORT_USERS: message.reply_text("You want to gban my SUPPORT USER huh?? F**K OFF!!") return if int(user_id) in WHITELIST_USERS: message.reply_text("I can't ban my master's close frd.") return if user_id == bot.id: message.reply_text("I Can't ban my self you dumb ass 😂.") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user.") return "" else: return if user_chat.type != 'private': message.reply_text("That's not a user!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "This user is already gbanned; I'd change the reason, but you haven't given me one..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text( "This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text( "This user is already gbanned, but had no reason set; I've gone and updated it!" ) return message.reply_text("On it!") start_time = time.time() datetime_fmt = "%H:%M - %d-%m-%Y" current_time = datetime.utcnow().strftime(datetime_fmt) if chat.type != 'private': chat_origin = "<b>{} ({})</b>\n".format(html.escape(chat.title), chat.id) else: chat_origin = "<b>{}</b>\n".format(chat.id) log_message = ( f"#GBANNED\n" f"<b>Originated from:</b> {chat_origin}\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Banned User:</b> {mention_html(user_chat.id, user_chat.first_name)}\n" f"<b>Banned User ID:</b> {user_chat.id}\n" f"<b>Event Stamp:</b> {current_time}") if reason: if chat.type == chat.SUPERGROUP and chat.username: log_message += f"\n<b>Reason:</b> <a href=\"http://telegram.me/{chat.username}/{message.message_id}\">{reason}</a>" else: log_message += f"\n<b>Reason:</b> {reason}" if GBAN_LOGS: try: log = bot.send_message(GBAN_LOGS, log_message, parse_mode=ParseMode.HTML) except BadRequest as excp: log = bot.send_message( GBAN_LOGS, log_message + "\n\nFormatting has been disabled due to an unexpected error.") else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS, log_message, html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() gbanned_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: bot.kick_chat_member(chat_id, user_id) gbanned_chats += 1 except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text(f"Could not gban due to: {excp.message}") if GBAN_LOGS: bot.send_message(GBAN_LOGS, f"Could not gban due to {excp.message}", parse_mode=ParseMode.HTML) else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS, f"Could not gban due to: {excp.message}") sql.ungban_user(user_id) return except TelegramError: pass if GBAN_LOGS: log.edit_text(log_message + f"\n<b>Chats affected:</b> {gbanned_chats}", parse_mode=ParseMode.HTML) else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS, f"Gban complete! (User banned in {gbanned_chats} chats)") end_time = time.time() gban_time = round((end_time - start_time), 2) if gban_time > 60: gban_time = round((gban_time / 60), 2) message.reply_text( f"Done! This gban affected {gbanned_chats} chats, Took {gban_time} min" ) else: message.reply_text( f"Done! This gban affected {gbanned_chats} chats, Took {gban_time} sec" ) try: bot.send_message( user_id, "You have been globally banned from all groups where I have administrative permissions." " If you think that this was a mistake, you may appeal your ban here: @allukatm", parse_mode=ParseMode.HTML) except: pass # bot probably blocked by user
def ungban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("That's not a user!") return banner = update.effective_user # type: Optional[User] message.reply_text("I'll give {} a second chance, globally.".format( user_chat.first_name)) send_to_list( bot, SUDO_USERS + SUPPORT_USERS, "[{}](tg://user?id={}) has ungbanned user [{}](tg://user?id={})". format(escape_markdown(banner.first_name), banner.id, escape_markdown(user_chat.first_name), user_chat.id), markdown=True) sql.ungban_user(user_id) chats = get_all_chats() 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) from tg_bot import LOGGER LOGGER.info(f"{member.status}") if member.status == 'kicked': bot.unban_chat_member(chat_id, user_id) except BadRequest as excp: from tg_bot import LOGGER LOGGER.exception("WTH IS THIS '{}'".format(excp.message)) if excp.message == "User is an administrator of the chat": pass elif excp.message == "Chat not found": pass elif excp.message == "Not enough rights to restrict/unrestrict chat member": pass elif excp.message == "User_not_participant": pass elif excp.message == "Method is available for supergroup and channel chats only": pass elif excp.message == "Not in the chat": pass else: message.reply_text("Could not un-gban due to: {}".format( excp.message)) bot.send_message( OWNER_ID, "Could not un-gban due to: {}".format(excp.message)) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "un-gban complete!") message.reply_text("Person has been un-gbanned.")
def gban(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, reason = extract_user_and_text(message, args) if not user_id: message.reply_text( "You don't seem to be referring to a user or the ID specified is incorrect.." ) return if int(user_id) in DEV_USERS: message.reply_text( "That user is part of the Association\nI can't act against our own." ) return if int(user_id) in SUDO_USERS: message.reply_text( "I spy, with my little eye... a disaster! Why are you guys turning on each other?" ) return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH someone's trying to gban a Demon Disaster! *grabs popcorn*") return if int(user_id) in WHITELIST_USERS: message.reply_text("That's a Wolf! They cannot be banned!") return if user_id == bot.id: message.reply_text("You uhh...want me to punch myself?") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user.") return "" return if user_chat.type != 'private': message.reply_text("That's not a user!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "This user is already gbanned; I'd change the reason, but you haven't given me one..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text( "This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text( "This user is already gbanned, but had no reason set; I've gone and updated it!" ) return message.reply_text("On it!") start_time = time.time() datetime_fmt = "%Y-%m-%dT%H:%M" current_time = datetime.utcnow().strftime(datetime_fmt) if chat.type != 'private': chat_origin = "<b>{} ({})</b>\n".format(html.escape(chat.title), chat.id) else: chat_origin = "<b>{}</b>\n".format(chat.id) log_message = ( f"#GBANNED\n" f"<b>Originated from:</b> <code>{chat_origin}</code>\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Banned User:</b> {mention_html(user_chat.id, user_chat.first_name)}\n" f"<b>Banned User ID:</b> <code>{user_chat.id}</code>\n" f"<b>Event Stamp:</b> <code>{current_time}</code>") if reason: if chat.type == chat.SUPERGROUP and chat.username: log_message += f"\n<b>Reason:</b> <a href=\"https://telegram.me/{chat.username}/{message.message_id}\">{reason}</a>" else: log_message += f"\n<b>Reason:</b> <code>{reason}</code>" if EVENT_LOGS: try: log = bot.send_message(EVENT_LOGS, log_message, parse_mode=ParseMode.HTML) except BadRequest as excp: log = context.bot.send_message( EVENT_LOGS, log_message + "\n\nFormatting has been disabled due to an unexpected error.") else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS, log_message, html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_user_com_chats(user_id) gbanned_chats = 0 for chat in chats: chat_id = int(chat) # Check if this group has disabled gbans if not sql.does_chat_gban(chat_id): continue try: bot.kick_chat_member(chat_id, user_id) gbanned_chats += 1 except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text(f"Could not gban due to: {excp.message}") if EVENT_LOGS: bot.send_message(EVENT_LOGS, f"Could not gban due to {excp.message}", parse_mode=ParseMode.HTML) else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS, f"Could not gban due to: {excp.message}") sql.ungban_user(user_id) return except TelegramError: pass if EVENT_LOGS: log.edit_text(log_message + f"\n<b>Chats affected:</b> <code>{gbanned_chats}</code>", parse_mode=ParseMode.HTML) else: send_to_list( bot, SUDO_USERS + SUPPORT_USERS, f"Gban complete! (User banned in <code>{gbanned_chats}</code> chats)", html=True) end_time = time.time() gban_time = round((end_time - start_time), 2) if gban_time > 60: gban_time = round((gban_time / 60), 2) message.reply_text("Done! Gbanned.", parse_mode=ParseMode.HTML) else: message.reply_text("Done! Gbanned.", parse_mode=ParseMode.HTML) try: bot.send_message( user_id, "#EVENT" "You have been marked as Malicious and as such have been banned from any future groups we manage." f"\n<b>Reason:</b> <code>{html.escape(user.reason)}</code>" f"</b>Appeal Chat:</b> @{SUPPORT_CHAT}", parse_mode=ParseMode.HTML) except: pass # bot probably blocked by user
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return if int(user_id) in SUDO_USERS: message.reply_text( "I spy, with my little eye... a sudo user war! Why are you guys turning on each other?" ) return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH someone's trying to gban a support user! *grabs popcorn*") return if user_id == bot.id: message.reply_text( "-_- So funny, lets gban myself why don't I? Nice try.") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return message.reply_text("*Blows dust off of banhammer* 😉") banner = update.effective_user # type: Optional[User] send_to_list( bot, SUDO_USERS + SUPPORT_USERS, "[{}](tg://user?id={}) is gbanning user [{}](tg://user?id={}) " "because:\n{}".format(escape_markdown(banner.first_name), banner.id, escape_markdown(user_chat.first_name), user_chat.id, reason or "No reason given"), markdown=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() 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: bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message == "User is an administrator of the chat": pass elif excp.message == "Chat not found": pass elif excp.message == "Not enough rights to restrict/unrestrict chat member": pass elif excp.message == "User_not_participant": pass else: message.reply_text("Could not gban due to: {}".format( excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "gban complete!") message.reply_text("Person has been gbanned.")
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("لا يبدو أنك تشير إلى مستخدم.") return if int(user_id) in SUDO_USERS: message.reply_text( "أنا جاسوس، مع عيني الصغيرة ... حرب مستخدم SUDO! لماذا أنت تحول يا رفاق بعضهم البعض؟" ) return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH يحاول شخص ما GBAN مستخدم الدعم! * الاستيلاء على الفشار *") return if user_id == bot.id: message.reply_text( "- - - مضحك جدا، يتيح GBAN بنفسي لماذا لا؟ محاولة لطيفة.") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("هذا ليس المستخدم!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "هذا المستخدم غلق بالفعل؛ سأغير السبب، لكنك لم تمنحني واحدا ..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text( "هذا المستخدم غالبت بالفعل، والسبب التالي:\n" "<code>{}</code>\n" "لقد ذهبت وتحديثها مع السبب الجديد الخاص بك!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text( "هذا المستخدم غلق بالفعل، ولكن ليس لديه أي سبب؛ لقد ذهبت وتحديثها!" ) return message.reply_text("⚡️ * فارض السيطرة 😏 * ⚡️") banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>حظر عالمي</b>" \ "\n#حظر" \ "\n<b>الحالة:</b> <code>Enforcing</code>" \ "\n<b>بواسطة المشرف:</b> {}" \ "\n<b>للمستخدم:</b> {}" \ "\n<b>ID:</b> <code>{}</code>" \ "\n<b>السبب:</b> {}".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason or "No reason given"), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() 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: bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text("لا يمكن أن غبن بسبب: {}".format( excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} وقد غلغت بنجاح!".format( mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("تم غلغان الشخص.")
def ungban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("That's not a user!") return if not sql.is_user_gbanned(user_id): message.reply_text("This user is not gbanned!") return banner = update.effective_user # type: Optional[User] message.reply_text("I'll give {} a second chance, globally.".format( mention_html(user_chat.id, user_chat.first_name)), parse_mode=ParseMode.HTML) send_to_list(bot, SUDO_USERS, "{} has ungbanned user {}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name)), html=True) chats = get_all_chats() 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) except BadRequest as excp: if excp.message in UNGBAN_ERRORS: pass else: message.reply_text("Could not un-gban due to: {}".format( excp.message)) bot.send_message( OWNER_ID, "Could not un-gban due to: {}".format(excp.message)) return except TelegramError: pass sql.ungban_user(user_id) send_to_list(bot, SUDO_USERS, "Un-gban complete!") message.reply_text("{} has been un-gbanned.".format( mention_html(user_chat.id, user_chat.first_name)), parse_mode=ParseMode.HTML)
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return if int(user_id) in SUDO_USERS: message.reply_text( "I spy, with my little eye... a sudo user war! Why are you guys turning on each other?" ) return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH someone's trying to gban a support user! *grabs popcorn*") return if user_id == bot.id: message.reply_text( "-_- So funny, lets gban myself why don't I? Nice try.") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "This user is already gbanned; I'd change the reason, but you haven't given me one..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text( "This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text( "This user is already gbanned, but had no reason set; I've gone and updated it!" ) return message.reply_text("⚡️ *Summoning the Infinity Stones* ⚡️") banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Global Ban</b>" \ "\n#GBAN" \ "\n<b>Status:</b> <code>Enforcing</code>" \ "\n<b>Sudo Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason or "No reason given"), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() 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: bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text("Could not gban due to: {}".format( excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} has been successfully gbanned!".format( mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("Person has been gbanned.")
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return if int(user_id) in SUDO_USERS: message.reply_text( "I spy, with my little eye... a sudo user war! Why are you guys turning on each other?" ) return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH someone's trying to gban a support user! *grabs popcorn*") return if int(user_id) in WHITELIST_USERS: message.reply_text("Yeah... I'm not gonna gban a whitelisted user.") return if int(user_id) == bot.id: message.reply_text("Nice try but I ain't gonna gban myself!") return if int(user_id) in (777000, 1087968824): message.reply_text("Huh, why would I gban Telegram bots?") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if user_chat.first_name == '': message.reply_text("That's a deleted account, no need to gban them!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "This user is already gbanned; I'd change the reason, but you haven't given me one..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if old_reason: if old_reason == reason: message.reply_text( "This user is already gbanned for the exact same reason!") return else: message.reply_text( "This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text( "This user is already gbanned, but had no reason set; I've gone and updated it!" ) return message.reply_text("Starting a global ban for {}".format( mention_html(user_chat.id, user_chat.first_name)), parse_mode=ParseMode.HTML) banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS, "{} is gbanning user {} " "because:\n{}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), reason or "No reason given"), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_user_com_chats(user_id) if not chats: message.reply_text( "No common chats with this user! Will yeet them once I see them though!" ) return for chat in chats: chat_id = int(chat) # Check if this group has disabled gbans if not sql.does_chat_gban(chat_id): continue gbanned_chats = 0 try: bot.kick_chat_member(chat_id, user_id) gbanned_chats += 1 except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text("Could not gban due to: {}".format( excp.message)) send_to_list(bot, SUDO_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS, "Gban complete!") if gbanned_chats: message.reply_text( "Done! {} has been globally banned in <code>{}</code> common chats." .format(mention_html(user_chat.id, user_chat.first_name), gbanned_chats), parse_mode=ParseMode.HTML) else: message.reply_text( f"Done! {mention_html(user_chat.id, user_chat.first_name)} has been added to the gbans database!", parse_mode=ParseMode.HTML) try: bot.send_message( user_id, "You've been globally banned from all groups where I am admin. If this is a mistake, you can appeal your ban @PhoenixSupport", parse_mode=ParseMode.HTML) except: pass #Bot either blocked or never started by user
def fed_ban(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) if not fed_id: update.effective_message.reply_text(tld(chat.id, "This group is not in any federation!")) return info = sql.get_fed_info(fed_id) OW = bot.get_chat(info.owner_id) HAHA = OW.id FEDADMIN = sql.all_fed_users(fed_id) FEDADMIN.append(int(HAHA)) if is_user_fed_admin(fed_id, user.id) == False: update.effective_message.reply_text(tld(chat.id, "Only fed admins can do this!")) return message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) fban = sql.get_fban_user(fed_id, user_id) if not fban == False: update.effective_message.reply_text(tld(chat.id, "*Cough* This user is already fbanned!")) return if not user_id: message.reply_text(tld(chat.id, "You don't seem to be referring to a user.")) return if user_id == bot.id: message.reply_text(tld(chat.id, "You can't fban me, better hit your head against the wall, it's more fun.")) return if is_user_fed_owner(fed_id, user_id) == True: message.reply_text(tld(chat.id, "Why you are trying to fban the federation owner?")) return if is_user_fed_admin(fed_id, user_id) == True: message.reply_text(tld(chat.id, "Why so serious trying to fban the federation admin?")) return if user_id == OWNER_ID: message.reply_text(tld(chat.id, "I'm not fbanning my master, That's pretty dumb idea!")) return if int(user_id) in SUDO_USERS: message.reply_text(tld(chat.id, "I'm not fbanning the bot sudoers!")) return if int(user_id) in WHITELIST_USERS: message.reply_text(tld(chat.id, "This person is whitelisted from being fbanned!")) return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text(tld(chat.id, "That's not a user!")) return ok123 = mention_html(user_chat.id, user_chat.first_name) ok1234 = info.fed_name text12 = f"Beginning federation ban of {ok123} in {ok1234}." update.effective_message.reply_text(text12, parse_mode=ParseMode.HTML) if reason == "": reason = "No Reason." x = sql.fban_user(fed_id, user_id, reason) if not x: message.reply_text("Failed to federation ban! Probably this bug is not fixed yet due to the developer is lazy as f**k.") return h = sql.all_fed_chats(fed_id) for O in h: try: bot.kick_chat_member(O, user_id) #text = tld(chat.id, "I should fban {}, but it's only test fban, right? So i let him live.").format(O) text = "Fbanning {}".format(user_id) #message.reply_text(text) except BadRequest as excp: if excp.message in FBAN_ERRORS: pass else: message.reply_text(tld(chat.id, "Could not fban due to: {}").format(excp.message)) return except TelegramError: pass send_to_list(bot, FEDADMIN, "<b>New FedBan</b>" \ "\n<b>Fed:</b> {}" \ "\n<b>FedAdmin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(info.fed_name, mention_html(user.id, user.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason), html=True)
def ungban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("That's not a user!") return if not sql.is_user_gbanned(user_id): message.reply_text("This user is not gbanned!") return banner = update.effective_user # type: Optional[User] message.reply_text( "аі∂аі∞аіњ, {} аі®аµН аіТаі∞аµБ аіЕаіµаіЄаі∞аіВ аіХаµВаіЯаіњ аіХаµКаіЯаµБаі§аµНаі§аµЗаіХаµНаіХаіЊаіВ!" .format(user_chat.first_name)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} has ungbanned user {}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name)), html=True) chats = get_all_chats() 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) except BadRequest as excp: if excp.message in UNGBAN_ERRORS: pass else: message.reply_text("Could not un-gban due to: {}".format( excp.message)) bot.send_message( OWNER_ID, "Could not un-gban due to: {}".format(excp.message)) return except TelegramError: pass sql.ungban_user(user_id) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "un-gban аіЪаµЖаіѓаµНаі§аµБ!") message.reply_text( "аіЗаіѓаіЊаі≥аµБаіЯаµЖ Gban аі™аіњаµїаіµаі≤аіњаіЪаµНаіЪаіњаіЯаµНаіЯаµБаі£аµНаіЯаµН!" )
def ungmute(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if not user_id: message.reply_text( "You don't seem to be referring to a user or the ID specified is incorrect.." ) return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("That's not a user!") return if not sql.is_user_gmuted(user_id): message.reply_text("This user is not gmuted!") return muter = update.effective_user # type: Optional[User] message.reply_text("I'll let {} speak again, globally.".format( user_chat.first_name)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Regression of Global Mute</b>" \ "\n#UNGMUTE" \ "\n<b>Status:</b> <code>Ceased</code>" \ "\n<b>Sudo Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>ID:</b> <code>{}</code>".format(mention_html(muter.id, muter.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id), html=True) chats = get_all_chats() for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gmutes if not sql.does_chat_gmute(chat_id): continue try: member = bot.get_chat_member(chat_id, user_id) if member.status == 'restricted': bot.restrict_chat_member(chat_id, int(user_id), can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True) except BadRequest as excp: if excp.message == "User is an administrator of the chat": pass elif excp.message == "Chat not found": pass elif excp.message == "Not enough rights to restrict/unrestrict chat member": pass elif excp.message == "User_not_participant": pass elif excp.message == "Method is available for supergroup and channel chats only": pass elif excp.message == "Not in the chat": pass elif excp.message == "Channel_private": pass elif excp.message == "Chat_admin_required": pass else: message.reply_text("Could not un-gmute due to: {}".format( excp.message)) bot.send_message( OWNER_ID, "Could not un-gmute due to: {}".format(excp.message)) return except TelegramError: pass sql.ungmute_user(user_id) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} has been successfully un-gmuted!".format( mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("Person has been un-gmuted.")
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return if int(user_id) in SUDO_USERS: message.reply_text( "I spy, with my little eye... a sudo user war! Why are you guys turning on each other?" ) return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH someone's trying to gban a support user! *grabs popcorn*") return if user_id == bot.id: message.reply_text( "-_- So funny, lets gban myself why don't I? Nice try.") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "This user is already gbanned; I'd change the reason, but you haven't given me one..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text( "This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text( "This user is already gbanned, but had no reason set; I've gone and updated it!" ) return message.reply_text( "аіЗаі™аµНаі™ аі∂аі∞аіњаіѓаіЊаіХаµНаіХаіњаі§аµНаі§аі∞аіЊаіВ! рЯШЙ") banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} is gbanning user {} " "because:\n{}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), reason or "No reason given"), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() 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: bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text("Could not gban due to: {}".format( excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Gban аіЪаµЖаіѓаµНаі§аµБ!") message.reply_text( "Get out of my world, you idiot! аі≤аіµаі®аµЖ GBAN аіЪаµЖаіѓаµНаі§аіњаіЯаµНаіЯаµБаі£аµНаіЯаµН аіЃаіЊаіЄаµНаі±аµНаі±аµЉ." )
def ungban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("That's not a user!") return if not sql.is_user_gbanned(user_id): message.reply_text("This user is not gbanned!") return banner = update.effective_user # type: Optional[User] message.reply_text("I pardon {}, globally with a second chance.".format( user_chat.first_name or "Deleted Account")) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Regression of Global Ban</b>" \ "\n#UNGBAN" \ "\n<b>Status:</b> <code>Ceased</code>" \ "\n<b>Sudo Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>ID:</b> <code>{}</code>".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name or "Deleted Account"), user_chat.id), html=True) chats = get_all_chats() 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) except BadRequest as excp: if excp.message in UNGBAN_ERRORS: pass else: message.reply_text("Could not un-gban due to: {}".format( excp.message)) bot.send_message( OWNER_ID, "Could not un-gban due to: {}".format(excp.message)) return except TelegramError: pass sql.ungban_user(user_id) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} has been pardoned from gban!".format( mention_html(user_chat.id, user_chat.first_name or "Deleted Account")), html=True) message.reply_text( "This person has been un-gbanned and pardon is granted!")
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return if int(user_id) in SUDO_USERS: message.reply_text("Bhabhi ko ban karega? @king_un_007 se baat kar tu ") return if int(user_id) in SUPPORT_USERS: message.reply_text("Bhabhi h panga mat le @king_un_007 ajaega!!!") return if user_id == bot.id: message.reply_text("-_- Isse bada pagal kon ho sakta h.") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text("user already globbalyy ban ho chuka h...") return old_reason = sql.update_gban_reason(user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text("This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format(html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text("This user is already gbanned, but had no reason set; I've gone and updated it!") return message.reply_text("⚡️ *Gets a punch* ⚡️") banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Global Ban</b>" \ "\n#GBAN" \ "\n<b>Status:</b> <code>Enforcing</code>" \ "\n<b>Sudo Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason or "No reason given"), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() 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: bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text("Could not gban due to: {}".format(excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} has been successfully gbanned!".format(mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("Person has been gbanned.")