changed CommandType to "CHAT" | "CONTEXT"

This commit is contained in:
mmacierzanka committed 2021-09-08 22:57:43 +02:00
1 parent 8ce872088d
commit 2ca3143a76
4 files changed
+10 -11

No files matched your search

+1 -1
View File
@@ -117,7 +117,7 @@ export class BaseCommand {
public toObject(): BaseCommandObject {
const obj: BaseCommandObject = {
name: this.name,
type: this.type === "MESSAGE" ? 3 : this.type === "USER" ? 2 : 1,
type: this.type === "CONTEXT" ? 0 : 1,
default_permissions: true,
};
return obj;
+7 -8
View File
@@ -42,7 +42,7 @@ export class CommandManager {
this._commands.push(command);
return;
} else if (command.isContextMenuCommand()) {
if (this.list("MESSAGE").find((c) => c.name === command.name)) {
if (this.list("CONTEXT").find((c) => c.name === command.name)) {
console.error(`[❌ ERROR] Cannot add command "${command.name}" because this name has already been registered as a ContextMenuCommand in this manager.`);
return;
}
@@ -53,7 +53,7 @@ export class CommandManager {
public get(q: string, t?: undefined): BaseCommand | null;
public get(q: string, t: "CHAT"): ChatCommand | null;
public get(q: string, t: "MESSAGE"): ContextMenuCommand | null;
public get(q: string, t: "CONTEXT"): ContextMenuCommand | null;
public get(q: string, t?: CommandType): BaseCommand | null {
if (t) {
switch (t) {
@@ -70,7 +70,7 @@ export class CommandManager {
}
}) || null
);
case "MESSAGE":
case "CONTEXT":
return this.list(t).find((c) => c.name === q) || null;
}
} else {
@@ -81,14 +81,13 @@ export class CommandManager {
public list(): readonly BaseCommand[];
public list(f: "CHAT"): readonly ChatCommand[];
public list(f: "MESSAGE"): readonly ContextMenuCommand[];
public list(f: "CONTEXT"): readonly ContextMenuCommand[];
public list(f?: CommandType): readonly BaseCommand[] {
switch (f) {
case "CHAT":
return Object.freeze([...this._commands.filter((c) => c.type === "CHAT")]);
case "USER":
case "MESSAGE":
return Object.freeze([...this._commands.filter((c) => c.type === "MESSAGE" || c.type === "USER")]);
case "CONTEXT":
return Object.freeze([...this._commands.filter((c) => c.type === "CONTEXT")]);
default:
return Object.freeze([...this._commands]);
}
@@ -108,7 +107,7 @@ export class CommandManager {
throw new CommandNotFound(i.commandName);
}
} else if (i.isContextMenu()) {
const cmd = this.get(i.commandName, "MESSAGE");
const cmd = this.get(i.commandName, "CONTEXT");
if (cmd) {
const target = new TargetID(i.targetId, i.targetType);
return {
+1 -1
View File
@@ -10,7 +10,7 @@ export class ContextMenuCommand extends BaseCommand {
if (!ContextMenuCommand.nameRegExp.test(o.name)) {
throw new Error("Incorrect command name. Command names must have 1-32 characters");
}
super("MESSAGE", {
super("CONTEXT", {
name: o.name,
function: o.function,
announceSuccess: o.announceSuccess,
+1 -1
View File
@@ -7,7 +7,7 @@ import { CommandInteraction, Message, MessageEmbed, ReplyMessageOptions } from "
export type CommandResolvable = BaseCommand | ChatCommand | ContextMenuCommand;
export type CommandType = "CHAT" | "MESSAGE" | "USER";
export type CommandType = "CHAT" | "CONTEXT";
export type CommandFunctionReturnTypes = void | string | MessageEmbed | ReplyMessageOptions | Promise<void | string | MessageEmbed | ReplyMessageOptions>;