diff --git a/lib/CoreBot.js b/lib/CoreBot.js index fe61062ba..66cf03274 100755 --- a/lib/CoreBot.js +++ b/lib/CoreBot.js @@ -110,7 +110,7 @@ function Botkit(configuration) { } else { // handle might be a mapping of keyword to callback. // lets see if the message matches any of the keywords - var patterns = this.handler; + var match, patterns = this.handler; for (var p = 0; p < patterns.length; p++) { if (patterns[p].pattern && botkit.hears_test([patterns[p].pattern], message)) { patterns[p].callback(message, this); @@ -706,8 +706,7 @@ function Botkit(configuration) { test = tests[t]; } - var match = message.text.match(test); - if (message.text.match(test)) { + if (match = message.text.match(test)) { message.match = match; return true; } @@ -748,7 +747,7 @@ function Botkit(configuration) { for (var e = 0; e < events.length; e++) { (function(keywords, test_function) { botkit.on(events[e], function(bot, message) { - if (test_function(keywords, message)) { + if (test_function && test_function(keywords, message)) { botkit.debug('I HEARD', keywords); cb.apply(this, [bot, message]); return false;