bugfix + tests

This commit is contained in:
Erik 2022-07-29 23:22:29 +03:00
parent 5c4accc58d
commit 19fef0ed6c
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 28 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "commandparser",
"version": "1.0.23",
"version": "1.0.24",
"description": "Parser meant to parse commands and their options for discord bots",
"main": "build/index.js",
"author": "Navy.gif",

View File

@ -103,16 +103,16 @@ class CommandOption implements ICommandOption {
protected STRING() {
if (!this.rawValue) return { error: true };
if (this._aliased) return { value: this.rawValue.join(' '), removed: [] };
if (this.aliased) return { value: this.rawValue.join(' '), removed: [] };
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 };
if (found) return { value: found, removed: this.rawValue };
return { error: true };
}
return { value: (this._rawValue as string[]).join(' '), removed: this._rawValue };
return { value: this.rawValue.join(' '), removed: this.rawValue };
}
}

View File

@ -0,0 +1,24 @@
const { Parser, Command, CommandOption, OptionType } = require('../build/index');
const opt = new CommandOption({
name: 'text',
type: OptionType.STRING
});
class TestCommand extends Command {
constructor() {
super({
name: 'test',
options: [opt]
})
}
};
const parser = new Parser({
commands: [new TestCommand()],
resolver: null
});
(async () => {
const parsed = await parser.parseMessage('test message.author')
console.log(parsed)
})();