def msg_evidence(update: Update, context: CallbackContext): msg = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] args = msg.text.split(" ") user_id, reason = extract_user_and_text(msg, args) user_chat = context.bot.get_chat(user_id) send_proof = msg.reply_to_message.forward(EVIDENCES_LOG) saved = msg.reply_text("Global Ban evidence submitted!") msg.delete() try: time.sleep(3) saved.delete() except TelegramError as e: if e.message == "Peer_id_invalid": msg.reply_text("Contact me in PM first.", reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="Start", url=f"t.me/{context.bot.username}") ]])) return if send_proof: saved banner = update.effective_user # type: Optional[User] send_gban = "<b>Global Ban Evidence</b>" \ "\n#EVIDENCE" \ "\n<b>Status:</b> <code>Submitted</code>" \ "\n<b>Name:</b> {}".format(mention_html(user_chat.id, user_chat.first_name or "Deleted Account")) if user_chat.last_name: send_gban += "\n<b>Surname:</b> {}".format( mention_html(user_chat.id, user_chat.last_name)) if user_chat.username: send_gban += "\n<b>Username:</b> @{}".format( html.escape(user_chat.username)) if user_chat: send_gban += "\n<b>ID:</b> <code>{}</code>".format(user_chat.id) if banner.id in SUDO_USERS: send_gban += "\n<b>Sudo:</b> {}".format( mention_html(banner.id, banner.first_name)) if banner.id in SUPPORT_USERS: send_gban += "\n<b>Support:</b> {}".format( mention_html(banner.id, banner.first_name)) if reason: send_gban += "\n<b>Description of Evidence:</b> \n{}".format( reason) context.bot.send_message(chat_id=EVIDENCES_LOG, text=send_gban, parse_mode=ParseMode.HTML) else: msg.reply_text("Failed to submit proof.")
def kick(update: Update, context: CallbackContext) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = message.text.split(" ") user_id, reason = extract_user_and_text(message, args) if not user_id: return "" try: member = chat.get_member(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 is_user_ban_protected(chat, user_id): message.reply_text( "I'm not gonna kick an admin... Though I reckon it'd be pretty funny." ) return "" if user_id == context.bot.id: message.reply_text("Yeahhh I'm not gonna do that") return "" res = chat.unban_member(user_id) # unban on current user = kick if res: log = "<b>{}:</b>" \ "\n#KICKED" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id) reply = "{} has been kicked!".format( mention_html(member.user.id, member.user.first_name)) if reason: log += "\n<b>• Reason:</b> {}".format(reason) reply += "\n<b>Reason:</b> <i>{}</i>".format(reason) context.bot.send_sticker(chat.id, BAN_STICKER) # banhammer hercules sticker message.reply_text(reply, parse_mode=ParseMode.HTML) return log else: message.reply_text("Well damn, I can't kick that user.") return ""
def mute(update: Update, context: CallbackContext) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = message.text.split(" ") user_id, reason = extract_user_and_text(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("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("Afraid I can't stop an admin from talking!") elif member.can_send_messages is None or member.can_send_messages: log = "<b>{}:</b>" \ "\n#MUTE" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id) reply = "Shh!\n{} is muted!".format( mention_html(member.user.id, member.user.first_name)) if reason: log += "\n<b>• Reason:</b> {}".format(reason) reply += "\n<b>Reason:</b> <i>{}</i>".format(reason) context.bot.restrict_chat_member(chat.id, user_id, MUTE_PERMISSIONS) message.reply_text(reply, parse_mode=ParseMode.HTML) return log else: message.reply_text("This user is already muted!") else: message.reply_text("This user isn't in the chat!") return ""
def sban(update: Update, context: CallbackContext) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = message.text.split(" ") update.effective_message.delete() user_id, reason = extract_user_and_text(message, args) if not user_id: return "" try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": return "" else: raise if is_user_ban_protected(chat, user_id, member): return "" if user_id == context.bot.id: return "" log = "<b>{}:</b>" \ "\n#SILENT_BAN" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id) if reason: log += "\n<b>• Reason:</b> {}".format(reason) try: chat.kick_member(user_id) return log except BadRequest as excp: if excp.message == "Reply message not found": return log else: LOGGER.warning(update) LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) return ""
def warn_user(update: Update, context: CallbackContext) -> str: message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] warner = update.effective_user # type: Optional[User] user_id, reason = extract_user_and_text(message, message.text.split(" ")) if user_id: if message.reply_to_message and message.reply_to_message.from_user.id == user_id: return warn(message.reply_to_message.from_user, chat, reason, message.reply_to_message, warner) else: return warn( chat.get_member(user_id).user, chat, reason, message, warner) else: message.reply_text("No user was designated!") return ""
def unban(update: Update, context: CallbackContext) -> str: message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] args = message.text.split(" ") user_id, reason = extract_user_and_text(message, args) if not user_id: return "" try: member = chat.get_member(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 user_id == context.bot.id: message.reply_text("How would I unban myself if I wasn't here...?") return "" if is_user_in_chat(chat, user_id): message.reply_text( "Why are you trying to unban someone that's already in the chat?") return "" chat.unban_member(user_id) reply = "Yep, {} can join again!".format( mention_html(member.user.id, member.user.first_name)) message.reply_text(reply, parse_mode=ParseMode.HTML) log = "<b>{}:</b>" \ "\n#UNBANNED" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id) if reason: log += "\n<b>• Reason:</b> {}".format(reason) return log
def smute(update: Update, context: CallbackContext) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = message.text.split(" ") update.effective_message.delete() user_id, reason = extract_user_and_text(message, args) if not user_id: return "" if user_id == context.bot.id: message.reply_text("Really?! You're not supposed silent mute me!") return "" member = chat.get_member(int(user_id)) if member: if is_user_admin(chat, user_id, member=member): return "" elif member.can_send_messages is None or member.can_send_messages: context.bot.restrict_chat_member(chat.id, user_id, MUTE_PERMISSIONS) log = "<b>{}:</b>" \ "\n#SILENT_MUTE" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id) if reason: log += "\n<b>• Reason:</b> {}".format(reason) return log return ""
def gban(update: Update, context: CallbackContext): message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] args = message.text.split(" ") 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( "You're playing with fire! Sudo war is catastrophic.") return if int(user_id) in SUPPORT_USERS: message.reply_text( "I can't global ban a support user! Only my creator can!") return if int(user_id) in SUPER_ADMINS: message.reply_text( "This is one of the super admin users appointed by the hierarchy. " "Therefore, I can't touch this user!") return if user_id == context.bot.id: message.reply_text("Only my creator can decide the fate!") return try: user_chat = context.bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if sql.is_user_gbanned(user_id): if not reason: msg = "User {} is already globally banned; I'd change the reason, " \ "but you haven't given me one...".format(mention_html(user_chat.id, user_chat.first_name or "Deleted Account")) message.reply_text(msg, parse_mode=ParseMode.HTML) 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 == new_reason: same_reason = "User {} has already been globally banned, with the " \ "exact same reason.".format(mention_html(user_chat.id, user_chat.first_name or "Deleted Account")) message.reply_text(same_reason, parse_mode=ParseMode.HTML) return if old_reason: banner = update.effective_user # type: Optional[User] send_gban = "<b>Emendation of Global Ban</b>" \ "\n#GBAN" \ "\n<b>Status:</b> <code>Amended</code>" \ "\n<b>Name:</b> {}".format(mention_html(user_chat.id, user_chat.first_name or "Deleted Account")) if user_chat.last_name: send_gban += "\n<b>Surname:</b> {}".format( mention_html(user_chat.id, user_chat.last_name)) if user_chat.username: send_gban += "\n<b>Username:</b> @{}".format( html.escape(user_chat.username)) if user_chat: send_gban += "\n<b>ID:</b> <code>{}</code>".format( user_chat.id) if banner.id in SUDO_USERS: send_gban += "\n<b>Sudo:</b> {}".format( mention_html(banner.id, banner.first_name)) if banner.id in SUPPORT_USERS: send_gban += "\n<b>Support:</b> {}".format( mention_html(banner.id, banner.first_name)) if reason: send_gban += "\n<b>Previous:</b> {}".format(old_reason) send_gban += "\n<b>Amended:</b> {}".format(new_reason) context.bot.send_message(chat_id=GBAN_LOG, text=send_gban, parse_mode=ParseMode.HTML) old_msg = "User {} is already globally banned, for the following reason:\n" \ "<code>{}</code>\n" \ "I've gone and updated it with your new reason!".format(mention_html(user_chat.id, user_chat.first_name or "Deleted Account"), old_reason) message.reply_text(old_msg, parse_mode=ParseMode.HTML) else: banner = update.effective_user # type: Optional[User] send_gban = "<b>Emendation of Global Ban</b>" \ "\n#GBAN" \ "\n<b>Status:</b> <code>New reason</code>" \ "\n<b>Name:</b> {}".format(mention_html(user_chat.id, user_chat.first_name or "Deleted Account")) if user_chat.last_name: send_gban += "\n<b>Surname:</b> {}".format( mention_html(user_chat.id, user_chat.last_name)) if user_chat.username: send_gban += "\n<b>Username:</b> @{}".format( html.escape(user_chat.username)) if user_chat: send_gban += "\n<b>ID:</b> <code>{}</code>".format( user_chat.id) if banner.id in SUDO_USERS: send_gban += "\n<b>Sudo:</b> {}".format( mention_html(banner.id, banner.first_name)) if banner.id in SUPPORT_USERS: send_gban += "\n<b>Support:</b> {}".format( mention_html(banner.id, banner.first_name)) if banner.id in SUPER_ADMINS: send_gban += "\n<b>Super Admin:</b> {}".format( mention_html(banner.id, banner.first_name)) if reason: send_gban += "\n<b>Reason:</b> {}".format(new_reason) context.bot.send_message(chat_id=GBAN_LOG, text=send_gban, parse_mode=ParseMode.HTML) msg = "User {} is already globally banned, but had no reason set; " \ "I've gone and updated it!".format(mention_html(user_chat.id, user_chat.first_name or "Deleted Account")) message.reply_text(msg, parse_mode=ParseMode.HTML) return starting = "Initiating global ban for {}...".format( mention_html(user_chat.id, user_chat.first_name or "Deleted Account")) message.reply_text(starting, parse_mode=ParseMode.HTML) banner = update.effective_user # type: Optional[User] send_gban = "<b>Global Ban</b>" \ "\n#GBAN" \ "\n<b>Status:</b> <code>Enforced</code>" \ "\n<b>Name:</b> {}".format(mention_html(user_chat.id, user_chat.first_name or "Deleted Account")) if user_chat.last_name: send_gban += "\n<b>Surname:</b> {}".format( mention_html(user_chat.id, user_chat.last_name)) if user_chat.username: send_gban += "\n<b>Username:</b> @{}".format( html.escape(user_chat.username)) if user_chat: send_gban += "\n<b>ID:</b> <code>{}</code>".format(user_chat.id) if banner.id in SUDO_USERS: send_gban += "\n<b>Sudo:</b> {}".format( mention_html(banner.id, banner.first_name)) if banner.id in SUPPORT_USERS: send_gban += "\n<b>Support:</b> {}".format( mention_html(banner.id, banner.first_name)) if reason: send_gban += "\n<b>Reason:</b> {}".format(reason) context.bot.send_message(chat_id=GBAN_LOG, text=send_gban, parse_mode=ParseMode.HTML) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) fban_id = update.effective_chat # type: Optional[Chat] chats = get_users_by_chat(fban_id.id, user_id) for chat in chats: chat_id = chat.chat # Check if this group has disabled gbans if not sql.does_chat_gban(chat_id): continue try: context.bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text("Could not gban due to: {}".format( excp.message)) sql.ungban_user(user_id) return except TelegramError: pass blacklist_t = "User {} has been successfully globally banned".format( mention_html(user_chat.id, user_chat.first_name or "Deleted Account")) context.bot.send_message(chat_id=GBAN_LOG, text=blacklist_t, parse_mode=ParseMode.HTML) message.reply_text("User {} has been globally banned!".format( mention_html(user_chat.id, user_chat.first_name or "Deleted Account")), parse_mode=ParseMode.HTML)
def temp_nomedia(update: Update, context: CallbackContext) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = message.text.split(" ") 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 "" try: member = chat.get_member(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 is_user_admin(chat, user_id, member): message.reply_text("I really wish I could restrict admins...") return "" if user_id == context.bot.id: message.reply_text("I'm not gonna RESTRICT myself, are you crazy?") return "" if not reason: message.reply_text( "You haven't specified a time to restrict this user for!") return "" split_reason = reason.split(None, 1) time_val = split_reason[0].lower() if len(split_reason) > 1: reason = split_reason[1] else: reason = "" mutetime = extract_time(message, time_val) if not mutetime: return "" log = "<b>{}:</b>" \ "\n#TEMP RESTRICTED" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>" \ "\n<b>• Time:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id, time_val) if reason: log += "\n<b>• Reason:</b> {}".format(reason) try: if member.can_send_messages is None or member.can_send_messages: context.bot.restrict_chat_member(chat.id, user_id, NOMEDIA_PERMISSIONS, until_date=mutetime) message.reply_text( "{} restricted from sending media for {}!".format( mention_html(member.user.id, member.user.first_name), time_val), parse_mode=ParseMode.HTML) return log else: message.reply_text("This user is already restricted.") except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text( "{} restricted from sending media for {}!".format( mention_html(member.user.id, member.user.first_name), time_val), parse_mode=ParseMode.HTML, quote=False) return log else: LOGGER.warning(update) LOGGER.exception("ERROR muting user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) message.reply_text("Well damn, I can't restrict that user.") return ""
def temp_ban(update: Update, context: CallbackContext) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = message.text.split(" ") 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 "" try: member = chat.get_member(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 is_user_ban_protected(chat, user_id, member): message.reply_text("I really wish I could ban admins...") return "" if user_id == context.bot.id: message.reply_text("I'm not gonna BAN myself, are you crazy?") return "" if not reason: message.reply_text( "You haven't specified a time to ban this user for!") return "" split_reason = reason.split(None, 1) time_val = split_reason[0].lower() if len(split_reason) > 1: reason = split_reason[1] else: reason = "" bantime = extract_time(message, time_val) if not bantime: return "" log = "<b>{}:</b>" \ "\n#TEMPBAN" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>" \ "\n<b>• Time:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id, time_val) if reason: log += "\n<b>• Reason:</b> {}".format(reason) try: chat.kick_member(user_id, until_date=bantime) context.bot.send_sticker(update.effective_chat.id, BAN_STICKER) # banhammer marie sticker reply = "{} has been temporarily banned for {}!".format( mention_html(member.user.id, member.user.first_name), time_val) message.reply_text(reply, parse_mode=ParseMode.HTML) return log except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text( "Banned! User will be banned for {}.".format(time_val), quote=False) return log else: LOGGER.warning(update) LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) message.reply_text("Well damn, I can't ban that user.") return ""
def ban(update: Update, context: CallbackContext) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = message.text.split(" ") 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 "" try: member = chat.get_member(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 is_user_ban_protected(chat, user_id, member): message.reply_text( "Why would I ban an admin? That sounds like a pretty dumb idea.") return "" if user_id == context.bot.id: message.reply_text("I'm not gonna BAN myself, are you crazy?") return "" log = "<b>{}:</b>" \ "\n#BANNED" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id) reply = "{} has been banned!".format( mention_html(member.user.id, member.user.first_name)) if reason: log += "\n<b>• Reason:</b> {}".format(reason) reply += "\n<b>Reason:</b> <i>{}</i>".format(reason) try: chat.kick_member(user_id) context.bot.send_sticker(update.effective_chat.id, BAN_STICKER) # banhammer hercules sticker message.reply_text(reply, parse_mode=ParseMode.HTML) return log except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text('Banned!', quote=False) return log else: LOGGER.warning(update) LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) message.reply_text("Well damn, I can't ban that user.") return ""
def rban(update: Update, context: CallbackContext): message = update.effective_message #chat_name = chat.title or chat.first or chat.username chat = update.effective_chat # type: Optional[Chat] args = message.text.split(" ") if not args: message.reply_text("You don't seem to be referring to a chat/user.") return user_id, chat_id = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return elif not chat_id: message.reply_text("You don't seem to be referring to a chat.") return try: chat = context.bot.get_chat(chat_id.split()[0]) except BadRequest as excp: if excp.message == "Chat not found": message.reply_text( "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat." ) return else: raise if chat.type == 'private': message.reply_text("I'm sorry, but that's a private chat!") return if not is_bot_admin(chat, context.bot.id) or not chat.get_member( context.bot.id).can_restrict_members: message.reply_text( "I can't restrict people there! Make sure I'm admin and can ban users." ) return try: member = chat.get_member(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 is_user_ban_protected(chat, user_id, member): message.reply_text("I really wish I could ban admins...") return if user_id == context.bot.id: message.reply_text("I'm not gonna BAN myself, are you crazy?") return try: chat.kick_member(user_id) rbanning = "Hunting again in the wild!\n{} has been remotely banned from {}! \n".format( mention_html(member.user.id, member.user.first_name), (chat.title or chat.first or chat.username)) context.bot.send_sticker(update.effective_chat.id, BAN_STICKER) message.reply_text(rbanning, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text('Banned!', quote=False) elif excp.message in RBAN_ERRORS: message.reply_text(excp.message) else: LOGGER.warning(update) LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) message.reply_text("Well damn, I can't ban that user.")
def runmute(update: Update, context: CallbackContext): message = update.effective_message args = message.text.split(" ") if not args: message.reply_text("You don't seem to be referring to a chat/user.") return user_id, chat_id = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return elif not chat_id: message.reply_text("You don't seem to be referring to a chat.") return try: chat = context.bot.get_chat(chat_id.split()[0]) except BadRequest as excp: if excp.message == "Chat not found": message.reply_text( "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat." ) return else: raise if chat.type == 'private': message.reply_text("I'm sorry, but that's a private chat!") return if not is_bot_admin(chat, context.bot.id) or not chat.get_member( context.bot.id).can_restrict_members: message.reply_text( "I can't unrestrict people there! Make sure I'm admin and can unban users." ) return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user there") return else: raise if is_user_in_chat(chat, user_id): if member.can_send_messages and member.can_send_media_messages \ and member.can_send_other_messages and member.can_add_web_page_previews: message.reply_text( "This user already has the right to speak in that chat.") return if user_id == context.bot.id: message.reply_text("I'm not gonna UNMUTE myself, I'm an admin there!") return try: context.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) runmuting = "Well, I will let {} speak on {}!".format( mention_html(member.user.id, member.user.first_name), (chat.title or chat.first or chat.username)) message.reply_text(runmuting, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text('Unmuted!', quote=False) elif excp.message in RUNMUTE_ERRORS: message.reply_text(excp.message) else: LOGGER.warning(update) LOGGER.exception( "ERROR unmnuting user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) message.reply_text("Well damn, I can't unmute that user.")
def runban(update: Update, context: CallbackContext): message = update.effective_message args = message.text.split(" ") if not args: message.reply_text("You don't seem to be referring to a chat/user.") return user_id, chat_id = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return elif not chat_id: message.reply_text("You don't seem to be referring to a chat.") return try: chat = context.bot.get_chat(chat_id.split()[0]) except BadRequest as excp: if excp.message == "Chat not found": message.reply_text( "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat." ) return else: raise if chat.type == 'private': message.reply_text("I'm sorry, but that's a private chat!") return if not is_bot_admin(chat, context.bot.id) or not chat.get_member( context.bot.id).can_restrict_members: message.reply_text( "I can't unrestrict people there! Make sure I'm admin and can unban users." ) return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user there") return else: raise if is_user_in_chat(chat, user_id): message.reply_text( "Why are you trying to remotely unban someone that's already in that chat?" ) return if user_id == context.bot.id: message.reply_text("I'm not gonna UNBAN myself, I'm an admin there!") return try: chat.unban_member(user_id) runbanning = "I am allowing {} to join {}!".format( mention_html(member.user.id, member.user.first_name), (chat.title or chat.first or chat.username)) message.reply_text(runbanning, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text('Unbanned!', quote=False) elif excp.message in RUNBAN_ERRORS: message.reply_text(excp.message) else: LOGGER.warning(update) LOGGER.exception( "ERROR unbanning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) message.reply_text("Well damn, I can't unban that user.")