diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-11-15 17:44:43 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-11-15 17:44:43 -0500 |
| commit | 3f36129ec17fd0de2091b1a883ac6466a641de77 (patch) | |
| tree | 9a549959722923df8968ce031a7ee20003d8c538 /lib | |
| parent | 54475086f2e47a61271a3f0c408bc68b54c6020f (diff) | |
message watcher api
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/index.js | 1 | ||||
| -rw-r--r-- | lib/panda.js | 24 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/index.js b/lib/index.js index 100989c..793581f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -14,7 +14,6 @@ var storage = multer.memoryStorage() var multer_upload = multer({ storage: storage }) var upload = require("./upload") - router.post("/_irc/image", multer_upload.single('image'), function(req, res){ upload.put("image", req.file, { unacceptable: function(err){ 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) { |
