diff --git a/package.json b/package.json index 8eb8333..8db58cb 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/Botlang.js b/src/Botlang.js index bbac51c..83b27a7 100644 --- a/src/Botlang.js +++ b/src/Botlang.js @@ -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.'; diff --git a/src/Parser/Parser.js b/src/Parser/Parser.js index caa223c..115772c 100644 --- a/src/Parser/Parser.js +++ b/src/Parser/Parser.js @@ -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 : [] }; } diff --git a/test/Data/hello_world.ast.json b/test/Data/hello_world.ast.json index e2d9757..94a755c 100644 --- a/test/Data/hello_world.ast.json +++ b/test/Data/hello_world.ast.json @@ -12,7 +12,7 @@ }] }, { "type": "trigger", - "pattern": "Hey", + "pattern": "(\\w?)Hey", "responses": [{ "type": "response", "value": "Hi, how is it going?" diff --git a/test/Data/hello_world.bot b/test/Data/hello_world.bot index 1b4cc72..56118e9 100644 --- a/test/Data/hello_world.bot +++ b/test/Data/hello_world.bot @@ -4,5 +4,5 @@ - "Hi, how are you?" - "Hey, how are you?" -+ "Hey" ++ "* Hey" - "Hi, how is it going?"