add cmd meta
This commit is contained in:
parent
d681dc41a7
commit
97ce6d1f36
4 changed files with 39 additions and 4 deletions
|
@ -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) =>
|
||||
|
|
|
@ -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
|
||||
|
|
29
test/meta.ts
Normal file
29
test/meta.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import {
|
||||
CommandClient,
|
||||
Command,
|
||||
Intents,
|
||||
CommandOptions,
|
||||
CommandContext
|
||||
} from '../mod.ts'
|
||||
import { TOKEN } from './config.ts'
|
||||
|
||||
const client = new CommandClient({
|
||||
prefix: '!',
|
||||
token: TOKEN,
|
||||
intents: Intents.None
|
||||
})
|
||||
|
||||
class Ping extends Command {
|
||||
static meta: CommandOptions = {
|
||||
name: 'ping',
|
||||
aliases: 'pong'
|
||||
}
|
||||
|
||||
execute(ctx: CommandContext): void {
|
||||
ctx.message.reply('Pong!')
|
||||
}
|
||||
}
|
||||
|
||||
client.commands.add(Ping)
|
||||
|
||||
client.connect()
|
|
@ -1,4 +1,4 @@
|
|||
import { SlashClient } from '../../mod.ts'
|
||||
import { SlashClient } from '../mod.ts'
|
||||
import { SLASH_ID, SLASH_PUB_KEY, SLASH_TOKEN } from './config.ts'
|
||||
import { listenAndServe } from 'https://deno.land/std@0.90.0/http/server.ts'
|
||||
|
||||
|
|
Loading…
Reference in a new issue