diff --git a/src/commands.ts b/src/commands.ts index 5ec6705..98133df 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -99,6 +99,22 @@ export class CommandManager { return this.getAll().filter((cmd) => !!cmd.name); } + public getGuildKeys(): Record { + return this.mergeKeys('guild_keys'); + } + + public getUserKeys(): Record { + return this.mergeKeys('user_keys'); + } + + private mergeKeys( + keyType: 'guild_keys' | 'user_keys' + ): Record { + return this.getAll() + .flatMap((cmd) => (cmd[keyType] ? [cmd[keyType]] : [])) + .reduce((acc, val) => Object.assign(acc, val), {}); + } + /* internal */