def removewhitelist(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat user_id = extract_user(message, args) user_member = bot.getChat(user_id) reply = check_user_id(user_id, bot) if reply: message.reply_text(reply) return "" with open(DEVIL_FAMILY_LIST, 'r') as infile: data = json.load(infile) if user_id in WHITELIST_USERS: message.reply_text("Demoting to normal user") WHITELIST_USERS.remove(user_id) data['whitelists'].remove(user_id) with open(DEVIL_FAMILY_LIST, 'w') as outfile: json.dump(data, outfile, indent=4) log_message = (f"#UNWHITELIST\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>User:</b> {mention_html(user_member.id, user_member.first_name)}") if chat.type != 'private': log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message else: message.reply_text("This user is not a whitelist!") return ""
def warns(update, context): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] args = context.args user_id = extract_user(message, args) or update.effective_user.id result = sql.get_warns(user_id, chat.id) num = 1 if result and result[0] != 0: num_warns, reasons = result limit, soft_warn = sql.get_warn_setting(chat.id) if reasons: text = "This user has {}/{} warnings, for the following reasons:".format( num_warns, limit) for reason in reasons: text += "\n {}. {}".format(num, reason) num += 1 msgs = split_message(text) for msg in msgs: update.effective_message.reply_text(msg) else: update.effective_message.reply_text( "User has {}/{} warnings, but no reasons for any of them.". format(num_warns, limit)) else: update.effective_message.reply_text( "This user hasn't got any warnings!")
def demote(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat message = update.effective_message user = update.effective_user 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 log_message try: user_member = chat.get_member(user_id) except: return log_message if user_member.status == 'creator': message.reply_text( "This person CREATED the chat, how would I demote them?") return log_message if not user_member.status == 'administrator': message.reply_text("Can't demote what wasn't promoted!") return log_message if user_id == bot.id: message.reply_text( "I can't demote myself! Get an admin to do it for me.") return log_message try: bot.promoteChatMember(chat.id, user_id, can_change_info=False, can_post_messages=False, can_edit_messages=False, can_delete_messages=False, can_invite_users=False, can_restrict_members=False, can_pin_messages=False, can_promote_members=False) bot.sendMessage(chat.id, "Sucessfully demoted <b>{}</b>!".format( user_member.user.first_name or user_id), parse_mode=ParseMode.HTML) log_message += "<b>{}:</b>" \ "\n#DEMOTED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name)) return log_message except BadRequest: message.reply_text("Could not demote. I might not be admin, or the admin status was appointed by another" \ "user, so I can't act upon them!") return log_message
def get_id(update, context): args = context.args user_id = extract_user(update.effective_message, args) if user_id: if update.effective_message.reply_to_message and update.effective_message.reply_to_message.forward_from: user1 = update.effective_message.reply_to_message.from_user user2 = update.effective_message.reply_to_message.forward_from update.effective_message.reply_text( "The original sender, {}, has an ID of `{}`.\nThe forwarder, {}, has an ID of `{}`." .format(escape_markdown(user2.first_name), user2.id, escape_markdown(user1.first_name), user1.id), parse_mode=ParseMode.MARKDOWN) else: user = context.bot.get_chat(user_id) update.effective_message.reply_text("{}'s id is `{}`.".format( escape_markdown(user.first_name), user.id), parse_mode=ParseMode.MARKDOWN) else: chat = update.effective_chat # type: Optional[Chat] if chat.type == "private": update.effective_message.reply_text("Your id is `{}`.".format( chat.id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( "This group's id is `{}`.".format(chat.id), parse_mode=ParseMode.MARKDOWN)
def get_user_common_chats(update, context): args = context.args msg = update.effective_message user = extract_user(msg, args) if not user: msg.reply_text("I share no common chats with the void.") return common_list = get_user_com_chats(user) if not common_list: msg.reply_text("No common chats with this user!") return name = context.bot.get_chat(user).first_name text = f"<b>Common chats with {name}</b>\n" for chat in common_list: try: chat_name = context.bot.get_chat(chat).title sleep(0.3) text += f"• <code>{chat_name}</code>\n" except BadRequest: pass except Unauthorized: pass except RetryAfter as e: sleep(e.retry_after) if len(text) < 4096: msg.reply_text(text, parse_mode="HTML") else: with open("common_chats.txt", 'w') as f: f.write(text) with open("common_chats.txt", 'rb') as f: msg.reply_document(f) os.remove("common_chats.txt")
def warns(bot: Bot, update: Update, args: List[str]): message: Optional[Message] = update.effective_message chat: Optional[Chat] = update.effective_chat user_id = extract_user(message, args) or update.effective_user.id result = sql.get_warns(user_id, chat.id) if result and result[0] != 0: num_warns, reasons = result limit, soft_warn = sql.get_warn_setting(chat.id) if reasons: text = f"This user has {num_warns}/{limit} warnings, for the following reasons:" for reason in reasons: text += f"\n - {reason}" msgs = split_message(text) for msg in msgs: update.effective_message.reply_text(msg) else: update.effective_message.reply_text( f"User has {num_warns}/{limit} warnings, but no reasons for any of them." ) else: update.effective_message.reply_text( "This user hasn't got any warnings!")
def sungban(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) 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) message.reply_text("{} has been un-gbanned.".format( mention_html(user_chat.id, user_chat.first_name)), parse_mode=ParseMode.HTML)
def addwhitelist(update, context) -> str: args = context.args message = update.effective_message user = update.effective_user chat = update.effective_chat user_id = extract_user(message, args) user_member = context.bot.getChat(user_id) rt = "" reply = check_user_id(user_id, update, context) if reply: message.reply_text(reply) return "" with open(DEVIL_FAMILY_LIST, 'r') as infile: data = json.load(infile) if user_id in SUDO_USERS: rt += "This member is a Sudo User, Demoting to Whitelist User." data['sudos'].remove(user_id) SUDO_USERS.remove(user_id) if user_id in SUPPORT_USERS: rt += "This user is already a Support User, Demoting to Whitelist User." data['supports'].remove(user_id) SUPPORT_USERS.remove(user_id) if user_id in WHITELIST_USERS: message.reply_text("This user is already a Whitelisted User.") return "" data['whitelists'].append(user_id) WHITELIST_USERS.append(user_id) with open(DEVIL_FAMILY_LIST, 'w') as outfile: json.dump(data, outfile, indent=4) update.effective_message.reply_text( rt + f"\nSuccessfully promoted {user_member.first_name} to a Whitelisted User!" ) log_message = ( f"#WHITELIST\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)} \n" f"<b>User:</b> {mention_html(user_member.id, user_member.first_name)}") if chat.type != 'private': log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message
def demote(update, context): chat = update.effective_chat message = update.effective_message user = update.effective_user args = context.args if user_can_promote(chat, user, context.bot.id) == False: message.reply_text("You don't have enough rights to demote someone!") return "" user_id = extract_user(message, args) if not user_id: message.reply_text("mention one.... ЪциЪЈ╗РђЇРЎѓ.") return "" user_member = chat.get_member(user_id) if user_member.status == 'creator': message.reply_text("Lol you want to demote the owner of this groupЪўѓ") return "" if not user_member.status == 'administrator': message.reply_text("How I'm supposed to demote someone who is not even an admin!") return "" if user_id == context.bot.id: message.reply_text("Yeahhh... Not gonna demote myself!") return "" try: context.bot.promoteChatMember(int(chat.id), int(user_id), can_change_info=False, can_post_messages=False, can_edit_messages=False, can_delete_messages=False, can_invite_users=False, can_restrict_members=False, can_pin_messages=False) message.reply_text("Successfully demoted!") return "<b>{}:</b>" \ "\n#DEMOTED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name)) except BadRequest: message.reply_text("Failed to demote. I might not be admin, or the admin status was appointed by another " "user, so I can't act upon them!") return ""
def caschecker(update, context): args = context.args #/info logic msg = update.effective_message # type: Optional[Message] user_id = extract_user(update.effective_message, args) if user_id and int(user_id) != 777000: user = context.bot.get_chat(user_id) elif user_id and int(user_id) == 777000: msg.reply_text( "This is Telegram. Unless you manually entered this reserved account's ID, it is likely a broadcast from a linked channel." ) return elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and ( not args or (len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities([MessageEntity.TEXT_MENTION]))): msg.reply_text("I can't extract a user from this.") return else: return text = "<b>CAS Check</b>:" \ "\nID: <code>{}</code>" \ "\nFirst Name: {}".format(user.id, html.escape(user.first_name)) if user.last_name: text += "\nLast Name: {}".format(html.escape(user.last_name)) if user.username: text += "\nUsername: @{}".format(html.escape(user.username)) text += "\n\nCAS Banned: " result = cas.banchecker(user.id) text += str(result) if result: parsing = cas.offenses(user.id) if parsing: text += "\nTotal of Offenses: " text += str(parsing) parsing = cas.timeadded(user.id) if parsing: parseArray = str(parsing).split(", ") text += "\nDay added: " text += str(parseArray[1]) text += "\nTime added: " text += str(parseArray[0]) text += "\n\nAll times are in UTC" update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def mute(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args if user_can_ban(chat, user, context.bot.id) == False: message.reply_text( "You don't have enough rights to restrict someone from talking!") return "" user_id = extract_user(message, args) if not user_id: message.reply_text( "You'll need to either give me a username to mute, or reply to someone to be muted." ) return "" if user_id == context.bot.id: message.reply_text("Yeahh... I'm not muting myself!") return "" member = chat.get_member(int(user_id)) if member: if is_user_admin(chat, user_id, member=member): message.reply_text( "Well i'm not gonna stop an admin from talking!") elif member.can_send_messages is None or member.can_send_messages: context.bot.restrict_chat_member( chat.id, user_id, permissions=ChatPermissions(can_send_messages=False)) message.reply_text("👍🏻 muted! 🤐") return "<b>{}:</b>" \ "\n#MUTE" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name)) else: message.reply_text("This user is already taped 🤐") else: message.reply_text("This user isn't in the chat!") return ""
def unmute(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args if user_can_ban(chat, user, context.bot.id) == False: message.reply_text("You don't have enough rights to unmute people") return "" user_id = extract_user(message, args) if not user_id: message.reply_text( "You'll need to either give me a username to unmute, or reply to someone to be unmuted." ) return "" member = chat.get_member(int(user_id)) if member.status != 'kicked' and member.status != 'left': if member.can_send_messages and member.can_send_media_messages \ and member.can_send_other_messages and member.can_add_web_page_previews: message.reply_text("This user already has the right to speak.") else: context.bot.restrict_chat_member( chat.id, int(user_id), permissions=ChatPermissions(can_send_messages=True, can_invite_users=True, can_pin_messages=True, can_send_polls=True, can_change_info=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True)) message.reply_text("Yep! this user can start talking again...") return "<b>{}:</b>" \ "\n#UNMUTE" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name)) else: message.reply_text( "This user isn't even in the chat, unmuting them won't make them talk more than they " "already do!") return ""
def addsudo(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat user_id = extract_user(message, args) user_member = bot.getChat(user_id) rt = "" reply = check_user_id(user_id, bot) if reply: message.reply_text(reply) return "" with open(DEVIL_FAMILY_LIST, 'r') as infile: data = json.load(infile) if user_id in SUDO_USERS: message.reply_text("This member is already my SUDO.") return "" if user_id in SUPPORT_USERS: rt += "This user is already a SUPPORT USER." data['supports'].remove(user_id) SUPPORT_USERS.remove(user_id) if user_id in WHITELIST_USERS: rt += "This user is already a WHITELIST USER." data['whitelists'].remove(user_id) WHITELIST_USERS.remove(user_id) data['sudos'].append(user_id) SUDO_USERS.append(user_id) with open(DEVIL_FAMILY_LIST, 'w') as outfile: json.dump(data, outfile, indent=4) update.effective_message.reply_text( rt + "\nSuccessfully added this user {} to sudo!".format(user_member.first_name)) log_message = (f"#SUDO\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>User:</b> {mention_html(user_member.id, user_member.first_name)}") if chat.type != 'private': log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message
def addsupport(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat user_id = extract_user(message, args) user_member = bot.getChat(user_id) rt = "" reply = check_user_id(user_id, bot) if reply: message.reply_text(reply) return "" with open(DEVIL_FAMILY_LIST, 'r') as infile: data = json.load(infile) if user_id in SUDO_USERS: rt += "Demoting status of this SUDO to SUPPORT" data['sudos'].remove(user_id) SUDO_USERS.remove(user_id) if user_id in SUPPORT_USERS: message.reply_text("This user is already a SUDO.") return "" if user_id in WHITELIST_USERS: rt += "Promoting Disaster level from WHITELIST USER to SUPPORT USER" data['whitelists'].remove(user_id) WHITELIST_USERS.remove(user_id) data['supports'].append(user_id) SUPPORT_USERS.append(user_id) with open(DEVIL_FAMILY_LIST, 'w') as outfile: json.dump(data, outfile, indent=4) update.effective_message.reply_text(rt + f"\n{user_member.first_name} was added as a support user!") log_message = (f"#SUPPORT\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>User:</b> {mention_html(user_member.id, user_member.first_name)}") if chat.type != 'private': log_message = "<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str: message: Optional[Message] = update.effective_message chat: Optional[Chat] = update.effective_chat user: Optional[User] = update.effective_user user_id = extract_user(message, args) if user_id: sql.reset_warns(user_id, chat.id) message.reply_text("Warnings have been reset!") warned = chat.get_member(user_id).user return (f"<b>{html.escape(chat.title)}:</b>\n" f"#RESETWARNS\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>User:</b> {mention_html(warned.id, warned.first_name)}") else: message.reply_text("No user has been designated!") return ""
def promote(update, context): chat_id = update.effective_chat.id message = update.effective_message chat = update.effective_chat user = update.effective_user args = context.args if user_can_promote(chat, user, context.bot.id) == False: message.reply_text("You don't have enough rights to promote someone!") return "" user_id = extract_user(message, args) if not user_id: message.reply_text("mention one.... ЪциЪЈ╗РђЇРЎѓ.") return "" user_member = chat.get_member(user_id) if user_member.status == 'administrator' or user_member.status == 'creator': message.reply_text("This person is already an admin...!") return "" if user_id == context.bot.id: message.reply_text("I hope, if i could promote myself!") return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chat.get_member(context.bot.id) context.bot.promoteChatMember(chat_id, user_id, can_change_info=bot_member.can_change_info, can_post_messages=bot_member.can_post_messages, can_edit_messages=bot_member.can_edit_messages, can_delete_messages=bot_member.can_delete_messages, can_invite_users=bot_member.can_invite_users, can_restrict_members=bot_member.can_restrict_members, can_pin_messages=bot_member.can_pin_messages) message.reply_text("PromotedЪДА") return "<b>{}:</b>" \ "\n#PROMOTED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name))
def unmute(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat chat_name = chat.title or chat.first or chat.username user = update.effective_user message = update.effective_message user_id = extract_user(message, args) if not user_id: message.reply_text( "You'll need to either give me a username to unmute, or reply to someone to be unmuted." ) return "" member = chat.get_member(int(user_id)) if member.status != 'kicked' and member.status != 'left': if (member.can_send_messages and member.can_send_media_messages and member.can_send_other_messages and member.can_add_web_page_previews): message.reply_text("This user already has the right to speak.") else: 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) bot.sendMessage( chat.id, f"Yep, <b>{html.escape(member.user.first_name)}</b> can start talking again in " + f"{chat_name}", parse_mode=ParseMode.HTML) return ( f"<b>{html.escape(chat.title)}:</b>\n" f"#UNMUTE\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>User:</b> {mention_html(member.user.id, member.user.first_name)}" ) else: message.reply_text( "This user isn't even in the chat, unmuting them won't make them talk more than they " "already do!") return ""
def reset_warns(update, context): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] args = context.args user_id = extract_user(message, args) if user_id: sql.reset_warns(user_id, chat.id) message.reply_text("Warnings have been reset!") warned = chat.get_member(user_id).user return "<b>{}:</b>" \ "\n#RESETWARNS" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(warned.id, warned.first_name), warned.id) else: message.reply_text("No user has been designated!") return ""
def removesudo(update, context) -> str: args = context.args message = update.effective_message user = update.effective_user chat = update.effective_chat user_id = extract_user(message, args) user_member = context.bot.getChat(user_id) reply = check_user_id(user_id, update, context) if reply: message.reply_text(reply) return "" with open(DEVIL_FAMILY_LIST, 'r') as infile: data = json.load(infile) if user_id in SUDO_USERS: message.reply_text("Demoting to normal user") SUDO_USERS.remove(user_id) data['sudos'].remove(user_id) with open(DEVIL_FAMILY_LIST, 'w') as outfile: json.dump(data, outfile, indent=4) log_message = ( f"#UNSUDO\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>User:</b> {mention_html(user_member.id, user_member.first_name)}" ) if chat.type != 'private': log_message = "<b>{}:</b>\n".format(html.escape( chat.title)) + log_message return log_message else: message.reply_text("This user is not a Sudo!") return ""
def about_bio(bot: Bot, update: Update, args: List[str]): message = update.effective_message user_id = extract_user(message, args) if user_id: user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_bio(user.id) if info: update.effective_message.reply_text("*{}*:\n{}".format( user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = user.first_name update.effective_message.reply_text( f"{username} hasn't had a message set about themselves yet!") else: update.effective_message.reply_text( "You haven't had a bio set about yourself yet!")
def unbl_user(update, context) -> str: message = update.effective_message user = update.effective_user bot, args = context.bot, context.args user_id = extract_user(message, args) if not user_id: message.reply_text("I doubt that's a user.") return "" if user_id == bot.id: message.reply_text("I always notice myself.") return "" try: target_user = 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: raise if sql.is_user_blacklisted(user_id): sql.unblacklist_user(user_id) message.reply_text("*notices user*") log_message = ( f"#UNBLACKLIST\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>User:</b> {mention_html(target_user.id, target_user.first_name)}" ) return log_message else: message.reply_text("I am not ignoring them at all though!") return ""
def about_me(update, context): args = context.args message = update.effective_message user_id = extract_user(message, args) if user_id: user = context.bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_me_info(user.id) if info: update.effective_message.reply_text( f"*{user.first_name}*:\n{escape_markdown(info)}", parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = message.reply_to_message.from_user.first_name update.effective_message.reply_text( f"{username} hasn't set an info message about themselves yet!") else: update.effective_message.reply_text( "You haven't set an info message about yourself yet!")
def gkick(bot: Bot, update: Update, args: List[str]): message = update.effective_message user_id = extract_user(message, args) try: user_chat = bot.get_chat(user_id) except BadRequest as excp: if excp.message in GKICK_ERRORS: pass else: message.reply_text( "User cannot be Globally kicked because: {}".format( excp.message)) return except TelegramError: pass if not user_id or int(user_id) == 777000: message.reply_text("You don't seem to be referring to a user.") return if int(user_id) in SUDO_USERS or int(user_id) in SUPPORT_USERS: message.reply_text( "OHHH! Someone's trying to gkick a sudo/support user! *Grabs popcorn*" ) return if int(user_id) == OWNER_ID: message.reply_text( "Wow! Someone's so noob that he want to gkick my owner! *Grabs Potato Chips*" ) return if user_id == bot.id: message.reply_text("Welp, I'm not gonna to gkick myself!") return chats = get_all_chats() banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "<b>Global Kick</b>" \ "\n#GKICK" \ "\n<b>Status:</b> <code>Enforcing</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) message.reply_text("Globally kicking user @{}".format(user_chat.username)) sql.gkick_user(user_id, user_chat.username, 1) for chat in chats: try: member = bot.get_chat_member(chat.chat_id, user_id) if member.can_send_messages is False: bot.unban_chat_member( chat.chat_id, user_id) # Unban_member = kick (and not ban) bot.restrict_chat_member(chat.chat_id, user_id, can_send_messages=False) else: bot.unban_chat_member(chat.chat_id, user_id) except BadRequest as excp: if excp.message in GKICK_ERRORS: pass else: message.reply_text( "User cannot be Globally kicked because: {}".format( excp.message)) return except TelegramError: pass
def info(update, context): args = context.args msg = update.effective_message # type: Optional[Message] user_id = extract_user(update.effective_message, args) chat = update.effective_chat if user_id: user = context.bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and ( not args or (len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities([MessageEntity.TEXT_MENTION]))): msg.reply_text("I can't extract a user from this.") return else: return del_msg = msg.reply_text("Life is <b>Short</b> Death is <b>Sure</b>...!", parse_mode=ParseMode.HTML) text = "<b>Knights of Hell</b>:" \ "\n\nID: <code>{}</code>" \ "\nFirst Name: {}".format(user.id, html.escape(user.first_name)) if user.last_name: text += "\nLast Name: {}".format(html.escape(user.last_name)) if user.username: text += "\nUsername: @{}".format(html.escape(user.username)) text += "\nPermanent user link: {}".format(mention_html(user.id, "link")) text += "\nNumber of profile pics: {}".format( context.bot.get_user_profile_photos(user.id).total_count) knight_of_hell = False try: sw = sw.get_ban(int(user.id)) if sw: text += '\n\n<b>This person is banned in Spamwatch!</b>' text += f'\nResason: <pre>{sw_reason}</pre>' else: pass except: pass # Don't break on exceptions like if api is down? if user.id == OWNER_ID: text += "\n\nAyy this Guy is my <b>Angel</b>!" knight_of_hell = True elif user.id in DEV_USERS: text += "\n\nThis person is a <b>Vampire</b>!" knight_of_hell = True elif user.id in SUDO_USERS: text += "\n\nThis person is a <b>Dragon</b>!" knight_of_hell = True elif user.id in SUPPORT_USERS: text += "\n\nThis person is a <b>Ghoul</b>!" knight_of_hell = True elif user.id in WHITELIST_USERS: text += "\n\nThis person is a <b>Ghost</b>!" knight_of_hell = True if knight_of_hell: text += ' [<a href="http://t.me/{}?start=knights">?</a>]'.format( context.bot.username) try: memstatus = chat.get_member(user.id).status if memstatus == 'administrator' or memstatus == 'creator': result = context.bot.get_chat_member(chat.id, user.id) if result.custom_title: text += f"\n\nThis user has custom title <b>{result.custom_title}</b> in this chat." except BadRequest: pass for mod in USER_INFO: try: mod_info = mod.__user_info__(user.id).strip() except TypeError: mod_info = mod.__user_info__(user.id, chat.id).strip() if mod_info: text += "\n\n" + mod_info try: profile = context.bot.get_user_profile_photos(user.id).photos[0][-1] context.bot.sendChatAction(chat.id, "upload_photo") context.bot.send_photo(chat.id, photo=profile, caption=(text), parse_mode=ParseMode.HTML, disable_web_page_preview=True) except IndexError: context.bot.sendChatAction(chat.id, "typing") msg.reply_text(text, parse_mode=ParseMode.HTML, disable_web_page_preview=True) finally: del_msg.delete()
def info(bot: Bot, update: Update, args: List[str]): message = update.effective_message chat = update.effective_chat user_id = extract_user(update.effective_message, args) if user_id: user = bot.get_chat(user_id) elif not message.reply_to_message and not args: user = message.from_user elif not message.reply_to_message and ( not args or (len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not message.parse_entities([MessageEntity.TEXT_MENTION]))): message.reply_text("I can't extract a user from this.") return else: return text = (f"<b>Characteristics:</b>\n" f"ID: <code>{user.id}</code>\n" f"First Name: {html.escape(user.first_name)}") if user.last_name: text += f"\nLast Name: {html.escape(user.last_name)}" if user.username: text += f"\nUsername: @{html.escape(user.username)}" text += f"\nPermanent user link: {mention_html(user.id, 'link')}" num_chats = sql.get_user_num_chats(user.id) text += f"\nChat count: <code>{num_chats}</code>" try: user_member = chat.get_member(user.id) if user_member.status == 'administrator': result = requests.post( f"https://api.telegram.org/bot{TOKEN}/getChatMember?chat_id={chat.id}&user_id={user.id}" ) result = result.json()["result"] if "custom_title" in result.keys(): custom_title = result['custom_title'] text += f"\nThis user holds the title <b>{custom_title}</b> here." except BadRequest: pass if user.id == OWNER_ID: text += "\nThis person is my owner - I would never do anything against them!." elif user.id in DEV_USERS: text += "\nThis person is my dev - I would never do anything against them!." elif user.id in SUDO_USERS: text += "\nThis person is one of my sudo users! " \ "Nearly as powerful as my owner - so watch it.." elif user.id in SUPPORT_USERS: text += "\nThis person is one of my support users! " \ "Not quite a sudo user, but can still gban you off the map." elif user.id in WHITELIST_USERS: text += "\nThis person has been whitelisted! " \ "That means I'm not allowed to ban/kick them." text += "\n" text += "\nCAS banned: " result = cas.banchecker(user.id) text += str(result) for mod in USER_INFO: if mod.__mod_name__ == "Users": continue try: mod_info = mod.__user_info__(user.id) except TypeError: mod_info = mod.__user_info__(user.id, chat.id) if mod_info: text += "\n" + mod_info update.effective_message.reply_text(text, parse_mode=ParseMode.HTML, disable_web_page_preview=True)
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.") 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 promote(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message chat = update.effective_chat user = update.effective_user 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 log_message try: user_member = chat.get_member(user_id) except: return log_message if user_member.status == 'administrator' or user_member.status == 'creator': message.reply_text( "How am I meant to promote someone that's already an admin?") return log_message if user_id == bot.id: message.reply_text( "I can't promote myself! Get an admin to do it for me.") return log_message # set same perms as bot - bot can't assign higher perms than itself! bot_member = chat.get_member(bot.id) try: bot.promoteChatMember( chat.id, user_id, can_change_info=bot_member.can_change_info, can_post_messages=bot_member.can_post_messages, can_edit_messages=bot_member.can_edit_messages, can_delete_messages=bot_member.can_delete_messages, can_invite_users=bot_member.can_invite_users, # can_promote_members=bot_member.can_promote_members, can_restrict_members=bot_member.can_restrict_members, can_pin_messages=bot_member.can_pin_messages) except BadRequest as err: if err.message == "User_not_mutual_contact": message.reply_text( "I can't promote someone who isn't in the group.") return log_message else: message.reply_text("An error occured while promoting.") return log_message bot.sendMessage(chat.id, "Sucessfully promoted <b>{}</b>!".format( user_member.user.first_name or user_id), parse_mode=ParseMode.HTML) log_message += "<b>{}:</b>" \ "\n#PROMOTED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name)) return log_message