From e2aac258a7612deedd453dad0bf57f5c0af228e2 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 29 Jul 2022 22:19:24 +0300 Subject: [PATCH] string type --- package.json | 2 +- src/classes/CommandOption.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7a9874e..3a824a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "commandparser", - "version": "1.0.21", + "version": "1.0.22", "description": "Parser meant to parse commands and their options for discord bots", "main": "build/index.js", "author": "Navy.gif", diff --git a/src/classes/CommandOption.ts b/src/classes/CommandOption.ts index b6c180f..18a9ce4 100644 --- a/src/classes/CommandOption.ts +++ b/src/classes/CommandOption.ts @@ -101,6 +101,20 @@ class CommandOption implements ICommandOption { return { value: member, removed: this.rawValue }; } + protected STRING() { + if (this._aliased) return { value: this.rawValue?.join(' ') || '', removed: [] }; + if(!this.rawValue) return { error: true }; + if (this.choices.length) { + const found = this.choices.find((c) => { + const choice = c as string; + return choice.toLowerCase() === this.rawValue?.join(' ').toLowerCase(); + }); + if (found) return { value: found, removed: this._rawValue }; + return { error: true }; + } + return { value: this._rawValue, removed: this._rawValue }; + } + } export { CommandOption };