From 6147263647f48db672fac154e29f018f660ab280 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Sat, 13 Aug 2022 20:23:56 -0400 Subject: [PATCH] Add UpdateUsernameVerify view to MessageManagementCog. --- cogs/commands/__init__.py | 21 ++++++++++++------- cogs/commands/data_management.py | 19 +++++++++++++---- cogs/commands/message_management.py | 2 +- cogs/commands/settings_management.py | 2 +- cogs/commands/views/update_username_verify.py | 4 ++-- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/cogs/commands/__init__.py b/cogs/commands/__init__.py index dbab5e5..d383dad 100644 --- a/cogs/commands/__init__.py +++ b/cogs/commands/__init__.py @@ -1,18 +1,23 @@ """ -Cog loader. Adds all command classes as cogs to the bot. +Cog loader. Adds all command cogs to the bot. """ from nextcord.ext import commands # Command classes -from .message_management import MessageManagement -from .settings_management import SettingsManagement -from .data_management import DataManagement +from .message_management import MessageManagementCog +from .settings_management import SettingsManagementCog +from .data_management import DataManagementCog + +# Views for commands +from .views.update_username_verify import UpdateUsernameVerifyView # 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 all command classes to bot.""" - bot.add_cog(DataManagement()) - bot.add_cog(MessageManagement(bot)) - bot.add_cog(SettingsManagement()) + """ + Adds all command classes to bot. + """ + bot.add_cog(DataManagementCog(bot)) + bot.add_cog(MessageManagementCog(bot)) + bot.add_cog(SettingsManagementCog()) diff --git a/cogs/commands/data_management.py b/cogs/commands/data_management.py index 8aec22a..5d9be3b 100644 --- a/cogs/commands/data_management.py +++ b/cogs/commands/data_management.py @@ -6,17 +6,26 @@ from nextcord.ext import commands import nextcord from highscores import highscores_data # pylint: disable=import-error +from .views.update_username_verify import UpdateUsernameVerifyView -class DataManagement(commands.Cog, name="Table Management"): +class DataManagementCog(commands.Cog, name="Table Management"): """ Class holds commands for managing the data storage of the highscores. """ - def __init__(self): + def __init__(self, bot: commands.Bot): """ - Default constructor for DataManagement class. Does nothing. + 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.", @@ -70,6 +79,8 @@ class DataManagement(commands.Cog, name="Table Management"): 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 + content=f"Username change request from <@{interaction.user.id}>.", + embed=embed, + view=UpdateUsernameVerifyView(), ) await interaction.send("Request sent to admins for verification.", ephemeral=True) diff --git a/cogs/commands/message_management.py b/cogs/commands/message_management.py index c1dde49..fa4f7db 100644 --- a/cogs/commands/message_management.py +++ b/cogs/commands/message_management.py @@ -10,7 +10,7 @@ from highscores import highscores_data # pylint: disable=import-error from utilities.utils import send_highscore_message # pylint: disable=import-error -class MessageManagement(commands.Cog, name="Message Management"): +class MessageManagementCog(commands.Cog, name="Message Management"): """ Class holds commands for managing the messages that display highscores. """ diff --git a/cogs/commands/settings_management.py b/cogs/commands/settings_management.py index 92efa06..6d61a80 100644 --- a/cogs/commands/settings_management.py +++ b/cogs/commands/settings_management.py @@ -8,7 +8,7 @@ import nextcord from highscores import highscores_data # pylint: disable=import-error -class SettingsManagement(commands.Cog, name="Settings Management"): +class SettingsManagementCog(commands.Cog, name="Settings Management"): """ Class holds commands for managing Guild's settings. """ diff --git a/cogs/commands/views/update_username_verify.py b/cogs/commands/views/update_username_verify.py index faa7f16..0c3a94c 100644 --- a/cogs/commands/views/update_username_verify.py +++ b/cogs/commands/views/update_username_verify.py @@ -45,8 +45,8 @@ class UpdateUsernameVerifyView(nextcord.ui.View): interaction (nextcord.Interaction): Interaction with the button """ embed_content = interaction.message.embeds[0].to_dict() - old_username: str = embed_content["Old Username"] - new_username: str = embed_content["New Username"] + old_username: str = embed_content[0].value() + new_username: str = embed_content[1].value() guild = highscores_data.get_guild(interaction.guild_id)