From 197215e82b08c44344bd8ab6d343300bb527e2e5 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 13 May 2025 19:06:22 +0530 Subject: [PATCH 1/3] Add `superusers` runtime option to default runtimeconfig in `initial_setup` The `superusers` option is a list which can contain an infinite number of Discord user IDs. Every single user ID present in this runtimeconfig option will have unrestricted access to all internal devtools commands. --- api/auth.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/auth.py b/api/auth.py index 6438066..eecae83 100644 --- a/api/auth.py +++ b/api/auth.py @@ -46,7 +46,8 @@ def initial_setup() -> Literal[0]: "ping_server_override": False, "debug_mode": False, "show_ping_on_startup": True, - "isocard_server_enabled": True + "isocard_server_enabled": True, + "superusers": [] } for key in default_runtime_option_values: if key not in runtimeconfig_db["runtime_options"]: From c693807870b0e9633b8fd7db7ea9bdc753dfe659 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 13 May 2025 19:14:45 +0530 Subject: [PATCH 2/3] Implement superusers runtime option to the devtools cog --- cogs/devtools.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cogs/devtools.py b/cogs/devtools.py index 1945124..ea699a4 100644 --- a/cogs/devtools.py +++ b/cogs/devtools.py @@ -1,6 +1,7 @@ # Imports import discord import os +from api import auth from framework.isobot.currency import CurrencyAPI from framework.isobot.db import levelling from discord import option, ApplicationContext, SlashCommandGroup @@ -16,6 +17,10 @@ # Bot Superusers List superusers = ["738290097170153472"] +def fetch_superusers() -> list: + """Fetches a list of all of the superusers' Discord IDs registered in isobot.""" + return list(auth.get_runtime_options["superusers"]) + # Commands class DevTools(commands.Cog): def __init__(self, bot): @@ -30,7 +35,7 @@ def __init__(self, bot): @option(name="user", description="Specify the user to change their balance", type=discord.User) @option(name="modifier", description="Specify the balance to modify", type=int) async def modify_balance(self, ctx: ApplicationContext, user: discord.User, modifier: int): - if str(ctx.author.id) not in superusers: return ctx.respond("This command is usable only by **developers** and **bot superusers**.", ephemeral=True) + if str(ctx.author.id) not in fetch_superusers(): return ctx.respond("This command is usable only by **developers** and **bot superusers**.", ephemeral=True) try: currency.add(user.id, modifier) await ctx.respond(f"{user.name}\'s balance has been modified by {modifier} coins.\n\n**New Balance:** {currency.get_wallet(user.id)} coins", ephemeral=True) @@ -43,7 +48,7 @@ async def modify_balance(self, ctx: ApplicationContext, user: discord.User, modi @option(name="user", description="Who's rank do you want to edit?", type=discord.User) @option(name="new_rank", description="The new rank you want to set for the user", type=int) async def edit_rank(self, ctx: ApplicationContext, user: discord.User, new_rank: int): - if str(ctx.author.id) not in superusers: return await ctx.respond("This command is usable only by **developers** and **bot superusers**.", ephemeral=True) + if str(ctx.author.id) not in fetch_superusers(): return await ctx.respond("This command is usable only by **developers** and **bot superusers**.", ephemeral=True) try: levelling.set_level(user.id, new_rank) await ctx.respond(f"{user.display_name}\'s rank successfully edited. `New Rank: {levelling.get_level(user.id)}`") @@ -56,7 +61,7 @@ async def edit_rank(self, ctx: ApplicationContext, user: discord.User, new_rank: @option(name="user", description="Who's rank do you want to edit?", type=discord.User) @option(name="new_xp", description="The new xp count you want to set for the user", type=int) async def edit_xp(self, ctx: ApplicationContext, user: discord.User, new_xp: int): - if str(ctx.author.id) not in superusers: return await ctx.respond("This command is usable only by **developers** and **bot superusers**.", ephemeral=True) + if str(ctx.author.id) not in fetch_superusers(): return await ctx.respond("This command is usable only by **developers** and **bot superusers**.", ephemeral=True) try: levelling.set_xp(user.id, new_xp) await ctx.respond(f"{user.display_name}\'s XP count successfully edited. `New XP: {levelling.get_xp(user.id)}`") From b01116ec74ac0313c03c7f96c27615cc165bf23a Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 13 May 2025 19:16:50 +0530 Subject: [PATCH 3/3] Remove a little bit of debug code --- cogs/devtools.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/cogs/devtools.py b/cogs/devtools.py index ea699a4..9b6483c 100644 --- a/cogs/devtools.py +++ b/cogs/devtools.py @@ -15,8 +15,6 @@ levelling = levelling.Levelling() # Bot Superusers List -superusers = ["738290097170153472"] - def fetch_superusers() -> list: """Fetches a list of all of the superusers' Discord IDs registered in isobot.""" return list(auth.get_runtime_options["superusers"])