def ban(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text(tld(chat.id, "You don't seem to be referring to a person.")) return "" try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "Person not found": message.reply_text(tld(chat.id, "I can't seem to find this person")) return "" else: raise if user_id == bot.id: message.reply_text(tld(chat.id, "I'm not gonna BAN myself, are you crazy?")) return "" if is_user_ban_protected(chat, user_id, member): message.reply_text(tld(chat.id, "Why would I ban an Admin? That sounds like a pretty dumb idea.")) return "" log = "<b>{}:</b>" \ "\n#BANNED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: chat.kick_member(user_id) bot.send_sticker(chat.id, BAN_STICKER) # Menhera Chan Ban sticker message.reply_text(tld(chat.id, "Banned!")) return log except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text(tld(chat.id, "Banned!"), quote=False) return log else: LOGGER.warning(update) LOGGER.exception("ERROR banning person %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) message.reply_text(tld(chat.id, "Banned!")) return ""
def unban(update, context): message = update.effective_message user = update.effective_user chat = update.effective_chat args = context.args if user_can_ban(chat, user, context.bot.id) is False: message.reply_text( "You don't have enough rights to unban people here!" ) return "" 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 who's already in this chat?" ) return "" chat.unban_member(user_id) message.reply_text("Done, they can join again!") log = ( "<b>{}:</b>" "\n#UNBANNED" "\n<b>Admin:</b> {}" "\n<b>User:</b> {} (<code>{}</code>)".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id, ) ) if reason: log += "\n<b>Reason:</b> {}".format(reason) return log
def kick(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] 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 == "Person not found": message.reply_text("I can't seem to find this person") return "" else: raise if user_id == bot.id: message.reply_text("I'm not kicking myself!") return "" if is_user_ban_protected(chat, user_id): message.reply_text("Why would I kick an Admin? That sounds like a pretty dumb idea.") return "" res = chat.unban_member(user_id) # unban on current user = kick if res: keyboard = [] reply = "{} Kicked!".format(mention_html(member.user.id, member.user.first_name)) message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) log = "<b>{}:</b>" \ "\n#KICKED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id) if reason: log += "\n<b>Reason:</b> {}".format(reason) return log else: message.reply_text("Kicked!") return ""
def sban(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] 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 == "Person not found": return "" else: raise if is_user_ban_protected(chat, user_id, member): return "" if user_id == bot.id: return "" log = "<b>{}:</b>" \ "\n# SILENTBAN" \ "\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 person %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) return ""
def warn_user(bot: Bot, update: Update, args: List[str]) -> 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, args) 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 person was designated!") return ""
def unban(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] 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 == "Person not found": message.reply_text("I can't seem to find this person") return "" else: raise if user_id == 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) message.reply_text("Destiny gave you second chance. Don't waste it. 🙂") log = "<b>{}:</b>" \ "\n#UNBANNED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id) if reason: log += "\n<b>Reason:</b> {}".format(reason) return log
def warn_user(update, context): message = update.effective_message chat = update.effective_chat warner = update.effective_user args = context.args user_id, reason = extract_user_and_text(message, args) 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 gmute(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a person.") return if int(user_id) in SUDO_USERS: message.reply_text( "I spy, with my little eye... a sudo user war! Why are you guys turning on each other?" ) return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH someone's trying to gmute a support user! *grabs popcorn*") return if user_id == bot.id: message.reply_text( "-_- So funny, lets gmute myself why don't I? Nice try.") return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if sql.is_user_gmuted(user_id): if not reason: message.reply_text( "This user is already gmuted; I'd change the reason, but you haven't given me one..." ) return success = sql.update_gmute_reason( user_id, user_chat.username or user_chat.first_name, reason) if success: message.reply_text( "This user is already gmuted; I've gone and updated the gmute reason though!" ) else: message.reply_text( "Do you mind trying again? I thought this person was gmuted, but then they weren't? " "Am very confused") return message.reply_text("*Gets duct tape ready* 😉") muter = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} is gmuting user {} " "because:\n{}".format( mention_html(muter.id, muter.first_name), mention_html(user_chat.id, user_chat.first_name), reason or "No reason given"), html=True) sql.gmute_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gmutes if not sql.does_chat_gban(chat_id): continue try: bot.restrict_chat_member(chat_id, user_id, can_send_messages=False) except BadRequest as excp: if excp.message == "User is an administrator of the chat": pass elif excp.message == "Chat not found": pass elif excp.message == "Not enough rights to restrict/unrestrict chat member": pass elif excp.message == "User_not_participant": pass elif excp.message == "Peer_id_invalid": # Suspect this happens when a group is suspended by telegram. pass elif excp.message == "Group chat was deactivated": pass elif excp.message == "Need to be inviter of a user to kick it from a basic group": pass elif excp.message == "Chat_admin_required": pass elif excp.message == "Only the creator of a basic group can kick group administrators": pass elif excp.message == "Method is available only for supergroups": pass elif excp.message == "Can't demote chat creator": pass else: message.reply_text("Could not gmute due to: {}".format( excp.message)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Could not gmute due to: {}".format(excp.message)) sql.ungmute_user(user_id) return except TelegramError: pass send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "gmute complete!") message.reply_text("Person has been gmuted.")
def temp_nomedia(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": exit(1) else: chatD = chat user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text( tld(chat.id, "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(tld(chat.id, "I can't seem to find this user")) return "" else: raise if is_user_admin(chat, user_id, member): message.reply_text( tld(chat.id, "I really wish I could restrict admins...")) return "" if user_id == bot.id: message.reply_text( tld(chat.id, "I'm not gonna RESTRICT myself, are you crazy?")) return "" if not reason: message.reply_text( tld(chat.id, "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: bot.restrict_chat_member(chat.id, user_id, until_date=mutetime, can_send_messages=True, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False) message.reply_text( tld(chat.id, "Restricted from sending media for {} in {}!").format( time_val, chatD.title)) return log else: message.reply_text( tld(chat.id, "This user is already restricted in {}.").format( chatD.title)) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text(tld(chat.id, "Restricted for {} in {}!").format( time_val, chatD.title), 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( tld(chat.id, "Well damn, I can't restrict that user.")) return ""
def kick(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message args = context.args if user_can_ban(chat, user, context.bot.id) is False: message.reply_text("You don't have enough rights to kick users!") return "" 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("Yeahh... let's start kicking admins?") 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: # context.bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie # sticker context.bot.sendMessage( chat.id, "Untill we meet again {}.".format( mention_html(member.user.id, member.user.first_name) ), parse_mode=ParseMode.HTML, ) log = ( "<b>{}:</b>" "\n#KICKED" "\n<b>Admin:</b> {}" "\n<b>User:</b> {} (<code>{}</code>)".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id, ) ) if reason: log += "\n<b>Reason:</b> {}".format(reason) return log else: message.reply_text("Get Out!.") return ""
def ban(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message args = context.args if user_can_ban(chat, user, context.bot.id) is False: message.reply_text("You don't have enough rights to ban users!") return "" user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("Dude atleast refer some user to ban!") 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'm not gonna ban an admin, don't make fun of yourself!" ) return "" if user_id == context.bot.id: message.reply_text("I'm not gonna BAN myself, are you crazy or wot?") return "" log = ( "<b>{}:</b>" "\n#BANNED" "\n<b>Admin:</b> {}" "\n<b>User:</b> {} (<code>{}</code>)".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id, ) ) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: chat.kick_member(user_id) # context.bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie # sticker context.bot.sendMessage( chat.id, "let {} walk the plank.".format( mention_html(member.user.id, member.user.first_name) ), 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 gban(update, context): message = update.effective_message chat = update.effective_chat args = context.args user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return if user_id == OWNER_ID: message.reply_text("Nice try -_- but I'm never gonna gban him.") return if int(user_id) in DEV_USERS: message.reply_text( "Whatt... How can i gban someone that take care of me +_+") 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 in (777000, 1087968824): message.reply_text( "How can i ban someone that i don't know who is it.") return if user_id == context.bot.id: message.reply_text( "-_- So funny, lets gban myself why don't I? Nice try.") return if not reason: message.reply_text( "Please Specified a reason. I won't allow a bare gban :)") 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 user_chat.first_name == "": message.reply_text( "This is a deleted account! no point to gban them...") return banner = update.effective_user bannerid = banner.id bannername = banner.first_name reason = f"{reason} // GBanned by {bannername} banner id: {bannerid}" if gban_db.is_user_gbanned(user_id): old_reason = gban_db.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) context.bot.sendMessage( GBAN_LOGS, "<b>Global Ban Reason Update</b>" "\n<b>Sudo Admin:</b> {}" "\n<b>User:</b> {}" "\n<b>ID:</b> <code>{}</code>" "\n<b>Previous Reason:</b> {}" "\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, old_reason, reason, ), parse_mode=ParseMode.HTML, ) 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( f"<b>Beginning of Global Ban for</b> {mention_html(user_chat.id, user_chat.first_name)}" f"\n<b>With ID</b>: <code>{user_chat.id}</code>" f"\n<b>Reason</b>: <code>{reason or 'No reason given'}</code>", parse_mode=ParseMode.HTML, ) context.bot.sendMessage( GBAN_LOGS, "<b>New 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, ), parse_mode=ParseMode.HTML, ) try: context.bot.kick_chat_member(chat.id, user_chat.id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass gban_db.gban_user(user_id, user_chat.username or user_chat.first_name, reason)
def temp_ban(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message args = context.args if user_can_ban(chat, user, context.bot.id) is False: message.reply_text( "You don't have enough rights to temporarily ban someone!" ) return "" user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("Dude! atleast refer some user to ban...") 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("Wow! let's start banning Admins themselves?...") return "" if user_id == context.bot.id: message.reply_text("I'm not gonna BAN myself, are you crazy or wot?") 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#TEMP BANNED" "\n<b>Admin:</b> {}" "\n<b>User:</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), member.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(chat.id, BAN_STICKER) # banhammer marie # sticker message.reply_text( "Banned! User will be banned for {}.".format(time_val) ) return log except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text( "Goodbye.. we'll meet after {}.".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 temp_ban(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text(tld(chat.id, "You don't seem to be referring to a person.")) return "" try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text(tld(chat.id, "I can't seem to find this person")) return "" else: raise if is_user_ban_protected(chat, user_id, member): message.reply_text(tld(chat.id, "This person is ban protected, meaning that you cannot ban this person!")) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "I'm not gonna BAN myself, are you crazy?")) return "" if not reason: message.reply_text(tld(chat.id, "You haven't specified a time to ban this person 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#TEMP BANNED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</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), member.user.id, time_val) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: chat.kick_member(user_id, until_date=bantime) keyboard = [] bot.send_sticker(update.effective_chat.id, BAN_STICKER) reply = "{} has been temporarily banned for {}!".format(mention_html(member.user.id, member.user.first_name),time_val) message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) return log except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie sticker message.reply_text(tld(chat.id, "Banned! Person will be banned for {}.").format(time_val), quote=False) return log else: LOGGER.warning(update) LOGGER.exception("ERROR banning person %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) message.reply_text(tld(chat.id, "Banned!")) return ""
def temp_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, 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 mute admins...") return "" if user_id == context.bot.id: message.reply_text("I'm not gonna MUTE myself, are you crazy?") return "" if not reason: message.reply_text( "You haven't specified a time to mute 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 MUTED" "\n<b>Admin:</b> {}" "\n<b>User:</b> {}" "\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), 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, until_date=mutetime, permissions=ChatPermissions(can_send_messages=False), ) message.reply_text("shut up! 🤐 Taped for {}!".format(time_val)) return log else: message.reply_text("This user is already muted.") except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text("shut up! 🤐 Taped for {}!".format(time_val), 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 mute that user.") return ""
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 person.") 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. Earth That is my price!" ) 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 person 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 person 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 person is already gbanned, but had no reason set; I've gone and updated it!" ) return ok123 = mention_html(user_chat.id, user_chat.first_name) text12 = f"*⚡️Another Bitch Goes Off⚡️* RIP {ok123}." update.effective_message.reply_text(text12, 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), 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) text13 = f"Successfully gbanned {ok123} 🙂 'He Deserve This'." update.effective_message.reply_text(text13, parse_mode=ParseMode.HTML)
def fed_ban(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) if not fed_id: update.effective_message.reply_text( tld(chat.id, "This group is not in any federation!")) return info = sql.get_fed_info(fed_id) OW = bot.get_chat(info.owner_id) HAHA = OW.id FEDADMIN = sql.all_fed_users(fed_id) FEDADMIN.append(int(HAHA)) if is_user_fed_admin(fed_id, user.id) == False: update.effective_message.reply_text( tld(chat.id, "Only fed admins can do this!")) return message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) fban = sql.get_fban_user(fed_id, user_id) if not fban == False: update.effective_message.reply_text( tld(chat.id, "*Cough* This user is already fbanned!")) return if not user_id: message.reply_text( tld(chat.id, "You don't seem to be referring to a user.")) return if user_id == bot.id: message.reply_text( tld( chat.id, "You can't fban me, better hit your head against the wall, it's more fun." )) return if is_user_fed_owner(fed_id, user_id) == True: message.reply_text( tld(chat.id, "Why you are trying to fban the federation owner?")) return if is_user_fed_admin(fed_id, user_id) == True: message.reply_text( tld(chat.id, "Why so serious trying to fban the federation admin?")) return if user_id == OWNER_ID: message.reply_text( tld(chat.id, "I'm not fbanning my master, That's pretty dumb idea!")) return if int(user_id) in SUDO_USERS: message.reply_text(tld(chat.id, "I'm not fbanning the bot sudoers!")) return if int(user_id) in WHITELIST_USERS: message.reply_text( tld(chat.id, "This person is whitelisted from being fbanned!")) return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text(tld(chat.id, "That's not a user!")) return ok123 = mention_html(user_chat.id, user_chat.first_name) ok1234 = info.fed_name text12 = f"Beginning federation ban of {ok123} in {ok1234}." update.effective_message.reply_text(text12, parse_mode=ParseMode.HTML) if reason == "": reason = "No Reason." x = sql.fban_user(fed_id, user_id, reason) if not x: message.reply_text( "Failed to federation ban! Probably this bug is not fixed yet due to the developer is lazy as f**k." ) return h = sql.all_fed_chats(fed_id) for O in h: try: bot.kick_chat_member(O, user_id) #text = tld(chat.id, "I should fban {}, but it's only test fban, right? So i let him live.").format(O) text = "Fbanning {}".format(user_id) #message.reply_text(text) except BadRequest as excp: if excp.message in FBAN_ERRORS: pass else: message.reply_text( tld(chat.id, "Could not fban due to: {}").format(excp.message)) return except TelegramError: pass send_to_list(bot, FEDADMIN, "<b>New FedBan</b>" \ "\n<b>Fed:</b> {}" \ "\n<b>FedAdmin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(info.fed_name, mention_html(user.id, user.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason), html=True) text13 = f"Chu {ok123} Sucessfully Fbanned in {ok1234} Fed." update.effective_message.reply_text(text13, parse_mode=ParseMode.HTML)
def runban(bot: Bot, update: Update, args: List[str]): message = update.effective_message 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 = 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, bot.id) or not chat.get_member( 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 == bot.id: message.reply_text("I'm not gonna UNBAN myself, I'm an admin there!") return try: chat.unban_member(user_id) message.reply_text("Yep, this user can join that chat!") 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.")
def runmute(bot: Bot, update: Update, args: List[str]): message = update.effective_message 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 = 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, bot.id) or not chat.get_member( 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 == bot.id: message.reply_text("I'm not gonna UNMUTE myself, I'm an admin there!") return try: 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) message.reply_text("Yep, this user can talk in that chat!") 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 rban(bot: Bot, update: Update, args: List[str]): message = update.effective_message 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 = 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, bot.id) or not chat.get_member( 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 == bot.id: message.reply_text("I'm not gonna BAN myself, are you crazy?") return try: chat.kick_member(user_id) message.reply_text("Banned from chat!") 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.")