From d262fdf7a46e320c34d0189104ae9434a50e47ad Mon Sep 17 00:00:00 2001 From: Choco <94597336+ChocoMeow@users.noreply.github.com> Date: Sun, 19 Feb 2023 15:21:31 +0800 Subject: [PATCH] Add alias and help to group command --- cogs/admin.py | 11 ++++++++--- cogs/playlist.py | 11 ++++++++--- view/help.py | 7 ++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cogs/admin.py b/cogs/admin.py index 653baa3..4201481 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -19,7 +19,7 @@ from function import ( get_aliases, cooldown_check ) -from view import DebugModal +from view import DebugModal, HelpView class Admin(commands.Cog, name="settings"): @@ -36,9 +36,14 @@ class Admin(commands.Cog, name="settings"): return player, settings - @commands.hybrid_group(name="settings", invoke_without_command=True) + @commands.hybrid_group(name="settings", + aliases=get_aliases("settings"), + invoke_without_command=True) async def settings(self, ctx: commands.Context): - return + view = HelpView(self.bot, ctx.author) + embed = view.build_embed(self.qualified_name) + message = await ctx.send(embed=embed, view=view) + view.response = message @settings.command(name="language", aliases=get_aliases("language")) @commands.has_permissions(manage_guild=True) diff --git a/cogs/playlist.py b/cogs/playlist.py index 0aa0d77..a4def1f 100644 --- a/cogs/playlist.py +++ b/cogs/playlist.py @@ -19,7 +19,7 @@ from function import ( ) from datetime import datetime -from view import PlaylistView, InboxView +from view import PlaylistView, InboxView, HelpView def assign_playlistId(existed: list) -> str: @@ -100,9 +100,14 @@ class Playlists(commands.Cog, name="playlist"): return [app_commands.Choice(name=p, value=p) for p in playlists if current in p] return [app_commands.Choice(name=p, value=p) for p in playlists] - @commands.hybrid_group(name="playlist", invoke_without_command=True) + @commands.hybrid_group(name="playlist", + aliases=get_aliases("playlist"), + invoke_without_command=True) async def playlist(self, ctx: commands.Context): - return + view = HelpView(self.bot, ctx.author) + embed = view.build_embed(self.qualified_name) + message = await ctx.send(embed=embed, view=view) + view.response = message @playlist.command(name="play", aliases=get_aliases("play")) @app_commands.describe( diff --git a/view/help.py b/view/help.py index 31fad05..481fcdd 100644 --- a/view/help.py +++ b/view/help.py @@ -82,7 +82,8 @@ class HelpView(discord.ui.View): return False def build_embed(self, category: str): - if category == "News": + category = category.lower() + if category == "news": embed = discord.Embed(title="Vocard Help Menu", url="https://discord.com/channels/811542332678996008/811909963718459392/1069971173116481636", color=function.embed_color) embed.add_field(name=f"Available Categories: [{2 + len(self.categorys)}]", @@ -103,11 +104,11 @@ class HelpView(discord.ui.View): embed = discord.Embed(title=f"Category: {category}", color=function.embed_color) embed.add_field(name=f"Categories: [{2 + len(self.categorys)}]", value="```py\n" + "\n".join(f"👉 {c}" if c == category else f"{i}. {c}" for i, c in enumerate(['News', 'Tutorial'] + self.categorys, start=1)) + "```", inline=True) - if category == 'Tutorial': + if category == 'tutorial': embed.description = "How can use Vocard? Some simple commands you should know now after watching this video." embed.set_image(url="https://cdn.discordapp.com/attachments/674788144931012638/917656288899514388/final_61aef3aa7836890135c6010c_669380.gif") else: - cog = [c for _, c in self.bot.cogs.items() if _.capitalize() == category][0] + cog = [c for _, c in self.bot.cogs.items() if _ == category][0] commands = [command for command in cog.walk_commands()] embed.description = cog.description