replaced undefined type with null in Parameter

This commit is contained in:
mmacierzanka committed 2021-09-07 18:27:11 +02:00
1 parent 49f01a3bed
commit 2c31443a01
3 files changed
+9 -8

No files matched your search

+7 -6
View File
@@ -1,9 +1,10 @@
import { CommandInteraction, CommandInteractionOption, Message } from "discord.js";
import { CommandInteraction, Message } from "discord.js";
import { CommandNotFound, MissingParameterError } from "../errors";
import { BooleanParameter, InputParameter, NullParameter, NumberParameter, ObjectParameter, Parameter, StringParameter } from "../structures/Parameter";
import { CommandMessageStructure as ChatCommandInteractionData } from "../types/ChatCommand";
import { ChatCommand } from "../structures/ChatCommand";
import { BooleanParameter, InputParameter, NullParameter, NumberParameter, ObjectParameter, Parameter, StringParameter } from "../structures/Parameter.js";
import { CommandMessageStructure as ChatCommandInteractionData } from "../types/ChatCommand.js";
import { ChatCommand } from "../structures/ChatCommand.js";
import { CommandManager } from "./CommandManager.js";
import { ParameterResolvable } from "../types/Parameter.js";
export class ChatCommandManager extends CommandManager {
protected readonly _list: ChatCommand[] = [];
@@ -99,7 +100,7 @@ export class ChatCommandManager extends CommandManager {
const command = this.get(i.commandName);
if (command) {
if (command.parameters.length > 0) {
const argsRaw = i.options.data.map((a) => a.value?.toString() || "");
const argsRaw = i.options.data.map((a) => a.value || null);
const args = this.processRawInput(argsRaw, command.parameters);
return {
command: command,
@@ -118,7 +119,7 @@ export class ChatCommandManager extends CommandManager {
}
}
private processRawInput(args: string[], schema: Parameter[]): InputParameter[] {
private processRawInput(args: ParameterResolvable[], schema: Parameter[]): InputParameter[] {
return schema.map((p, i) => {
if (!p.optional && !args[i]) {
throw new MissingParameterError(p);
+1 -1
View File
@@ -95,7 +95,7 @@ export class StringParameter extends InputParameter {
return;
}
}
super(parameter, value?.toString());
super(parameter, value?.toString() || "");
}
}
+1 -1
View File
@@ -2,7 +2,7 @@ import { ObjectID } from "../structures/Parameter.js";
export type ParameterType = "string" | "boolean" | "number" | "user" | "role" | "channel" | "mentionable";
export type ParameterResolvable = string | boolean | number | ObjectID | null | undefined; //remove "undefined"
export type ParameterResolvable = string | boolean | number | ObjectID | null;
/**
* @interface