def sudodemote(bot: Bot, update: Update, args: List[str]): message = update.effective_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 "" if int(user_id) == OWNER_ID: message.reply_text( "The specified user is my owner! I won't remove him from SUDO_USERS list!" ) return "" if user_id not in SUDO_USERS: message.reply_text("{} is not a sudo user".format(user_id)) return "" users = [line.rstrip('\n') for line in open("sudo_users.txt")] with open("sudo_users.txt", "w") as file: for user in users: if not int(user) == user_id: file.write(str(user) + "\n") SUDO_USERS.remove(user_id) message.reply_text("Succefully removed from SUDO user list!") return ""
def sudopromote(bot: Bot, update: Update, args: List[str]): message = update.effective_message banner = update.effective_user user_id = extract_user(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return "" if int(user_id) == OWNER_ID: message.reply_text( "The specified user is my owner! No need add him to SUDO_USERS list!" ) return "" if int(user_id) in SUDO_USERS: message.reply_text("The user is already a sudo user.") return "" with open("sudo_users.txt", "a") as file: file.write(str(user_id) + "\n") SUDO_USERS.append(user_id) message.reply_text("Succefully added to SUDO user list!") return ""
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, Demoting to SUDO." data['sudos'].remove(user_id) SUDO_USERS.remove(user_id) if user_id in SUPPORT_USERS: rt += "This user is already a SUPPORT, Demoting to SUPPORT" data['supports'].remove(user_id) SUPPORT_USERS.remove(user_id) if user_id in WHITELIST_USERS: message.reply_text("This user is already a WHITELIST 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 Whitelist 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 addsudo(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat user_id = extract_user(message, args) user_member = bot.getChat(user_id) rt = "" reply = check_user_id(user_id, bot) if reply: message.reply_text(reply) return "" with open(ALLUKA_FAMILY_LIST, 'r') as infile: data = json.load(infile) if user_id in SUDO_USERS: message.reply_text("This member is already my SUDO.") return "" if user_id in SUPPORT_USERS: rt += "This user is already a SUPPORT USER." data['supports'].remove(user_id) SUPPORT_USERS.remove(user_id) if user_id in WHITELIST_USERS: rt += "This user is already a WHITELIST USER." data['whitelists'].remove(user_id) WHITELIST_USERS.remove(user_id) data['sudos'].append(user_id) SUDO_USERS.append(user_id) with open(ALLUKA_FAMILY_LIST, 'w') as outfile: json.dump(data, outfile, indent=4) update.effective_message.reply_text( rt + "\nSuccessfully added this user {} to sudo!".format(user_member.first_name)) log_message = (f"#SUDO\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>User:</b> {mention_html(user_member.id, user_member.first_name)}") if chat.type != 'private': log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message
def addsupport(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat user_id = extract_user(message, args) user_member = bot.getChat(user_id) rt = "" reply = check_user_id(user_id, bot) if reply: message.reply_text(reply) return "" with open(ALLUKA_FAMILY_LIST, 'r') as infile: data = json.load(infile) if user_id in SUDO_USERS: rt += "Demoting status of this SUDO to SUPPORT" data['sudos'].remove(user_id) SUDO_USERS.remove(user_id) if user_id in SUPPORT_USERS: message.reply_text("This user is already a SUDO.") return "" if user_id in WHITELIST_USERS: rt += "Promoting Disaster level from WHITELIST USER to SUPPORT USER" data['whitelists'].remove(user_id) WHITELIST_USERS.remove(user_id) data['supports'].append(user_id) SUPPORT_USERS.append(user_id) with open(ALLUKA_FAMILY_LIST, 'w') as outfile: json.dump(data, outfile, indent=4) update.effective_message.reply_text(rt + f"\n{user_member.first_name} was added as a support user!") log_message = (f"#SUPPORT\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>User:</b> {mention_html(user_member.id, user_member.first_name)}") if chat.type != 'private': log_message = "<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message
def 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 ""