From 8e93c5cb43fc8f375f91a44dc665ddc573435f84 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 12 Oct 2022 05:34:39 +0200 Subject: [PATCH] CommandsApi: fix accidently overwriting inputType BUILT_IN --- src/api/Commands.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/api/Commands.ts b/src/api/Commands.ts index 907a65d3..f7f42e94 100644 --- a/src/api/Commands.ts +++ b/src/api/Commands.ts @@ -45,7 +45,9 @@ export function generateId() { * @param fallbackValue Fallback value in case this option wasn't passed * @returns Value */ -export function findOption(args: Argument[], name: string, fallbackValue?: T): T extends undefined ? T : string { +export function findOption(args: Argument[], name: string): T & {} | undefined; +export function findOption(args: Argument[], name: string, fallbackValue: T): T & {}; +export function findOption(args: Argument[], name: string, fallbackValue?: any) { return (args.find(a => a.name === name)?.value || fallbackValue) as any; } @@ -64,10 +66,10 @@ export function registerCommand(command: Command, plugin: string) { if (BUILT_IN.some(c => c.name === command.name)) throw new Error(`Command '${command.name}' already exists.`); - command.id ||= generateId(); - command.applicationId ||= "-1"; // BUILT_IN; - command.type ||= ApplicationCommandType.CHAT_INPUT; - command.inputType ||= ApplicationCommandInputType.BUILT_IN_TEXT; + command.id ??= generateId(); + command.applicationId ??= "-1"; // BUILT_IN; + command.type ??= ApplicationCommandType.CHAT_INPUT; + command.inputType ??= ApplicationCommandInputType.BUILT_IN_TEXT; command.plugin ||= plugin; modifyOpt(command); @@ -155,5 +157,5 @@ export interface Command { options?: Option[]; predicate?(ctx: CommandContext): boolean; - execute(args: Argument[], ctx: CommandContext): CommandReturnValue | void; + execute(args: Argument[], ctx: CommandContext): CommandReturnValue | void | Promise; }