From f9c586dd14cec3bcc9ca3d30967a89969b2e1360 Mon Sep 17 00:00:00 2001 From: GRZ4NA Date: Sun, 8 Aug 2021 18:39:10 +0200 Subject: [PATCH] removed keywords --- src/Command.ts | 2 -- src/CommandManager.ts | 71 ++++++++----------------------------------- src/Help.ts | 10 +----- src/types.ts | 1 - 4 files changed, 13 insertions(+), 71 deletions(-) diff --git a/src/Command.ts b/src/Command.ts index d6a3a91..e36b74d 100644 --- a/src/Command.ts +++ b/src/Command.ts @@ -20,7 +20,6 @@ export class Command { name: string; parameters: Parameter[]; aliases?: string[]; - keywords?: string[]; description: string; usage?: string; permissionCheck: PermissionCheckTypes; @@ -64,7 +63,6 @@ export class Command { this.parameters = options.parameters.map((ps) => new Parameter(ps)); } this.aliases = Command.processPhrase(options.aliases); - this.keywords = Command.processPhrase(options.keywords); this.description = options.description || "No description"; this.usage = options.usage || this.generateUsageFromArguments(); this.permissionCheck = diff --git a/src/CommandManager.ts b/src/CommandManager.ts index 57aadc6..aafc7eb 100644 --- a/src/CommandManager.ts +++ b/src/CommandManager.ts @@ -31,48 +31,18 @@ export class CommandManager { * @param {GetMode} [mode='ALL'] - specifies which types of command triggers will be used to find the command [*NO_PREFIX* - only keywords; *PREFIX* - names and aliases] * @returns *Command* | *null* */ - get(phrase: string, mode?: GetMode): Command | null { - if (!mode) mode = "ALL"; + get(phrase: string): Command | null { let command: Command | null = null; this.list.map((c) => { - switch (mode) { - case "PREFIX": - if (c.name == phrase) { - command = c; - } - c.aliases && - c.aliases.map((a) => { - if (a == phrase) { - command = c; - } - }); - break; - case "NO_PREFIX": - c.keywords && - c.keywords.map((k) => { - if (k == phrase) { - command = c; - } - }); - break; - case "ALL": - if (c.name == phrase) { - command = c; - } - c.aliases && - c.aliases.map((a) => { - if (a == phrase) { - command = c; - } - }); - c.keywords && - c.keywords.map((k) => { - if (k == phrase) { - command = c; - } - }); - break; + if (c.name == phrase) { + command = c; } + c.aliases && + c.aliases.map((a) => { + if (a == phrase) { + command = c; + } + }); }); return command; } @@ -105,17 +75,6 @@ export class CommandManager { ar.splice(i, 1); } }); - this.list.map((c) => { - command.keywords && - command.keywords.map((k, i, a) => { - if (c.keywords && c.keywords.indexOf(k) != -1) { - console.warn( - `[⚠ WARN] The name "${k}" is already a registered KEYWORD for the "${c.name}" command. It will be removed from the "${command.name}" command` - ); - a.splice(i, 1); - } - }); - }); this.list.push(command); return true; } catch (e) { @@ -130,16 +89,10 @@ export class CommandManager { * @returns *CommandMessagesStructure* | *null* */ fetchFromMessage(message: Message): CommandMessageStructure | null { - if (!message.author.bot) { - let prefix = false; - if (message.content.startsWith(this.prefix)) { - prefix = true; - } - const content = prefix - ? message.content.replace(this.prefix, "") - : message.content; + if (!message.author.bot && message.content.startsWith(this.prefix)) { + const content = message.content.replace(this.prefix, ""); const name = content.split(" ")[0]; - const command = this.get(name, prefix ? "PREFIX" : "NO_PREFIX"); + const command = this.get(name); if (command) { const argumentsText = content.replace(name, ""); const paramsList = argumentsText diff --git a/src/Help.ts b/src/Help.ts index 8dd3100..4df3ddf 100644 --- a/src/Help.ts +++ b/src/Help.ts @@ -31,8 +31,7 @@ export class HelpMessage extends Command { if (helpMsg != null) { if (param("command_name")) { const cmd: Command | null = cmdManager.get( - param("command_name")?.toString() || "", - "ALL" + param("command_name")?.toString() || "" ); if (cmd) { helpMsg.setTitle( @@ -66,13 +65,6 @@ export class HelpMessage extends Command { }); helpMsg.addField("Aliases:", aList, false); } - if (cmd.keywords && cmd.keywords.length > 0) { - let kwrdList: string = ""; - cmd.keywords.map((k) => { - kwrdList += k + "\n"; - }); - helpMsg.addField("Keywords:", kwrdList, false); - } } else { throw new ReferenceError( `Command "${param( diff --git a/src/types.ts b/src/types.ts index a682bab..c970dee 100644 --- a/src/types.ts +++ b/src/types.ts @@ -22,7 +22,6 @@ export interface CommandBuilder { name: string; parameters?: ParameterSchema[] | "simple" | "no_input"; aliases?: string[] | string; - keywords?: string[] | string; description?: string; usage?: string; permissionCheck?: PermissionCheckTypes;