Skip to content

Commit

Permalink
Add help command (#53)
Browse files Browse the repository at this point in the history
Co-authored-by: nova <novanai.dev@gmail.com>
  • Loading branch information
aydenjahola and novanai authored Jan 14, 2025
1 parent d0a1d5f commit 3ea8fc8
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/extensions/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import hikari
import arc
import itertools
import collections

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


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."""

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

for plugin_, commands in plugin_commands.items():
embed.add_field(
name=plugin_ or "No plugin", value="\n".join(commands), inline=False
)

await ctx.respond(embed=embed)


@arc.loader
def load(client: arc.GatewayClient) -> None:
client.add_plugin(plugin)

0 comments on commit 3ea8fc8

Please sign in to comment.