From 72b65bfd6aefdd859148e44e9c79cbcab669a9b6 Mon Sep 17 00:00:00 2001 From: Pkmmte Xeleon Date: Sun, 14 May 2023 22:15:18 -0700 Subject: [PATCH] patch: updated default /help to support new subcommands and subcommand groups --- .changeset/funny-shoes-chew.md | 5 ++++ packages/robo/src/default/commands/help.ts | 29 +++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 .changeset/funny-shoes-chew.md diff --git a/.changeset/funny-shoes-chew.md b/.changeset/funny-shoes-chew.md new file mode 100644 index 000000000..0753fa4d7 --- /dev/null +++ b/.changeset/funny-shoes-chew.md @@ -0,0 +1,5 @@ +--- +'@roboplay/robo.js': patch +--- + +patch: updated default /help to support new subcommands and subcommand groups diff --git a/packages/robo/src/default/commands/help.ts b/packages/robo/src/default/commands/help.ts index 93446387e..6dcf85dd1 100644 --- a/packages/robo/src/default/commands/help.ts +++ b/packages/robo/src/default/commands/help.ts @@ -1,13 +1,34 @@ // @ts-expect-error - This is valid once command file is parsed import { getManifest } from '@roboplay/robo.js' -import type { CommandConfig } from '../../types/commands.js' +import type { CommandConfig, CommandEntry } from '../../types/commands.js' export const config: CommandConfig = { description: 'Displays a list of commands.' } +function getInnermostCommands( + commands: Record, + prefix = '' +): { key: string; command: CommandEntry }[] { + let innermostCommands: { key: string; command: CommandEntry }[] = [] + const keys = Object.keys(commands) + + for (const key of keys) { + if (commands[key].subcommands) { + const subInnermostCommands = getInnermostCommands(commands[key].subcommands, prefix ? `${prefix} ${key}` : key) + innermostCommands = innermostCommands.concat(subInnermostCommands) + } else { + const commandPath = prefix ? `${prefix} ${key}` : key + innermostCommands.push({ key: commandPath, command: commands[key] }) + } + } + + return innermostCommands +} + export default () => { const manifest = getManifest() + const commands = getInnermostCommands(manifest.commands) const poweredBy = process.env.ROBOPLAY_HOST ? 'Powered by [**RoboPlay** ✨](https://roboplay.dev)' : 'Powered by [**Robo.js**](https://roboplay.dev/robo)' @@ -16,9 +37,9 @@ export default () => { embeds: [ { fields: [ - ...Object.keys(manifest.commands).map((command) => ({ - name: `/${command}`, - value: manifest.commands[command].description || 'No description provided.', + ...commands.map(({ key, command }) => ({ + name: `/${key}`, + value: command.description || 'No description provided.', inline: false })), {