From d7d0c50fefcc0579f9f2ebded4cbf930fb0ef53c Mon Sep 17 00:00:00 2001 From: Slipstreamm Date: Sat, 14 Jun 2025 12:43:05 -0600 Subject: [PATCH] refactor(oauth): Convert authentication commands to hybrid group Migrate `auth`, `deauth`, and `authstatus` commands to subcommands of a new `auth` hybrid command group. This results in commands like `auth login`, `auth logout`, and `auth status`. This change: - Improves command organization and discoverability. - Leverages Discord's built-in help system for command groups, making the custom `authhelp` command redundant. - Prepares for seamless integration with slash commands by using `commands.hybrid_group`. --- cogs/oauth_cog.py | 56 ++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/cogs/oauth_cog.py b/cogs/oauth_cog.py index 3983035..2180890 100644 --- a/cogs/oauth_cog.py +++ b/cogs/oauth_cog.py @@ -153,8 +153,17 @@ class OAuthCog(commands.Cog): # Remove the pending auth entry self.pending_auth.pop(user_id, None) - @commands.command(name="auth") - async def auth_command(self, ctx): + @commands.hybrid_group(name="auth", description="Manage Discord authentication.") + async def auth(self, ctx: commands.Context): + """Manage Discord authentication.""" + if ctx.invoked_subcommand is None: + await ctx.send_help(ctx.command) + + @auth.command( + name="login", + description="Authenticate with Discord to allow the bot to access the API on your behalf.", + ) + async def login(self, ctx: commands.Context): """Authenticate with Discord to allow the bot to access the API on your behalf.""" user_id = str(ctx.author.id) @@ -165,7 +174,7 @@ class OAuthCog(commands.Cog): is_valid, _ = await discord_oauth.validate_token(token) if is_valid: await ctx.send( - f"You are already authenticated. Use `!deauth` to revoke access or `!authstatus` to check your status." + f"You are already authenticated. Use `{ctx.prefix}auth logout` to revoke access or `{ctx.prefix}auth status` to check your status." ) return @@ -241,8 +250,10 @@ class OAuthCog(commands.Cog): f"This link will expire in 10 minutes." ) - @commands.command(name="deauth") - async def deauth_command(self, ctx): + @auth.command( + name="logout", description="Revoke the bot's access to your Discord account." + ) + async def logout(self, ctx: commands.Context): """Revoke the bot's access to your Discord account.""" user_id = str(ctx.author.id) @@ -275,8 +286,8 @@ class OAuthCog(commands.Cog): else: await ctx.send("❌ You are not currently authenticated.") - @commands.command(name="authstatus") - async def auth_status_command(self, ctx): + @auth.command(name="status", description="Check your authentication status.") + async def status(self, ctx: commands.Context): """Check your authentication status.""" user_id = str(ctx.author.id) @@ -367,38 +378,9 @@ class OAuthCog(commands.Cog): # If we get here, the user is not authenticated anywhere await ctx.send( - "❌ You are not currently authenticated. Use `!auth` to authenticate." + f"❌ You are not currently authenticated. Use `{ctx.prefix}auth login` to authenticate." ) - @commands.command(name="authhelp") - async def auth_help_command(self, ctx): - """Get help with authentication commands.""" - embed = discord.Embed( - title="Authentication Help", - description="Commands for managing Discord authentication", - color=discord.Color.blue(), - ) - - embed.add_field( - name="!auth", - value="Authenticate with Discord to allow the bot to access additional OAuth scopes", - inline=False, - ) - - embed.add_field( - name="!deauth", - value="Revoke the bot's access to your Discord account", - inline=False, - ) - - embed.add_field( - name="!authstatus", value="Check your authentication status", inline=False - ) - - embed.add_field(name="!authhelp", value="Show this help message", inline=False) - - await ctx.send(embed=embed) - async def setup(bot: commands.Bot): await bot.add_cog(OAuthCog(bot))