CommandsApi: fix accidently overwriting inputType BUILT_IN

This commit is contained in:
Vendicated 2022-10-12 05:34:39 +02:00
parent 66f8fde353
commit 8e93c5cb43
No known key found for this signature in database
GPG Key ID: EC781ADFB93EFFA3

@ -45,7 +45,9 @@ export function generateId() {
* @param fallbackValue Fallback value in case this option wasn't passed * @param fallbackValue Fallback value in case this option wasn't passed
* @returns Value * @returns Value
*/ */
export function findOption<T extends string | undefined>(args: Argument[], name: string, fallbackValue?: T): T extends undefined ? T : string { export function findOption<T>(args: Argument[], name: string): T & {} | undefined;
export function findOption<T>(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; 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)) if (BUILT_IN.some(c => c.name === command.name))
throw new Error(`Command '${command.name}' already exists.`); throw new Error(`Command '${command.name}' already exists.`);
command.id ||= generateId(); command.id ??= generateId();
command.applicationId ||= "-1"; // BUILT_IN; command.applicationId ??= "-1"; // BUILT_IN;
command.type ||= ApplicationCommandType.CHAT_INPUT; command.type ??= ApplicationCommandType.CHAT_INPUT;
command.inputType ||= ApplicationCommandInputType.BUILT_IN_TEXT; command.inputType ??= ApplicationCommandInputType.BUILT_IN_TEXT;
command.plugin ||= plugin; command.plugin ||= plugin;
modifyOpt(command); modifyOpt(command);
@ -155,5 +157,5 @@ export interface Command {
options?: Option[]; options?: Option[];
predicate?(ctx: CommandContext): boolean; predicate?(ctx: CommandContext): boolean;
execute(args: Argument[], ctx: CommandContext): CommandReturnValue | void; execute(args: Argument[], ctx: CommandContext): CommandReturnValue | void | Promise<CommandReturnValue | void>;
} }