From 82a3ff107c2ee7d943fc9f0dd54cbb2d6299aaef Mon Sep 17 00:00:00 2001 From: GRZ4NA Date: Wed, 15 Sep 2021 18:45:39 +0200 Subject: [PATCH] changed get method to not use overlaps --- src/commands/CommandManager.ts | 62 +++++++++++++++------------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/src/commands/CommandManager.ts b/src/commands/CommandManager.ts index b0543d8..7348a7b 100644 --- a/src/commands/CommandManager.ts +++ b/src/commands/CommandManager.ts @@ -148,41 +148,33 @@ export class CommandManager { * @param {string} q - command name or alias * @param {CommandType} t - type of command you want to get from this manager */ - public get(q: string, t?: undefined): BaseCommand | null; - public get(q: string, t: "CHAT"): ChatCommand | null; - public get(q: string, t: "NESTED"): NestedCommand | null; - public get(q: string, t: "CONTEXT"): ContextMenuCommand | null; - public get(q: string, t?: CommandType): BaseCommand | null { - if (t) { - switch (t) { - case "CHAT": - return ( - this.list(t).find((c) => { - if (c.name === q) { - return true; - } - if (c.aliases && c.aliases.length > 0 && c.aliases.find((a) => a === q)) { - return true; - } else { - return false; - } - }) || null - ); - case "NESTED": - return ( - this.list(t).find((c) => { - if (c.name === q) { - return true; - } else { - return false; - } - }) || null - ); - case "CONTEXT": - return this.list(t).find((c) => c.name === q) || null; - } - } else { - return this.list().find((c) => c.name === q) || null; + public get(q: string, t?: T): Command | null { + switch (t) { + case "CHAT": + return ( + (this.list(t).find((c) => { + if (c.name === q) { + return true; + } + if (c.aliases && c.aliases.length > 0 && c.aliases.find((a) => a === q)) { + return true; + } else { + return false; + } + }) as Command) || null + ); + case "NESTED": + return (this.list(t).find((c) => { + if (c.name === q) { + return true; + } else { + return false; + } + }) || null) as Command; + case "CONTEXT": + return (this.list(t).find((c) => c.name === q) as Command) || null; + default: + return (this.list().find((c) => c.name === q) as Command) || null; } }