From f13bb90db951aeb924a4c19608d00003259768d2 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 9 Apr 2025 10:29:15 +0530 Subject: [PATCH] Move all of the DevTools commands to a new cog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This update has also moved all of the DevTools commands to a new slash command group, to make finding the commands easier. (only developers will understand 🤫) --- cogs/devtools.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++ cogs/economy.py | 13 --------- cogs/levelling.py | 26 ------------------ main.py | 1 + 4 files changed, 69 insertions(+), 39 deletions(-) create mode 100644 cogs/devtools.py diff --git a/cogs/devtools.py b/cogs/devtools.py new file mode 100644 index 0000000..1945124 --- /dev/null +++ b/cogs/devtools.py @@ -0,0 +1,68 @@ +# Imports +import discord +import os +from framework.isobot.currency import CurrencyAPI +from framework.isobot.db import levelling +from discord import option, ApplicationContext, SlashCommandGroup +from discord.ext import commands + +# Variables +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + +# Framework Module Initialization +currency = CurrencyAPI(f"{client_data_dir}/database/currency.json", f"{client_data_dir}/logs/currency.log") +levelling = levelling.Levelling() + +# Bot Superusers List +superusers = ["738290097170153472"] + +# Commands +class DevTools(commands.Cog): + def __init__(self, bot): + self.bot = bot + + devtools = SlashCommandGroup("devtools", "Developer-only configuration commands for the bot.") + + @devtools.command( + name='modify_balance', + description="Modifies user balance (Normal Digit: Adds Balance; Negative Digit: Removes Balance)" + ) + @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) + 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) + except KeyError: await ctx.respond("That user doesn't exist in the database.", ephemeral=True) + + @devtools.command( + name="edit_rank", + description="Edits a user's rank." + ) + @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) + 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)}`") + except KeyError: return await ctx.respond("That user isn't indexed yet.", ephemeral=True) + + @devtools.commands( + name="edit_xp", + description="Edits a user's XP." + ) + @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) + 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)}`") + except KeyError: return await ctx.respond("That user isn't indexed yet.", ephemeral=True) + + +# Initialization +def setup(bot): + bot.add_cog(DevTools(bot)) diff --git a/cogs/economy.py b/cogs/economy.py index dc09c06..8435a22 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -399,19 +399,6 @@ async def gift(self, ctx: ApplicationContext, user:discord.User, item:str, amoun utils.logger.error(e) await ctx.respond(f"wtf is {item}?") - @commands.slash_command( - name='modify_balance', - description="Modifies user balance (Normal Digit: Adds Balance; Negative Digit: Removes Balance)" - ) - @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 ctx.author.id != 738290097170153472: return ctx.respond("Sorry, but this command is only for my developer's use.", 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) - except KeyError: await ctx.respond("That user doesn't exist in the database.", ephemeral=True) - @commands.slash_command( name='give', description='Gives any amount of cash to someone else' diff --git a/cogs/levelling.py b/cogs/levelling.py index ae1e145..3344ef2 100644 --- a/cogs/levelling.py +++ b/cogs/levelling.py @@ -36,32 +36,6 @@ async def rank(self, ctx: ApplicationContext, user: discord.User=None): await ctx.respond(embed=localembed) except KeyError: return await ctx.respond("Looks like that user isn't indexed yet. Try again later.", ephemeral=True) - @commands.slash_command( - name="edit_rank", - description="Edits a user's rank. (DEV ONLY)" - ) - @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 ctx.author.id != 738290097170153472: return await ctx.respond("This command isn't for you.", 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)}`") - except KeyError: return await ctx.respond("That user isn't indexed yet.", ephemeral=True) - - @commands.slash_command( - name="edit_xp", - description="Edits a user's XP. (DEV ONLY)" - ) - @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 ctx.author.id != 738290097170153472: return await ctx.respond("This command isn't for you.", 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)}`") - except KeyError: return await ctx.respond("That user isn't indexed yet.", ephemeral=True) - @commands.slash_command( name="leaderboard_levels", description="View the global leaderboard for user levelling ranks." diff --git a/main.py b/main.py index f2e5d32..23b23a5 100644 --- a/main.py +++ b/main.py @@ -620,6 +620,7 @@ async def credits(ctx: ApplicationContext): "fun", "utils", "afk", + "devtools", # "osu", Disabled due to ossapi library metadata issues. (will probably remove osu cog anyway, because cog code is outdated with ossapi library) "weather", "isocard"