Skip to content

Commit

Permalink
Add wildcard to trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
matchilling committed Apr 23, 2017
1 parent b56a9ad commit b1a19d8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -44,6 +44,7 @@
"dev": "./node_modules/.bin/mocha --compilers js:babel-core/register --recursive --watch test/",
"docs:make": "./node_modules/.bin/esdoc -c .esdoc.json",
"eslint": "./node_modules/.bin/eslint src/",
"start": "node ./lib/Cli ./example/eliza.bot",
"test": "./node_modules/.bin/mocha --compilers js:babel-core/register --recursive test/"
},
"eslintConfig": {
Expand Down
2 changes: 1 addition & 1 deletion src/Botlang.js
Expand Up @@ -43,7 +43,7 @@ class Botlang {
let res = null;

this.program.body.forEach((el) => {
if ('trigger' === el.type && new RegExp(el.pattern).test(message)) res = Botlang.evalTriggerNode(message, el);
if ('trigger' === el.type && new RegExp(el.pattern, 'i').test(message)) res = Botlang.evalTriggerNode(message, el);
});

return res || 'Sorry, I do not know the answer to that question.';
Expand Down
7 changes: 5 additions & 2 deletions src/Parser/Parser.js
Expand Up @@ -94,14 +94,17 @@ class Parser {
* @return {Object}
*/
parseTrigger() {
const trigger = this.lexer.next();
const trigger = this.lexer.next(),
// Replace wildcard characters
pattern = trigger.getValue().replace(/(\s?)\*(\s?)/g, '(\\w?)');

if ('string' !== trigger.getType()) {
return this.lexer.inputError('Expected trigger pattern after trigger identifier.');
}

return {
type : 'trigger',
pattern : trigger.getValue(),
pattern,
responses : []
};
}
Expand Down
2 changes: 1 addition & 1 deletion test/Data/hello_world.ast.json
Expand Up @@ -12,7 +12,7 @@
}]
}, {
"type": "trigger",
"pattern": "Hey",
"pattern": "(\\w?)Hey",
"responses": [{
"type": "response",
"value": "Hi, how is it going?"
Expand Down
2 changes: 1 addition & 1 deletion test/Data/hello_world.bot
Expand Up @@ -4,5 +4,5 @@
- "Hi, how are you?"
- "Hey, how are you?"

+ "Hey"
+ "* Hey"
- "Hi, how is it going?"

0 comments on commit b1a19d8

Please sign in to comment.