def promote(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] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": exit(1) if not chatD.get_member(bot.id).can_promote_members: update.effective_message.reply_text( "I can't promote/demote people here! " "Make sure I'm admin and can appoint new admins.") exit(1) user_id = extract_user(message, args) if not user_id: message.reply_text( tld(chat.id, "You don't seem to be referring to a user.")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'administrator' or user_member.status == 'creator': message.reply_text( tld(chat.id, "How am I meant to promote someone that's already an admin?")) return "" if user_id == bot.id: message.reply_text( tld(chat.id, "I can't promote myself! Get an admin to do it for me.")) return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chatD.get_member(bot.id) bot.promoteChatMember( chatD.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, can_promote_members=bot_member.can_promote_members) message.reply_text(tld(chat.id, f"Successfully promoted in *{chatD.title}*!"), parse_mode=ParseMode.MARKDOWN) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#PROMOTED" \ f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
def addwhitelist(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(ELEVATED_USERS_FILE, '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(ELEVATED_USERS_FILE, '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 slap(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message if msg.from_user.username: curr_user = "******" + escape_markdown(msg.from_user.username) else: curr_user = "******".format(msg.from_user.first_name, msg.from_user.id) user_id = extract_user(update.effective_message, args) if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user if slapped_user.username: user2 = "@" + escape_markdown(slapped_user.username) else: user2 = "[{}](tg://user?id={})".format(slapped_user.first_name, slapped_user.id) # if no target found, bot targets the sender else: user1 = "[{}](tg://user?id={})".format(bot.first_name, bot.id) user2 = curr_user temp = random.choice(tld(chat.id, "SLAP_TEMPLATES-K")) item = random.choice(tld(chat.id, "ITEMS-K")) hit = random.choice(tld(chat.id, "HIT-K")) throw = random.choice(tld(chat.id, "THROW-K")) itemp = random.choice(tld(chat.id, "ITEMP-K")) itemr = random.choice(tld(chat.id, "ITEMR-K")) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw, itemp=itemp, itemr=itemr) #user1=user1, user2=user2, item=item_ru, hits=hit_ru, throws=throw_ru, itemp=itemp_ru, itemr=itemr_ru reply_text(repl, parse_mode=ParseMode.MARKDOWN)
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[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 "<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 user_join_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] fed_id = sql.get_fed_id(chat.id) if is_user_fed_owner(fed_id, user.id): user_id = extract_user(msg, args) if user_id: user = 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 cannot extract users from this message") return else: LOGGER.warning('error') getuser = sql.search_user_in_fed(fed_id, user_id) fed_id = sql.get_fed_id(chat.id) info = sql.get_fed_info(fed_id) get_owner = eval(info['fusers'])['owner'] get_owner = bot.get_chat(get_owner).id if user_id == get_owner: update.effective_message.reply_text("Why are you trying to promote a federation owner?") return if getuser: update.effective_message.reply_text("I cannot promote users who are already federation admins! But I can remove them if you want!") return if user_id == bot.id: update.effective_message.reply_text("I already am a federation admin in all federations!") return res = sql.user_join_fed(fed_id, user_id) if res: update.effective_message.reply_text("Successfully Promoted!") else: update.effective_message.reply_text("Failed to promote!") else: update.effective_message.reply_text("Only federation owners can do this!")
def removesudo(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(ELEVATED_USERS_FILE, '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(ELEVATED_USERS_FILE, '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 user_demote_fed(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 is_user_fed_owner(fed_id, user.id): msg = update.effective_message # type: Optional[Message] user_id = extract_user(msg, args) if user_id: user = 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 cannot extract users from this message") return else: LOGGER.warning('error') if user_id == bot.id: update.effective_message.reply_text("Are you trying to demote me as a federation admin? Do you think I am stupid?") return if sql.search_user_in_fed(fed_id, user_id) == False: update.effective_message.reply_text("I cannot demote people who are not federation admins!") return res = sql.user_demote_fed(fed_id, user_id) if res == True: update.effective_message.reply_text("Get out of here!") else: update.effective_message.reply_text("Demotion failed!") else: update.effective_message.reply_text("Only federation owners can do this!") return
def about_bio(bot: Bot, update: Update, args: List[str]): spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return message = update.effective_message # type: Optional[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("{} hasn't had a message set about themselves yet!".format(username)) else: update.effective_message.reply_text("You haven't had a bio set about yourself yet!")
def warns(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[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 = "This user has {}/{} warnings, for the following reasons:".format(num_warns, limit) for reason in reasons: text += "\n - {}".format(reason) 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 unbl_user(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user 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 = "#UNBLACKLIST" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(mention_html(user.id, user.first_name), 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 get_id(bot: Bot, update: Update, args: List[str]): spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return user_id = extract_user(update.effective_message, args) chat = update.effective_chat # type: Optional[Chat] 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(tld( chat.id, "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 = bot.get_chat(user_id) update.effective_message.reply_text(tld( chat.id, "{}'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(tld( chat.id, "Your id is `{}`.").format(chat.id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text(tld( chat.id, "This group's id is `{}`.").format(chat.id), parse_mode=ParseMode.MARKDOWN)
def media(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 = extract_user(message, args) if not user_id: message.reply_text( tld( chat.id, "You'll need to either give me a username to unrestrict, or reply to someone to be unrestricted." )) return "" member = chatD.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( tld( chat.id, "This user already has the rights to send anything in {}." ).format(chatD.title)) else: bot.restrict_chat_member(chatD.id, int(user_id), can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True) keyboard = [] reply = tld(chat.id, "Yep, {} can send media again in {}!").format( mention_html(member.user.id, member.user.first_name), chatD.title) message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) return "<b>{}:</b>" \ "\n#UNRESTRICTED" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chatD.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id) else: message.reply_text( tld( chat.id, "This user isn't even in the chat, unrestricting them won't make them send anything than they " "already do!")) return ""
def 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 = extract_user(message, args) if not user_id: message.reply_text( tld( chat.id, "You'll need to either give me a username to restrict, or reply to someone to be restricted." )) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "I'm not restricting myself!")) return "" member = chatD.get_member(int(user_id)) if member: if is_user_admin(chatD, user_id, member=member): message.reply_text(tld(chat.id, "Afraid I can't restrict admins!")) elif member.can_send_messages is None or member.can_send_messages: bot.restrict_chat_member(chatD.id, user_id, can_send_messages=True, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False) keyboard = [] reply = tld(chat.id, "{} is restricted from sending media in {}!").format( mention_html(member.user.id, member.user.first_name), chatD.title) message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) return "<b>{}:</b>" \ "\n#RESTRICTED" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chatD.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id) else: message.reply_text( tld(chat.id, "This user is already restricted in {}!")) else: message.reply_text( tld(chat.id, "This user isn't in the {}!").format(chatD.title)) return ""
def mute(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 = extract_user(message, args) if not user_id: message.reply_text( tld( chat.id, "You'll need to either give me a username to mute, or reply to someone to be muted." )) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "I'm not muting myself!")) return "" member = chatD.get_member(int(user_id)) if member: if user_id in SUDO_USERS: message.reply_text( tld( chat.id, "No! I'm not muting bot sudoers! That would be a pretty dumb idea." )) elif is_user_admin(chatD, user_id, member=member): message.reply_text( tld( chat.id, "No! I'm not muting chat administrator! That would be a pretty dumb idea." )) elif member.can_send_messages is None or member.can_send_messages: bot.restrict_chat_member(chatD.id, user_id, can_send_messages=False) keyboard = [] reply = tld(chat.id, "{} is muted in {}!").format( mention_html(member.user.id, member.user.first_name), chatD.title) message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) return "<b>{}:</b>" \ "\n#MUTE" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chatD.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name)) else: message.reply_text( tld(chat.id, "This user is already muted in {}!").format(chatD.title)) else: message.reply_text( tld(chat.id, "This user isn't in the {}!").format(chatD.title)) return ""
def info(bot: Bot, update: Update, args: List[str]): msg = update.effective_message # type: Optional[Message] user_id = extract_user(update.effective_message, args) chat = update.effective_chat # type: Optional[Chat] if user_id: user = 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(tld(chat.id, "I can't extract a user from this.")) return else: return text = tld(chat.id, "<b>User info</b>:") text += "\nID: <code>{}</code>".format(user.id) text += tld(chat.id, "\nFirst Name: {}").format(html.escape(user.first_name)) if user.last_name: text += tld(chat.id, "\nLast Name: {}").format(html.escape(user.last_name)) if user.username: text += tld(chat.id, "\nUsername: @{}").format(html.escape(user.username)) text += tld(chat.id, "\nPermanent user link: {}").format( mention_html(user.id, "link")) if user.id == OWNER_ID: text += tld( chat.id, "\n\nAy, This guy is my owner. I would never do anything against him!" ) else: if user.id in SUPPORT_USERS: text += tld(chat.id, "\nThis person is one of my support users! " \ "Not quite a sudo user or a developer, but can still gban you off the map.") if user.id in SUDO_USERS: text += tld(chat.id, "\nThis person is one of my sudo users !" \ "Don't mess with them kthnxbye :)") if user.id in DEV_USERS: text += tld(chat.id, "\nThis person is one of my DEVELOPERS! " \ "They help to manage the bot and are more powerful than Sudos.") if user.id in WHITELIST_USERS: text += tld(chat.id, "\nThis person has been whitelisted! " \ "That means I'm not allowed to ban/kick them.") 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 update.effective_message.reply_text(text, parse_mode=ParseMode.HTML, disable_web_page_preview=True)
def unfban(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] fed_id = sql.get_fed_id(chat.id) if not fed_id: update.effective_message.reply_text("This group is not a part of any federation!") return info = sql.get_fed_info(fed_id) if is_user_fed_admin(fed_id, user.id) == False: update.effective_message.reply_text("Only federation admins can do this!") return user_id = extract_user(message, args) if not user_id: message.reply_text("You do not 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 fban, fbanreason = sql.get_fban_user(fed_id, user_id) if fban == False: message.reply_text("This user is not fbanned!") return banner = update.effective_user # type: Optional[User] message.reply_text("I'll give {} a second chance in this federation".format(user_chat.first_name)) chat_list = sql.all_fed_chats(fed_id) for chat in chat_list: try: member = bot.get_chat_member(chat, user_id) if member.status == 'kicked': bot.unban_chat_member(chat, user_id) """ bot.send_message(chat, "<b>Un-FedBan</b>" \ "\n<b>Federation:</b> {}" \ "\n<b>Federation Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>".format(info['fname'], mention_html(user.id, user.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id), parse_mode="HTML") """ except BadRequest as excp: if excp.message in UNFBAN_ERRORS: pass else: LOGGER.warning("Cannot remove fban on {} because: {}".format(chat, excp.message)) except TelegramError: pass try: x = sql.un_fban_user(fed_id, user_id) if not x: message.reply_text("Fban failure, this user may have been un-fedbanned!") return except: pass message.reply_text("This person is un-fbanned.") FEDADMIN = sql.all_fed_users(fed_id)
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: message.reply_text("You do not seems 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) in DEV_USERS: message.reply_text( "OHHH! Someone's trying to gkick a developer! *Grabs popcorn*") return if int(user_id) == OWNER_ID: message.reply_text( "Wow! Some's trying to gkick my owner! *Grabs Potato Chips*") return if user_id == bot.id: message.reply_text("Welp, I'm not gonna gkick myself!") return if int(user_id) in SUDO_USERS: message.reply_text("") return if int(user_id) in DEV_USERS: message.reply_text("") return chats = get_all_chats() message.reply_text("Globally kicking user @{}".format(user_chat.username)) for chat in chats: try: bot.unban_chat_member(chat.chat_id, user_id) # Unban_member = kick (and not ban) 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 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 + DEV_USERS, "{} has ungmuted user {}".format( mention_html(muter.id, muter.first_name), mention_html(user_chat.id, user_chat.first_name)), html=True) chats = get_all_chats() for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gmutes if not sql.does_chat_gban(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, "un-gmute complete!") message.reply_text("Person has been un-gmuted.")
def ungban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("That's not a user!") return if not sql.is_user_gbanned(user_id): message.reply_text("This user is not gbanned!") return banner = update.effective_user # type: Optional[User] message.reply_text("I'll give {} a second chance, globally.".format( user_chat.first_name)) send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "{} has ungbanned user {}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name)), html=True) chats = get_all_chats() for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gbans if not sql.does_chat_gban(chat_id): continue try: member = bot.get_chat_member(chat_id, user_id) if member.status == 'kicked': bot.unban_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in UNGBAN_ERRORS: pass else: message.reply_text("Could not un-gban due to: {}".format( excp.message)) bot.send_message( OWNER_ID, "Could not un-gban due to: {}".format(excp.message)) return except TelegramError: pass sql.ungban_user(user_id) send_to_list(bot, SUDO_USERS + SUPPORT_USERS + DEV_USERS, "un-gban complete!") message.reply_text("Person has been un-gbanned.")
def demote(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": exit(1) if not chatD.get_member(bot.id).can_promote_members: update.effective_message.reply_text( "I can't promote/demote people here! " "Make sure I'm admin and can appoint new admins.") exit(1) user_id = extract_user(message, args) if not user_id: message.reply_text( tld(chat.id, "You don't seem to be referring to a user.")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'creator': message.reply_text( tld(chat.id, "This person CREATED the chat, how would I demote them?")) return "" if not user_member.status == 'administrator': message.reply_text(tld(chat.id, "Can't demote what wasn't promoted!")) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "I can't demote myself!")) return "" try: bot.promoteChatMember(int(chatD.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, can_promote_members=False) message.reply_text(tld(chat.id, f"Successfully demoted in *{chatD.title}*!"), parse_mode=ParseMode.MARKDOWN) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#DEMOTED" \ f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}" except BadRequest: message.reply_text( tld( chat.id, "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 ""