add cmd meta

This commit is contained in:
DjDeveloperr 2021-04-08 15:10:50 +05:30
parent d681dc41a7
commit 97ce6d1f36
4 changed files with 39 additions and 4 deletions

View file

@ -72,6 +72,8 @@ export interface CommandOptions {
}
export class Command implements CommandOptions {
static meta?: CommandOptions
name: string = ''
description?: string
category?: string
@ -486,12 +488,16 @@ export class CommandsManager {
/** Add a Command */
add(cmd: Command | typeof Command): boolean {
// eslint-disable-next-line new-cap
if (!(cmd instanceof Command)) cmd = new cmd()
if (!(cmd instanceof Command)) {
const CmdClass = cmd
cmd = new CmdClass()
Object.assign(cmd, CmdClass.meta ?? {})
}
if (this.exists(cmd, cmd.extension?.subPrefix))
throw new Error(
`Failed to add Command '${cmd.toString()}' with name/alias already exists.`
)
if (cmd.name === '') throw new Error('Command has no name')
this.list.set(
`${cmd.name}-${
this.list.filter((e) =>

View file

@ -253,7 +253,7 @@ export class SlashClient extends HarmonyEventEmitter<SlashClientEvents> {
respond: (options: {
status?: number
headers?: Headers
body?: string | Uint8Array | FormData
body?: any
}) => Promise<void>
}): Promise<false | Interaction> {
if (req.method.toLowerCase() !== 'post') return false