bugfix + tests
This commit is contained in:
parent
5c4accc58d
commit
19fef0ed6c
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "commandparser",
|
"name": "commandparser",
|
||||||
"version": "1.0.23",
|
"version": "1.0.24",
|
||||||
"description": "Parser meant to parse commands and their options for discord bots",
|
"description": "Parser meant to parse commands and their options for discord bots",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"author": "Navy.gif",
|
"author": "Navy.gif",
|
||||||
|
@ -103,16 +103,16 @@ class CommandOption implements ICommandOption {
|
|||||||
|
|
||||||
protected STRING() {
|
protected STRING() {
|
||||||
if (!this.rawValue) return { error: true };
|
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) {
|
if (this.choices.length) {
|
||||||
const found = this.choices.find((c) => {
|
const found = this.choices.find((c) => {
|
||||||
const choice = c as string;
|
const choice = c as string;
|
||||||
return choice.toLowerCase() === this.rawValue?.join(' ').toLowerCase();
|
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 { error: true };
|
||||||
}
|
}
|
||||||
return { value: (this._rawValue as string[]).join(' '), removed: this._rawValue };
|
return { value: this.rawValue.join(' '), removed: this.rawValue };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
24
tests/CommandOption.test.js
Normal file
24
tests/CommandOption.test.js
Normal 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)
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user