From 9ccc04cf8932bcbdae287e4bdcd8aad5699f8f53 Mon Sep 17 00:00:00 2001 From: kevinsuh Date: Sun, 12 Jun 2016 14:46:23 -0400 Subject: [PATCH] Update Corebot to handle undefined test_function --- lib/CoreBot.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/CoreBot.js b/lib/CoreBot.js index ee0d61065..ae12bb118 100755 --- a/lib/CoreBot.js +++ b/lib/CoreBot.js @@ -109,7 +109,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); @@ -728,8 +728,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; } @@ -770,7 +769,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;