Skip to content

Commit

Permalink
patch: updated default /help to support new subcommands and subcomman…
Browse files Browse the repository at this point in the history
…d groups
  • Loading branch information
Pkmmte committed May 15, 2023
1 parent 8fe87c3 commit 72b65bf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-shoes-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roboplay/robo.js': patch
---

patch: updated default /help to support new subcommands and subcommand groups
29 changes: 25 additions & 4 deletions packages/robo/src/default/commands/help.ts
Original file line number Diff line number Diff line change
@@ -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<string, CommandEntry>,
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)'
Expand All @@ -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
})),
{
Expand Down

1 comment on commit 72b65bf

@vercel
Copy link

@vercel vercel bot commented on 72b65bf May 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.