Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add help command #53

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)