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`.
This commit is contained in:
parent
d64da1aa9a
commit
d7d0c50fef
@ -153,8 +153,17 @@ class OAuthCog(commands.Cog):
|
|||||||
# Remove the pending auth entry
|
# Remove the pending auth entry
|
||||||
self.pending_auth.pop(user_id, None)
|
self.pending_auth.pop(user_id, None)
|
||||||
|
|
||||||
@commands.command(name="auth")
|
@commands.hybrid_group(name="auth", description="Manage Discord authentication.")
|
||||||
async def auth_command(self, ctx):
|
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."""
|
"""Authenticate with Discord to allow the bot to access the API on your behalf."""
|
||||||
user_id = str(ctx.author.id)
|
user_id = str(ctx.author.id)
|
||||||
|
|
||||||
@ -165,7 +174,7 @@ class OAuthCog(commands.Cog):
|
|||||||
is_valid, _ = await discord_oauth.validate_token(token)
|
is_valid, _ = await discord_oauth.validate_token(token)
|
||||||
if is_valid:
|
if is_valid:
|
||||||
await ctx.send(
|
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
|
return
|
||||||
|
|
||||||
@ -241,8 +250,10 @@ class OAuthCog(commands.Cog):
|
|||||||
f"This link will expire in 10 minutes."
|
f"This link will expire in 10 minutes."
|
||||||
)
|
)
|
||||||
|
|
||||||
@commands.command(name="deauth")
|
@auth.command(
|
||||||
async def deauth_command(self, ctx):
|
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."""
|
"""Revoke the bot's access to your Discord account."""
|
||||||
user_id = str(ctx.author.id)
|
user_id = str(ctx.author.id)
|
||||||
|
|
||||||
@ -275,8 +286,8 @@ class OAuthCog(commands.Cog):
|
|||||||
else:
|
else:
|
||||||
await ctx.send("❌ You are not currently authenticated.")
|
await ctx.send("❌ You are not currently authenticated.")
|
||||||
|
|
||||||
@commands.command(name="authstatus")
|
@auth.command(name="status", description="Check your authentication status.")
|
||||||
async def auth_status_command(self, ctx):
|
async def status(self, ctx: commands.Context):
|
||||||
"""Check your authentication status."""
|
"""Check your authentication status."""
|
||||||
user_id = str(ctx.author.id)
|
user_id = str(ctx.author.id)
|
||||||
|
|
||||||
@ -367,38 +378,9 @@ class OAuthCog(commands.Cog):
|
|||||||
|
|
||||||
# If we get here, the user is not authenticated anywhere
|
# If we get here, the user is not authenticated anywhere
|
||||||
await ctx.send(
|
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):
|
async def setup(bot: commands.Bot):
|
||||||
await bot.add_cog(OAuthCog(bot))
|
await bot.add_cog(OAuthCog(bot))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user