diff options
Diffstat (limited to 'lib/panda.js')
| -rw-r--r-- | lib/panda.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/panda.js b/lib/panda.js index 4b4b350..bb4b6ed 100644 --- a/lib/panda.js +++ b/lib/panda.js @@ -52,10 +52,19 @@ panda.query = function(nick, msg, cb){ }) } +panda.watch = function(channel, regexp, cb){ + watchers.push({ + channel: channel, + regexp: regexp, + cb: cb, + }) +} + process.on('uncaughtException', function (err) { client.disconnect() }) +var watchers = [] var current_task var message_queue = async.queue(function(task, done){ current_task = task @@ -85,6 +94,21 @@ client.addListener('join', function (channel, nick, message) { panda.login() } }) +client.addListener('message', function (nick, to, text, message) { + watchers.forEach(function(watcher){ + if (to === watcher.channel) { + var match = watcher.regexp.match(text) + if (match) { + cb({ + channel: to, + nick: nick, + message: message, + match: match, + }) + } + } + }) +}) client.addListener('pm', function (nick, text, message) { if (! current_task) return if (nick === current_task.nick) { |
