Change delete_scores to a slash command.

This commit is contained in:
alwayscompiling
2022-08-08 22:07:12 -04:00
parent ffefd08761
commit 0acfa77492
+24 -15
View File
@@ -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())