88 lines
3.4 KiB
Python
88 lines
3.4 KiB
Python
"""
|
|
Commands for managing the tables/categories/scores for a Guild.
|
|
"""
|
|
|
|
from nextcord.ext import commands
|
|
import nextcord
|
|
|
|
from highscores import highscores_data # pylint: disable=import-error
|
|
from .views.update_username_verify import UpdateUsernameVerifyView
|
|
|
|
|
|
class DataManagementCog(commands.Cog, name="Table Management"):
|
|
"""
|
|
Class holds commands for managing the data storage of the highscores.
|
|
"""
|
|
|
|
def __init__(self, bot: commands.Bot):
|
|
"""
|
|
Default constructor for DataManagement class. Sets internal bot variable.
|
|
"""
|
|
self._bot: commands.Bot = bot
|
|
|
|
@commands.Cog.listener()
|
|
async def on_ready(self):
|
|
"""
|
|
Called when cog is loaded. Adds views required for DataManagement commands.
|
|
"""
|
|
self._bot.add_view(UpdateUsernameVerifyView())
|
|
|
|
@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):
|
|
"""
|
|
Warning: This command only works for developers.
|
|
|
|
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 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(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
|
|
)
|
|
|
|
@nextcord.slash_command(description="Request a username update. Admins must approve.")
|
|
async def update_username(
|
|
self,
|
|
interaction: nextcord.Interaction,
|
|
old_username: str = nextcord.SlashOption(
|
|
description="Username currently stored in highscores.", required=True
|
|
),
|
|
new_username: str = nextcord.SlashOption(
|
|
description="Username to update to.", required=True
|
|
),
|
|
):
|
|
"""
|
|
Creates a request to send to admins for changing a username. Uses
|
|
UpdateUsernameVerifyView to do the work.
|
|
|
|
Args:
|
|
interaction (nextcord.Interaction): Interaction that invoked the command
|
|
old_username (str): Username to replace.
|
|
new_username (str): Username to replace old with.
|
|
"""
|
|
guild = highscores_data.get_guild(interaction.guild_id)
|
|
verify_channel = interaction.guild.get_channel(guild.verification_channel)
|
|
|
|
embed: nextcord.Embed = nextcord.Embed(title="Username change request.")
|
|
embed.add_field(name="Old Username", value=old_username)
|
|
embed.add_field(name="New Username", value=new_username)
|
|
await verify_channel.send(
|
|
content=f"Username change request from <@{interaction.user.id}>.",
|
|
embed=embed,
|
|
view=UpdateUsernameVerifyView(),
|
|
)
|
|
await interaction.send("Request sent to admins for verification.", ephemeral=True)
|