def removewhitelist(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user user_id = extract_user(message, args) user_member = update.effective_chat.get_member(user_id) log_message = "" if not user_id: message.reply_text("I can't remove a chat from whitelist list!") return "" with open('{}/tg_bot/elevated_users.json'.format(os.getcwd()), 'r') as infile: data = json.load(infile) if user_id in WHITELIST_USERS: message.reply_text("Demoting to normal user") WHITELIST_USERS.remove(user_id) data['whitelists'].remove(user_id) with open('{}/tg_bot/elevated_users.json'.format(os.getcwd()), 'w') as outfile: json.dump(data, outfile, indent=4) log_message += "<b>{}:</b>" \ "\n#UNWHITELIST" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(update.effective_chat.title), mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name)) return log_message else: message.reply_text("This user is not a Wolf Disaster!") return ""
def removewhitelist(update: Update, context: CallbackContext) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat bot, args = context.bot, context.args 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 "" if user_id in WHITELIST_USERS: message.reply_text("Demoting to normal user") WHITELIST_USERS.remove(user_id) sql.remove_royal(user_id) log_message = ( f"#UNWHITELIST\n" f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n" f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}" ) if chat.type != "private": log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message else: message.reply_text("This user is not a Whitelist user!") return ""
def addsupport(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user user_id = extract_user(message, args) user_member = update.effective_chat.get_member(user_id) rt = "" with open('{}/tg_bot/elevated_users.json'.format(os.getcwd()), 'r') as infile: data = json.load(infile) if user_id in SUDO_USERS: rt += ("Demoting status of this Dragon to Demon") data['sudos'].remove(user_id) SUDO_USERS.remove(user_id) if user_id in SUPPORT_USERS: message.reply_text("This user is already a Demon ranker.") return "" if user_id in WHITELIST_USERS: rt += ("Promoting Disaster level from Wolf to Demon") data['whitelists'].remove(user_id) WHITELIST_USERS.remove(user_id) data['supports'].append(user_id) with open('{}/tg_bot/elevated_users.json'.format(os.getcwd()), 'w') as outfile: json.dump(data, outfile, indent=4) SUPPORT_USERS.append(user_id) update.effective_message.reply_text( rt + "\n{} was added as a Demon level Disaster!".format( user_member.user.first_name)) return "<b>{}:</b>" \ "\n#SUPPORT" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(update.effective_chat.title), mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name))
def removewhitelist(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat user_id = extract_user(message, args) user_member = bot.getChat(user_id) reply = check_user_id(user_id, bot) if reply: message.reply_text(reply) return "" with open(ELEVATED_USERS_FILE, 'r') as infile: data = json.load(infile) if user_id in WHITELIST_USERS: message.reply_text("Demoting to normal user") WHITELIST_USERS.remove(user_id) data['whitelists'].remove(user_id) with open(ELEVATED_USERS_FILE, 'w') as outfile: json.dump(data, outfile, indent=4) log_message = (f"#UNWHITELIST\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>User:</b> {mention_html(user_member.id, user_member.first_name)}") if chat.type != 'private': log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message else: message.reply_text("This user is not a Wolf Disaster!") return ""
def addsardegna(update: Update, context: CallbackContext) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat bot, args = context.bot, context.args 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 Sardegna." 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 Sardegna." data["supports"].remove(user_id) SUPPORT_USERS.remove(user_id) if user_id in WHITELIST_USERS: rt += "This user is already a Whitelist user, Demoting to Sardegna." data["whitelists"].remove(user_id) WHITELIST_USERS.remove(user_id) if user_id in SARDEGNA_USERS: message.reply_text("This user is already a Sardegna.") return "" data["sardegnas"].append(user_id) SARDEGNA_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 Sardegna Nation!" ) log_message = ( f"#SARDEGNA\n" f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))} \n" f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}" ) if chat.type != "private": log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message
def addtiger(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 Dragon Disaster, Demoting to Tiger." data['sudos'].remove(user_id) SUDO_USERS.remove(user_id) if user_id in SUPPORT_USERS: rt += "This user is already a Demon Disaster, Demoting to Tiger." data['supports'].remove(user_id) SUPPORT_USERS.remove(user_id) if user_id in WHITELIST_USERS: rt += "This user is already a Wolf Disaster, Demoting to Tiger." data['whitelists'].remove(user_id) WHITELIST_USERS.remove(user_id) if user_id in TIGER_USERS: message.reply_text("This user is already a Tiger.") return "" data['tigers'].append(user_id) TIGER_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 Tiger Disaster!" ) log_message = ( f"#TIGER\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(ELEVATED_USERS_FILE, "r") as infile: data = json.load(infile) if user_id in SUDO_USERS: message.reply_text("This member is already a Royal Nation") return "" if user_id in SUPPORT_USERS: rt += "Requested HA to promote a Sakura Nation to Royal." data["supports"].remove(user_id) SUPPORT_USERS.remove(user_id) if user_id in WHITELIST_USERS: rt += "Requested HA to promote a Neptunia Nation to Royal." data["whitelists"].remove(user_id) WHITELIST_USERS.remove(user_id) data["sudos"].append(user_id) SUDO_USERS.append(user_id) with open(ELEVATED_USERS_FILE, "w") as outfile: json.dump(data, outfile, indent=4) update.effective_message.reply_text( rt + "\nSuccessfully set Nation level of {} to Royal!".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( update: Update, context: CallbackContext, ) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat bot, args = context.bot, context.args 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 += "Requested Eagle Union to demote 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 Support user.") return "" if user_id in WHITELIST_USERS: rt += "Requested Eagle Union to promote this Whitelist user to Support" data["whitelists"].remove(user_id) WHITELIST_USERS.remove(user_id) data["supports"].append(user_id) SUPPORT_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"\n{user_member.first_name} was added as a Support user!" ) log_message = ( f"#SUPPORT\n" f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n" f"<b>User:</b> {mention_html(user_member.id, html.escape(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(ELEVATED_USERS_FILE, '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(ELEVATED_USERS_FILE, '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 addsudo(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user user_id = extract_user(message, args) user_member = update.effective_chat.get_member(user_id) rt, log_message = "", "" if not user_id: message.reply_text("I can't add a chat to sudo list!") return log_message with open('{}/tg_bot/elevated_users.json'.format(os.getcwd()), 'r') as infile: data = json.load(infile) if user_id in SUDO_USERS: message.reply_text("This member is already a Dragon Disaster") return log_message if user_id in SUPPORT_USERS: rt += ( "This user is already a Demon Disaster, Promoting to Dragon Disaster." ) data['supports'].remove(user_id) SUPPORT_USERS.remove(user_id) if user_id in WHITELIST_USERS: rt += ("This user is already a Wolf, Promoting to Dragon Disaster.") data['whitelists'].remove(user_id) WHITELIST_USERS.remove(user_id) data['sudos'].append(user_id) SUDO_USERS.append(user_id) with open('{}/tg_bot/elevated_users.json'.format(os.getcwd()), 'w') as outfile: json.dump(data, outfile, indent=4) update.effective_message.reply_text( rt + "\nSuccessfully set Disaster level of {} to Dragon!".format( user_member.user.first_name)) log_message += "<b>{}:</b> "\ "\n#SUDO "\ "\n<b>Admin:</b> {} "\ "\n<b>User:</b> {}".format(html.escape(update.effective_chat.title), mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name)) 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(ELEVATED_USERS_FILE, '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(ELEVATED_USERS_FILE, '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 Demon Disaster!") 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 addsardegna(update: Update, context: CallbackContext) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat bot, args = context.bot, context.args 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 "" if user_id in SUDO_USERS: rt += "This member is a Sudo user, Demoting to Sardegna." SUDO_USERS.remove(user_id) if user_id in SUPPORT_USERS: rt += "This user is already a Support user, Demoting to Sardegna." SUPPORT_USERS.remove(user_id) if user_id in WHITELIST_USERS: rt += "This user is already a Whitelist user, Demoting to Sardegna." WHITELIST_USERS.remove(user_id) if user_id in SARDEGNA_USERS: message.reply_text("This user is already a Sardegna.") return "" sql.set_royal_role(user_id, "sardegnas") SARDEGNA_USERS.append(user_id) update.effective_message.reply_text( rt + f"\nSuccessfully promoted {user_member.first_name} to a Sardegna Nation!" ) log_message = ( f"#SARDEGNA\n" f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))} \n" f"<b>User:</b> {mention_html(user_member.id, html.escape(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(update: Update, context: CallbackContext) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat bot, args = context.bot, context.args 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 "" if user_id in SUDO_USERS: message.reply_text("This member is already a Sudo user") return "" if user_id in SUPPORT_USERS: rt += "Requested Eagle Union to promote a Support user to Sudo." SUPPORT_USERS.remove(user_id) if user_id in WHITELIST_USERS: rt += "Requested Eagle Union to promote a Whitelist user to Sudo." WHITELIST_USERS.remove(user_id) # will add or update their role sql.set_royal_role(user_id, "sudos") SUDO_USERS.append(user_id) update.effective_message.reply_text( rt + "\nSuccessfully promoted {} to Sudo!".format( user_member.first_name ) ) log_message = ( f"#SUDO\n" f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n" f"<b>User:</b> {mention_html(user_member.id, html.escape(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( update: Update, context: CallbackContext, ) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat bot, args = context.bot, context.args 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 "" if user_id in SUDO_USERS: rt += "Requested Eagle Union to demote this Sudo to Support" SUDO_USERS.remove(user_id) if user_id in SUPPORT_USERS: message.reply_text("This user is already a Support user.") return "" if user_id in WHITELIST_USERS: rt += "Requested Eagle Union to promote this Whitelist user to Support" WHITELIST_USERS.remove(user_id) sql.set_royal_role(user_id, "supports") SUPPORT_USERS.append(user_id) 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, html.escape(user.first_name))}\n" f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}" ) if chat.type != "private": log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message
def removewhitelist(update: Update, context: CallbackContext) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat bot, args = context.bot, context.args 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 WHITELIST_USERS: message.reply_text("Demoting to normal user") WHITELIST_USERS.remove(user_id) data["whitelists"].remove(user_id) with open(ELEVATED_USERS_FILE, "w") as outfile: json.dump(data, outfile, indent=4) log_message = ( f"#UNWHITELIST\n" f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n" f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}" ) if chat.type != "private": log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message return log_message else: message.reply_text("This user is not a Whitelist user!") return ""