Skip to content

Commit

Permalink
Update help command format
Browse files Browse the repository at this point in the history
  • Loading branch information
novanai committed Nov 20, 2024
1 parent f473897 commit c774c84
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/extensions/help.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
import hikari
import arc
import itertools
import collections

plugin = arc.GatewayPlugin(name="Help Command Plugin")


def gather_commands(client: arc.GatewayClient):
command_list = []
for command in itertools.chain(client.walk_commands(hikari.CommandType.SLASH)):
command_list.append(
{
"name": command.name,
"description": command.description or "No description provided.",
}
)
return command_list
def gather_commands() -> dict[str | None, list[str]]:
plugin_commands: dict[str | None, list[str]] = collections.defaultdict(list)

for plugin_, commands in itertools.groupby(
plugin.client.walk_commands(hikari.CommandType.SLASH),
key=lambda cmd: cmd.plugin,
):
for cmd in commands:
if not isinstance(cmd, (arc.SlashCommand, arc.SlashSubCommand)):
continue

plugin_commands[plugin_.name if plugin_ else None].append(
f"{cmd.make_mention()} - {cmd.description}"
)

return plugin_commands


@plugin.include
@arc.slash_command("help", "Displays a list of all commands.")
async def help_command(ctx: arc.GatewayContext) -> None:
"""Displays a simple list of all bot commands."""

commands = gather_commands(ctx.client)
plugin_commands = gather_commands()
embed = hikari.Embed(title="Bot Commands", color=0x00FF00)

for command in commands:
for plugin_, commands in plugin_commands.items():
embed.add_field(
name=f"/{command['name']}", value=command["description"], inline=False
name=plugin_ or "No plugin", value="\n".join(commands), inline=False
)

await ctx.respond(embed=embed)
Expand Down

0 comments on commit c774c84

Please sign in to comment.