accepts message with ""
This commit is contained in:
@@ -28,8 +28,10 @@ class Command{
|
|||||||
}else if(this.requireInput){
|
}else if(this.requireInput){
|
||||||
//the command requires input
|
//the command requires input
|
||||||
|
|
||||||
|
|
||||||
let splitCommand = this.command.split(' ');
|
let splitCommand = this.command.split(' ');
|
||||||
let splitMsg = msg.split(' ');
|
let splitMsg = this._getInputMessage(message);
|
||||||
|
|
||||||
|
|
||||||
//check the number of words both has
|
//check the number of words both has
|
||||||
//if not same then return false
|
//if not same then return false
|
||||||
@@ -95,6 +97,19 @@ class Command{
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getInputMessage(msg){
|
||||||
|
let split = msg.split(/['"]/g);
|
||||||
|
if(split.length > 1)
|
||||||
|
{
|
||||||
|
let splitMsg = split[0].trim().split(' ');
|
||||||
|
let inputs = split.slice(1).filter( el => el.trim() == "" ? null : el);
|
||||||
|
splitMsg = splitMsg.concat(inputs);
|
||||||
|
return splitMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
return msg.split(' ');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.Command = Command;
|
module.exports.Command = Command;
|
||||||
|
|||||||
@@ -238,4 +238,5 @@ module.exports= onMessage = async (message, client) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//export default onMessage;
|
//export default onMessage;
|
||||||
@@ -164,6 +164,33 @@ describe('Command', () => {
|
|||||||
expect(a.getInput(message)['name']).to.equal('pikachu');
|
expect(a.getInput(message)['name']).to.equal('pikachu');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Test : _getInputMessage() with a sentence', () => {
|
||||||
|
let a = new Command({command : 'wg website desc <desc>'});
|
||||||
|
let b = a._getInputMessage(`wg website desc "Hello everynyan, how are you"`);
|
||||||
|
expect(b[0]).to.equal('wg');
|
||||||
|
expect(b[1]).to.equal('website');
|
||||||
|
expect(b[2]).to.equal('desc');
|
||||||
|
expect(b[3]).to.equal('Hello everynyan, how are you');
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Test : _getInputMessage() with multiple sentence input', () => {
|
||||||
|
let a = new Command({command : 'wg website desc <desc>'});
|
||||||
|
let b = a._getInputMessage(`wg website desc "Hello everynyan, how are you" "I am fine thank you"`);
|
||||||
|
expect(b[0]).to.equal('wg');
|
||||||
|
expect(b[1]).to.equal('website');
|
||||||
|
expect(b[2]).to.equal('desc');
|
||||||
|
expect(b[3]).to.equal('Hello everynyan, how are you');
|
||||||
|
expect(b[4]).to.equal('I am fine thank you');
|
||||||
|
})
|
||||||
|
it('Test : _getInputMessage() with single word', () => {
|
||||||
|
let a = new Command({command : 'wg website desc <desc>'});
|
||||||
|
let b = a._getInputMessage(`wg website desc Hello`);
|
||||||
|
expect(b[0]).to.equal('wg');
|
||||||
|
expect(b[1]).to.equal('website');
|
||||||
|
expect(b[2]).to.equal('desc');
|
||||||
|
expect(b[3]).to.equal('Hello');
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -76,7 +76,7 @@ describe('Entity', () => {
|
|||||||
expect(a.selectedData).to.equals('gada');
|
expect(a.selectedData).to.equals('gada');
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only('Test: selectedData() = false', () => {
|
it('Test: selectedData() = false', () => {
|
||||||
let a = new Entity();
|
let a = new Entity();
|
||||||
a.addData('hello world', new Website('hello world'));
|
a.addData('hello world', new Website('hello world'));
|
||||||
a.addData('gada', new Website('gada'));
|
a.addData('gada', new Website('gada'));
|
||||||
|
|||||||
Reference in New Issue
Block a user