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("Deyəsən bir istifadəçini nəzərdə tutmursan.") return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("Bu istifadəçi deyil!") return if not sql.is_user_gbanned(user_id): message.reply_text("İstifadəçi banlanmadı") return banner = update.effective_user # type: Optional[User] message.reply_text("İkinci bir şansla qlobal olaraq {} bağışlayıram.".format(user_chat.first_name)) 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), 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)), 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("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("F*****g this gey Globally ☠️") 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 cant't Gban my BF :V") 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 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 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!") 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 @Mr_Tavish007", 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 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) 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 GBAN_LOGS: bot.send_message( GBAN_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 GBAN_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 check_and_ban(update, user_id, should_message=True): if sql.is_user_gbanned(user_id): update.effective_chat.kick_member(user_id) if should_message: update.effective_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( 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) 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 == "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 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 complete!") message.reply_text("Person has been un-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 user_id == OWNER_ID: message.reply_text("I'm not going to Gban my master nice try n***a.") 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( "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("Wolves cannot be gbanned!") 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 "" 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 = "#GBANNED" \ "\n<b>Originated from:</b> {}" \ "\n<b>Bot-Admin:</b> {}" \ "\n<b>GBanned User:</b> {}" \ "\n<b>GBanned User ID:</b> {}" \ "\n<b>Event Stamp:</b> {}".format(chat_origin, mention_html(user.id, user.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, current_time) if reason: if chat.type == chat.SUPERGROUP and chat.username: log_message += "\n<b>Reason:</b> " \ "<a href=\"http://telegram.me/{}/{}\">{}</a>".format(chat.username, message.message_id, reason) else: log_message += "\n<b>Reason:</b> {}".format(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 + DEV_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("Could not gban due to: {}".format( excp.message)) if GBAN_LOGS: bot.send_message(GBAN_LOGS, "Could not gban due to {}".format( excp.message), parse_mode=ParseMode.HTML) else: send_to_list( bot, SUDO_USERS + SUPPORT_USERS + DEV_USERS, "Could not gban due to: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass if GBAN_LOGS: log.edit_text(log_message + "\n<b>Chats affected:</b> {}".format(gbanned_chats), parse_mode=ParseMode.HTML) else: send_to_list( bot, SUDO_USERS + SUPPORT_USERS + DEV_USERS, "Gban complete! (User banned from {} chats)".format(gbanned_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( "Done! This gban affected {} chats, Took {} min".format( gbanned_chats, gban_time)) else: message.reply_text( "Done! This gban affected {} chats, Took {} sec".format( gbanned_chats, gban_time)) try: bot.send_message( user_id, "You have been globally banned from all groups where I'm appoint as Admin. If you think that this was a mistake, you may appeal for Ungban requet here: @OnePunchSupport", parse_mode=ParseMode.HTML) except: pass # bot probably blocked by user
def left_member(update, context): chat = update.effective_chat should_goodbye, cust_goodbye, goodbye_type = sql.get_gdbye_pref(chat.id) cust_goodbye = markdown_to_html(cust_goodbye) if should_goodbye: reply = update.message.message_id cleanserv = sql.clean_service(chat.id) # Clean service welcome if cleanserv: try: dispatcher.bot.delete_message(chat.id, update.message.message_id) except BadRequest: pass reply = False left_mem = update.effective_message.left_chat_member if left_mem: # Ignore gbanned users if is_user_gbanned(left_mem.id): return # Ignore spamwatch banned users try: sw = spamwtc.get_ban(int(left_mem.id)) if sw: return except BaseException: pass # Ignore bot being kicked if left_mem.id == context.bot.id: return # Give the owner a special goodbye if left_mem.id == OWNER_ID: update.effective_message.reply_text("RIP Master", reply_to_message_id=reply) return # if media goodbye, use appropriate function for it if goodbye_type != sql.Types.TEXT and goodbye_type != sql.Types.BUTTON_TEXT: ENUM_FUNC_MAP[goodbye_type](chat.id, cust_goodbye) return first_name = (left_mem.first_name or "PersonWithNoName" ) # edge case of empty name - occurs for some bugs. if cust_goodbye: if left_mem.last_name: fullname = "{} {}".format(first_name, left_mem.last_name) else: fullname = first_name count = chat.get_members_count() mention = mention_html(left_mem.id, first_name) if left_mem.username: username = "******" + escape(left_mem.username) else: username = mention valid_format = escape_invalid_curly_brackets( cust_goodbye, VALID_WELCOME_FORMATTERS) res = valid_format.format( first=escape(first_name), last=escape(left_mem.last_name or first_name), fullname=escape(fullname), username=username, mention=mention, count=count, chatname=escape(chat.title), id=left_mem.id, ) buttons = sql.get_gdbye_buttons(chat.id) keyb = build_keyboard(buttons) else: res = sql.DEFAULT_GOODBYE keyb = [] keyboard = InlineKeyboardMarkup(keyb) send(update, res, keyboard, sql.DEFAULT_GOODBYE)
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 need to reply to an user.") return if int(user_id) in SUDO_USERS: message.reply_text("Cannot !gban a SUDO user.") return if int(user_id) in SUPPORT_USERS: message.reply_text("Cannot !gban a SUPPORT user.") return if user_id == bot.id: message.reply_text("Cannot !gban me, lol..") 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.") 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 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("User {} was banned globally. (Thorough all Pundi X / Function X groups) ".format(user_chat.first_name)) if update.effective_message.reply_to_message: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] if can_delete(chat, bot.id): update.effective_message.reply_to_message.delete() update.effective_message.delete() return "<b>{}:</b>" \ "\n#DEL" \ "\n<b>Admin:</b> {}" \ "\nMessage deleted.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) else: update.effective_message.reply_text("Whadya want to delete?") return ""
def gban(update: Update, context: CallbackContext): bot, args = context.bot, 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.ban_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.ban_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 new_member(update, context): chat = update.effective_chat user = update.effective_user msg = update.effective_message chat_name = chat.title or chat.first or chat.username should_welc, cust_welcome, cust_content, welc_type = sql.get_welc_pref( chat.id) cust_welcome = markdown_to_html(cust_welcome) welc_mutes = sql.welcome_mutes(chat.id) user_id = user.id human_checks = sql.get_human_checks(user_id, chat.id) if should_welc: sent = None new_members = update.effective_message.new_chat_members for new_mem in new_members: reply = update.message.message_id cleanserv = sql.clean_service(chat.id) # Clean service welcome if cleanserv: reply = False try: dispatcher.bot.delete_message(chat.id, update.message.message_id) except BadRequest: pass # Ignore spamwatch banned users try: sw = spamwtc.get_ban(int(new_mem.id)) if sw: return except Exception: pass # Ignore gbanned users if is_user_gbanned(new_mem.id): return # Give the owner a special welcome if new_mem.id == OWNER_ID: update.effective_message.reply_text( "My master joined ur chat !", reply_to_message_id=reply, ) continue # Give the DEV a special welcome if new_mem.id in DEV_USERS: update.effective_message.reply_text( "My Dev Here,All welcome him ", reply_to_message_id=reply, ) continue # Make bot greet admins if new_mem.id == context.bot.id: update.effective_message.reply_text( "Hey {}, I'm {}! Thank you for adding me to {}".format( user.first_name, context.bot.first_name, chat_name), reply_to_message_id=reply, ) context.bot.send_message( MESSAGE_DUMP, "Saber have been added to <pre>{}</pre> with ID: \n<pre>{}</pre>" .format(chat.title, chat.id), parse_mode=ParseMode.HTML, ) else: # If welcome message is media, send with appropriate function if welc_type != sql.Types.TEXT and welc_type != sql.Types.BUTTON_TEXT: # edge case of empty name - occurs for some bugs. first_name = new_mem.first_name or "PersonWithNoName" # Start formating text if new_mem.last_name: fullname = "{} {}".format(first_name, new_mem.last_name) else: fullname = first_name count = chat.get_members_count() mention = mention_html(new_mem.id, first_name) if new_mem.username: username = "******" + escape(new_mem.username) else: username = mention valid_format = escape_invalid_curly_brackets( cust_welcome, VALID_WELCOME_FORMATTERS) formated_text = valid_format.format( first=escape(first_name), last=escape(new_mem.last_name or first_name), fullname=escape(fullname), username=username, mention=mention, count=count, chatname=escape(chat.title), id=new_mem.id, ) # build the button buttons = sql.get_welc_buttons(chat.id) if buttons: keyb = build_keyboard_parser(context.bot, chat.id, buttons) keyboard = InlineKeyboardMarkup(keyb) else: keyboard = None sent = ENUM_FUNC_MAP[welc_type]( chat.id, cust_content, caption=formated_text, reply_markup=keyboard, parse_mode="html", reply_to_message_id=reply, ) # else, move on else: # edge case of empty name - occurs for some bugs. first_name = new_mem.first_name or "PersonWithNoName" if cust_welcome: if new_mem.last_name: fullname = "{} {}".format(first_name, new_mem.last_name) else: fullname = first_name count = chat.get_members_count() mention = mention_html(new_mem.id, first_name) if new_mem.username: username = "******" + escape(new_mem.username) else: username = mention valid_format = escape_invalid_curly_brackets( cust_welcome, VALID_WELCOME_FORMATTERS) res = valid_format.format( first=escape(first_name), last=escape(new_mem.last_name or first_name), fullname=escape(fullname), username=username, mention=mention, count=count, chatname=escape(chat.title), id=new_mem.id, ) buttons = sql.get_welc_buttons(chat.id) keyb = build_keyboard(buttons) else: res = sql.DEFAULT_WELCOME.format(first=first_name) keyb = [] keyboard = InlineKeyboardMarkup(keyb) sent = send( update, res, keyboard, sql.DEFAULT_WELCOME.format(first=first_name), ) if (is_user_ban_protected( chat, new_mem.id, chat.get_member(new_mem.id) or new_mem.is_bot, ) or human_checks): continue # Join welcome: soft mute if welc_mutes == "soft": context.bot.restrict_chat_member( chat.id, new_mem.id, permissions=ChatPermissions( can_send_messages=True, can_send_media_messages=False, can_send_other_messages=False, can_invite_users=False, can_pin_messages=False, can_send_polls=False, can_change_info=False, can_add_web_page_previews=False, until_date=(int(time.time() + 24 * 60 * 60)), ), ) # Join welcome: strong mute if welc_mutes == "strong": new_join_mem = "Hey {}!".format( mention_html(user.id, new_mem.first_name)) msg.reply_text( "{}\nClick the button below to start talking.". format(new_join_mem), reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="Yus, I'm a human", callback_data="user_join_({})".format( new_mem.id), ) ]]), parse_mode=ParseMode.HTML, reply_to_message_id=reply, ) context.bot.restrict_chat_member( chat.id, new_mem.id, permissions=ChatPermissions( can_send_messages=False, can_invite_users=False, can_pin_messages=False, can_send_polls=False, can_change_info=False, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False, ), ) prev_welc = sql.get_clean_pref(chat.id) if prev_welc: try: context.bot.delete_message(chat.id, prev_welc) except BadRequest: pass if sent: sql.set_clean_welcome(chat.id, sent.message_id)
def ungban(update: Update, context: CallbackContext): bot, args = context.bot, context.args message = update.effective_message # type: Optional[Message] user_id = extract_user(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 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("{}, will be unbanned globally.".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 unbanned globally!".format( mention_html(user_chat.id, user_chat.first_name or "Deleted Account")), html=True, ) message.reply_text("Person has been un-gbanned.")
def enforce_gban(bot, update): user = update.effective_message.from_user if sql.is_user_gbanned(user.id): update.effective_chat.kick_member(user.id) update.effective_message.reply_text( "This is a bad person, they shouldn't be here!")
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("Deyəsən bir istifadəçiyə istinad etmirsiniz.") return if int(user_id) in SUDO_USERS: message.reply_text("Mən kiçik gözümlə casusluq edirəm ... sudo istifadəçisi müharibəsi! Uşaqlar niyə bir-birinizə dönürsünüz?") return if int(user_id) in SUPPORT_USERS: message.reply_text("Kimsə bir dəstək istifadəçisini gban etməyə çalışır!") return if user_id == bot.id: message.reply_text("Özünü gban etmək istəyirsəN?") 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 istifadəçi deyil!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text("Bu istifadəçi artıq gbanlandı") return old_reason = sql.update_gban_reason(user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text("c:\n" "<code>{}</code>\n" "Səbəbinizi yenilədim".format(html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text("Bu istifadəçi artıq banlandı") return message.reply_text("⚡️ *Snaps the Banhammer* ⚡️") 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>İcraedici</code>" \ "\n<b>Sudo Admin:</b> {}" \ "\n<b>istifadəci:</b> {}" \ "\n<b>ID:</b> <code>{}</code>" \ "\n<b>Səbə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("Aşağıdakı səbəbdən gban edilə bilmədi {}".format(excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Səbəbiylə gban edilə bilmədi: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + !SUPPORT_USERS, "{} uğurla ban edilmişdir!".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 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 success = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if success: message.reply_text( "This user is already gbanned; I've gone and updated the gban reason though!" ) else: message.reply_text( "Do you mind trying again? I thought this person was gbanned, but then they weren't? " "Am very confused") return message.reply_text("*Blows dust off of banhammer* 😉") 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("Person has been gbanned.")
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("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_gbanned(user_id): message.reply_text("Kullanıcı zaten gbanlı değil!") return banner = update.effective_user # type: Optional[User] message.reply_text("{} Kullanıcısına ikinci bir şans veriyorum.".format(user_chat.first_name)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Regression of Global Ban</b>" \ "\n#UNGBAN" \ "\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(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("Şu sebepten dolayı ungbanlanamıyor: {}".format(excp.message)) bot.send_message(OWNER_ID, "Şu sebepten dolayı ungbanlanamıyor: {}".format(excp.message)) return except TelegramError: pass sql.ungban_user(user_id) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} Başarıyla ungbanlandı!".format(mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("Başarıyla ungbanlandı.")
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 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( "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 Demon Disaster! *grabs popcorn*") return if int(user_id) in WHITELIST_USERS: message.reply_text("Wolves cannot be gbanned!") 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: 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("On it!") banner = update.effective_user # type: Optional[User] messagerep = "{} 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") if GBAN_LOGS: bot.send_message(GBAN_LOGS, messagerep, parse_mode=ParseMode.HTML) else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS, messagerep, 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("Could not gban due to: {}".format( excp.message)) if GBAN_LOGS: bot.send_message(GBAN_LOGS, "Could not gban due to {}".format( excp.message), parse_mode=ParseMode.HTML) else: 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 if GBAN_LOGS: bot.send_message( GBAN_LOGS, "gban complete! (User banned in {} chats)".format(gbanned_chats), parse_mode=ParseMode.HTML) else: send_to_list( bot, SUDO_USERS + SUPPORT_USERS, "gban complete! (User banned in {} chats)".format(gbanned_chats)) message.reply_text( "Done! This gban affected {} chats".format(gbanned_chats)) 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: @onepunchsupport", parse_mode=ParseMode.HTML) except: pass # bot probably blocked by user
def check_and_ban(update, user_id, should_message=True): if sql.is_user_gbanned(user_id): update.effective_chat.kick_member(user_id) if should_message: update.effective_message.reply_text("Bu kullanıcı burada olmamalı!")
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("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 message.reply_text("I'll give {} a second chance, globally.".format( user_chat.first_name)) 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 = "#UNGBANNED" \ "\n<b>Originated from:</b> {}" \ "\n<b>Bot-Admin:</b> {}" \ "\n<b>Ungbanned User:</b> {}" \ "\n<b>Ungbanned User ID:</b> {}" \ "\n<b>Event Stamp:</b> {}".format(chat_origin, mention_html(user.id, user.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, 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\nFormatting has been disabled due to an unexpected error.") else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS + DEV_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("Could not un-gban due to: {}".format( excp.message)) if GBAN_LOGS: bot.send_message(GBAN_LOGS, "Could not un-gban due to: {}".format( excp.message), parse_mode=ParseMode.HTML) else: bot.send_message( OWNER_ID, "Could not un-gban due to: {}".format(excp.message)) return except TelegramError: pass sql.ungban_user(user_id) if GBAN_LOGS: log.edit_text(log_message + "\n<b>Chats affected:</b> {}".format(ungbanned_chats), parse_mode=ParseMode.HTML) else: send_to_list(bot, SUDO_USERS + SUPPORT_USERS + DEV_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( "Person has been un-gbanned. Took {} min".format(ungban_time)) else: message.reply_text( "Person has been un-gbanned. Took {} sec".format(ungban_time))
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("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ı gbanlamaya çalışıyor!") return if user_id == bot.id: message.reply_text("Ölmek mi istiyorsun?") 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_gbanned(user_id): if not reason: message.reply_text("Bu kullanıcı zaten gbanlı; Sebebini değiştirebilirdim ama, ama bana sebep vermedin...") return old_reason = sql.update_gban_reason(user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text("Bu kullanıcı zaten aşağıdaki sebepten dolayı gbanlı:\n" "<code>{}</code>\n" "Yeni sebebini güncelledim!".format(html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text("Bu kullanıcı zaten gbanlı, ama daha önce sebebi yoktu. Şimdi gidip ekledim!") return message.reply_text("Şimdi öldün ! 👉😎👉") banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Global Ban</b>" \ "\n#GBAN" \ "\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(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason or "Sebep belirtmedi"), 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("Şu sebepten dolayı gbanlanamadı: {}".format(excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Şu sebepten dolayı gbanlanamadı: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} Başarıyla gbanlandı!".format(mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("Kullanıcı yaptıklarıyla \"yüzleşti\".")
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 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("Bir istifadəçiyə istinaq etmirsiniz.") return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("Bu bir istifadəçi deyil!") return if not sql.is_user_gbanned(user_id): message.reply_text("Bu istifadəçi gban edilməyib!") return banner = update.effective_user # type: Optional[User] message.reply_text("{}, səni qlobal olaraq ikinci bir şansla bağışlayıram😏.".format(user_chat.first_name)) 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), 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("Ungban edilə bilmədi. Xəta: {}".format(excp.message)) bot.send_message(OWNER_ID, "Ungban edilə bilmədi. Xəta: {}".format(excp.message)) return except TelegramError: pass sql.ungban_user(user_id) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} şəxsinin gbanı aradan qaldırıldı!".format(mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("Bu şəxsin gbanı aradan qaldırıldı və əfv edildi!")
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 Union\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 nation! 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 Sakura Nation! *grabs popcorn*") return if int(user_id) in SARDEGNA_USERS: message.reply_text("That's a Sardegna! They cannot be banned!") return if int(user_id) in WHITELIST_USERS: message.reply_text("That's a Neptunia! They cannot be banned!") return if int(user_id) in (777000, 1087968824): message.reply_text("Huh, why would I gban Telegram bots?") return if user_id == bot.id: message.reply_text("You uhh...want me to kill 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 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_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 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> <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, "#GBAN" "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> @YorkTownEagleUnion", parse_mode=ParseMode.HTML, ) except: pass # bot probably blocked by user
def check_and_ban(update, user_id, should_message=True): if sql.is_user_gbanned(user_id): update.effective_chat.kick_member(user_id) if should_message: update.effective_message.reply_text("Bu pis insandır, burada qalmamalıdır!")
def left_member(bot: Bot, update: Update): chat = update.effective_chat user = update.effective_user should_goodbye, cust_goodbye, goodbye_type = sql.get_gdbye_pref(chat.id) if user.id == bot.id: return if should_goodbye: reply = update.message.message_id cleanserv = sql.clean_service(chat.id) # Clean service welcome if cleanserv: try: dispatcher.bot.delete_message(chat.id, update.message.message_id) except BadRequest: pass reply = False left_mem = update.effective_message.left_chat_member if left_mem: if sw != None: sw_ban = sw.get_ban(left_mem.id) if sw_ban: return # Dont say goodbyes to gbanned users if is_user_gbanned(left_mem.id): return # Ignore bot being kicked if left_mem.id == bot.id: return # Give the owner a special goodbye if left_mem.id == OWNER_ID: update.effective_message.reply_text("Oi! Genos! He left..", reply_to_message_id=reply) return # Give the devs a special goodbye elif left_mem.id in DEV_USERS: update.effective_message.reply_text( "See you later at the Hero's Association!", reply_to_message_id=reply) return # if media goodbye, use appropriate function for it if goodbye_type != sql.Types.TEXT and goodbye_type != sql.Types.BUTTON_TEXT: ENUM_FUNC_MAP[goodbye_type](chat.id, cust_goodbye) return first_name = left_mem.first_name or "PersonWithNoName" # edge case of empty name - occurs for some bugs. if cust_goodbye: if cust_goodbye == sql.DEFAULT_GOODBYE: cust_goodbye = random.choice( sql.DEFAULT_GOODBYE_MESSAGES).format( first=escape_markdown(first_name)) if left_mem.last_name: fullname = escape_markdown( f"{first_name} {left_mem.last_name}") else: fullname = escape_markdown(first_name) count = chat.get_members_count() mention = mention_markdown(left_mem.id, first_name) if left_mem.username: username = "******" + escape_markdown(left_mem.username) else: username = mention valid_format = escape_invalid_curly_brackets( cust_goodbye, VALID_WELCOME_FORMATTERS) res = valid_format.format( first=escape_markdown(first_name), last=escape_markdown(left_mem.last_name or first_name), fullname=escape_markdown(fullname), username=username, mention=mention, count=count, chatname=escape_markdown(chat.title), id=left_mem.id) buttons = sql.get_gdbye_buttons(chat.id) keyb = build_keyboard(buttons) else: res = random.choice( sql.DEFAULT_GOODBYE_MESSAGES).format(first=first_name) keyb = [] keyboard = InlineKeyboardMarkup(keyb) send( update, res, keyboard, random.choice( sql.DEFAULT_GOODBYE_MESSAGES).format(first=first_name))
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("Bir istifadəçi versən gban edə bilərəm.") return if int(user_id) in SUDO_USERS: message.reply_text("Mən öz balaca gözlərim ilə ağlayıram... sudo istifadəçi müharibəsi! Siz niyə bir-birinizə bunu edirsiniz?") return if int(user_id) in SUPPORT_USERS: message.reply_text("OOOH kimsə Support istifadəçisini gban edir! *popcorn alıb izləyirəm*") return if user_id == bot.id: message.reply_text("-_- Çox əyləncəlidir, gəl özümü gban edim! pf") 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 istifadəçi deyil!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text("Bu istifadəçi onsuzda gbanlıdır; Səbəbi dəyişərdim, amma bir səbəb verməmisən...") return old_reason = sql.update_gban_reason(user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text("Bu istifadəçi onsuzda gbanlıdır, reason:\n" "<code>{}</code>\n" "Və mən köhnə səbəbi yenisi ilə əvəz etdim!".format(html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text("Bu istifadəçi onsuzda gbanlıdır, amma bir səbəb verilməyib; Mən səbəbi güncəllədim!") return message.reply_text("OHA SƏN GBAN ALDIN😳 TƏƏSÜFKİ GBAN VERƏN ŞƏXS SƏNİ BAĞIŞLAMASA MƏNDƏ SƏNİ BAĞIŞLAYA Bİlmərəm🤕") 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>Səbəb:</b> {}".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason or "Səbəb verilməyib"), 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 etmək mümkün olmadı. Xəta: `{}`".format(excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Gban etmək mümkün olmadı. Xəta: `{}`".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} uğurla gban edildi!".format(mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("İstifadəçi gban edildi.")
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 + SUPPORT_USERS, "<b>Regression of Global Ban</b>" \ "\n#UNGBAN" \ "\n<b>Status:</b> <code>Ceased</code>" \ "\n<b>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, "Un-gban complete!") message.reply_text("{} has been un-gbanned.kek.".format( mention_html(user_chat.id, user_chat.first_name)), parse_mode=ParseMode.HTML)
def new_member(update: Update, context: CallbackContext): bot = context.bot chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] chat_name = chat.title or chat.first or chat.username # type: Optional:[chat name] should_welc, cust_welcome, cust_media, welc_type = sql.get_welc_pref( chat.id) welc_mutes = sql.welcome_mutes(chat.id) casPrefs = sql.get_cas_status(str(chat.id)) #check if enabled, obviously autoban = sql.get_cas_autoban(str(chat.id)) chatbanned = sql.isBanned(str(chat.id)) defense = sql.getDefenseStatus(str(chat.id)) time_value = sql.getKickTime(str(chat.id)) isUserGbanned = gbansql.is_user_gbanned(user.id) if isUserGbanned: return if chatbanned: bot.leave_chat(int(chat.id)) elif casPrefs and not autoban and cas.banchecker(user.id): bot.restrict_chat_member(chat.id, user.id, permissions=ChatPermissions( can_send_messages=False, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False)) msg.reply_text( "Warning! This user is CAS Banned. I have muted them to avoid spam. Ban is advised." ) if not isUserGbanned: report = "CAS Banned user detected: <code>{}</code>".format( user.id) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, report, html=True) if defense: bantime = int(time.time()) + 60 chat.kick_member(new_mem.id, until_date=bantime) elif casPrefs and autoban and cas.banchecker(user.id): chat.kick_member(user.id) msg.reply_text( "CAS banned user detected! User has been automatically banned!") isUserGbanned = gbansql.is_user_gbanned(user.id) if not isUserGbanned: report = "CAS Banned user detected: <code>{}</code>".format( user.id) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, report, html=True) elif defense and (user.id not in SUDO_USERS + SUPPORT_USERS): bantime = int(time.time()) + 60 chat.kick_member(user.id, until_date=bantime) elif should_welc: sent = None new_members = update.effective_message.new_chat_members for new_mem in new_members: # Give the owner a special welcome if new_mem.id == OWNER_ID: update.effective_message.reply_text( "Master is in the houseeee, you all must obey my master!") continue # Give the sudos/support a special welcome too elif new_mem.id in SUDO_USERS or new_mem.id in SUPPORT_USERS: update.effective_message.reply_text( "Welcome to the Dark Side! May the force be with you...") continue # Make bot greet admins elif new_mem.id == bot.id: update.effective_message.reply_text( "Hey {}, I'm {}! Thank you for adding me to {}" " and be sure to check /help in PM for more commands and tricks!" .format(user.first_name, bot.first_name, chat_name)) else: first_name = new_mem.first_name or "PersonWithNoName" # edge case of empty name - occurs for some bugs. if cust_welcome: if new_mem.last_name: fullname = "{} {}".format(first_name, new_mem.last_name) else: fullname = first_name count = chat.get_members_count() mention = mention_markdown(new_mem.id, first_name) if new_mem.username: username = "******" + escape_markdown(new_mem.username) else: username = mention valid_format = escape_invalid_curly_brackets( cust_welcome, VALID_WELCOME_FORMATTERS) res = valid_format.format( first=escape_markdown(first_name), last=escape_markdown(new_mem.last_name or first_name), fullname=escape_markdown(fullname), username=username, mention=mention, count=count, chatname=escape_markdown(chat.title), id=new_mem.id) buttons = sql.get_welc_buttons(chat.id) keyb = build_keyboard(buttons) else: res = sql.DEFAULT_WELCOME.format(first=first_name) keyb = [] keyboard = InlineKeyboardMarkup(keyb) # If welcome message is media, send with appropriate function if welc_type != sql.Types.TEXT and welc_type != sql.Types.BUTTON_TEXT: sent = ENUM_FUNC_MAP[welc_type]( chat.id, cust_media, caption=res, reply_to_message_id=msg.message_id, parse_mode=ParseMode.MARKDOWN) pass else: sent = send( update, res, keyboard, sql.DEFAULT_WELCOME.format( first=first_name)) # type: Optional[Message] #Sudo user exception from mutes: if is_user_ban_protected(chat, new_mem.id, chat.get_member(new_mem.id)): continue #Safe mode newMember = chat.get_member(int(new_mem.id)) if welc_mutes == "on" and ((newMember.can_send_messages is None or newMember.can_send_messages)): text = "" if time_value: text = " else you'll be kicked after {} seconds.".format( str(time_value)) buttonMsg = msg.reply_text( "Click the button below to prove you're human 👀" + text, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="I'm not a bot! 🤖", callback_data="userverify_({})".format( new_mem.id)) ]])) bot.restrict_chat_member( chat.id, new_mem.id, permissions=ChatPermissions( can_send_messages=False, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False)) if time_value: time.sleep(time_value) member = chat.get_member(int(new_mem.id)) if not (member.can_send_messages or member.status == 'left'): print("kicking user..") bantime = int(time.time()) + 60 chat.kick_member(new_mem.id, until_date=bantime) buttonMsg.delete() sent.delete() update.message.delete() delete_join(bot, update) prev_welc = sql.get_clean_pref(chat.id) if prev_welc: try: bot.delete_message(chat.id, prev_welc) except BadRequest as excp: pass if sent: sql.set_clean_welcome(chat.id, sent.message_id)
def check_and_ban(update, user_id): if sql.is_user_gbanned(user_id): update.effective_chat.kick_member(user_id) update.effective_message.reply_text("This is a bad person, they shouldn't be here!")
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("İstifadəçi qeyd olunmayıb.") return if int(user_id) in SUDO_USERS: message.reply_text("Support istifadəçi niyə o həmkarın Qlobal Ban etsin ki?") return if int(user_id) in SUPPORT_USERS: message.reply_text("AHAHAH Kimsə Support İstifadəçini Qlobal Ban etmək istiyir *popcorn gətirim gəlirəm*") return if user_id == bot.id: message.reply_text("Çox gülməli idi birdə yoxla") 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("Qeyd etdiyin insan deyil!") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text("Bu istifadəçi Qlobal Ban olub amma Support İstifadəçilər heçnə qeyd etməyib!") return old_reason = sql.update_gban_reason(user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text("İstifadəçi onsuzda bu səbəbdən gban alıb :\n" "<code>{}</code>\n" "".format(html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text("Bu istifadəçi Qlobal Ban olub amma Support İstifadəçilər heçnə qeyd etməyib!") return message.reply_text("⚡️ Hazır olun Support istifadəçilərdən kimsə Qloban Ban verdi ⚡️") 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>Support dəstəsi əsəbləşdi</code>" \ "\n<b>Sudo Admin:</b> {}" \ "\n<b>İstifadəçi:</b> {}" \ "\n<b>ID:</b> <code>{}</code>" \ "\n<b>Səbəb:</b> {}".format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason or "Səbəb qeyd olunmayıb"), 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 olmadı xəta kodu: {}".format(excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Gban olmadı xəta kodu: {}".format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} gban olundu!".format(mention_html(user_chat.id, user_chat.first_name)), html=True) message.reply_text("İstifadəçi Qlobal Ban oldu.")