From 0acfa77492fd954563827afb361fb2516d4bef48 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Mon, 8 Aug 2022 22:06:28 -0400 Subject: [PATCH] Change delete_scores to a slash command. --- cogs/delete_scores/__init__.py | 39 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/cogs/delete_scores/__init__.py b/cogs/delete_scores/__init__.py index a08b077..9c417b5 100644 --- a/cogs/delete_scores/__init__.py +++ b/cogs/delete_scores/__init__.py @@ -2,8 +2,8 @@ Bot command for deleting the guild's scores. """ -from nextcord import Embed from nextcord.ext import commands +import nextcord from highscores import highscores_data # pylint: disable=import-error @@ -14,29 +14,38 @@ class DeleteScores(commands.Cog, name="Delete Scores"): Deletes this guild's scores. """ - def __init__(self, bot: commands.Bot): - self.bot = bot + def __init__(self): + """ + Default constructor for DeleteScores class. Does nothing. + """ - @commands.command(name="delete-scores") - @commands.has_permissions(administrator=True) - async def delete_scores(self, ctx: commands.Context): - """A command which deletes all scores for this guild. - Usage: - ``` - ?delete_scores - ``` + @nextcord.slash_command( + description="Deletes all scores for this guild. Used for testing.", + default_member_permissions=nextcord.Permissions(administrator=True), + ) + async def delete_scores(self, interaction: nextcord.Interaction): + """ + A command which deletes all scores in all tables for this guild. + Command limits to admins to prevent devs from usings on non-test servers. """ # only allow AlwaysCompiling to use. # If you are a developer and want to use command, can add name to list - if ctx.author.id == 206602713511886849: - for table in highscores_data.get_guild(ctx.guild.id).tables: + if interaction.user.id == 206602713511886849: + for table in highscores_data.get_guild(interaction.guild_id).tables: for category in table.categories: category.clear() - highscores_data.save_guild_data(highscores_data.get_guild(ctx.guild.id)) + highscores_data.save_guild_data(highscores_data.get_guild(interaction.guild_id)) + await interaction.response.send_message( + f"Cleared score data for {interaction.guild.name}.", ephemeral=True + ) + else: + await interaction.response.send_message( + "You shouldn't be using this message.", ephemeral=True + ) # This function will be called when this extension is loaded. # It is necessary to add these functions to the bot. def setup(bot: commands.Bot): """Adds function to bot""" - bot.add_cog(DeleteScores(bot)) + bot.add_cog(DeleteScores())