From b9a9866e5e65b0acafe8fd9add2298c041d1766c Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 23 Apr 2013 18:48:41 +0000 Subject: [PATCH] nickserv module in master --- modules/nickserv/config.json | 9 +++++++++ modules/nickserv/nickserv.js | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 modules/nickserv/config.json create mode 100644 modules/nickserv/nickserv.js diff --git a/modules/nickserv/config.json b/modules/nickserv/config.json new file mode 100644 index 0000000..3bcaece --- /dev/null +++ b/modules/nickserv/config.json @@ -0,0 +1,9 @@ +{ + "servers": { + "nc": { + "matcher": "STATUS ([^ ]+) (\\d)$", + "acceptableState": 3, + "infoCommand": "status" + } + } +} diff --git a/modules/nickserv/nickserv.js b/modules/nickserv/nickserv.js new file mode 100644 index 0000000..28f20ae --- /dev/null +++ b/modules/nickserv/nickserv.js @@ -0,0 +1,37 @@ +var nickserv = function(dbot) { + this.authStack = {}; + + this.api = { + 'auth': function(server, nick, callback) { + var nickserv = dbot.config.servers[server].nickserv, + infoCommand = this.config.servers[server].infoCommand; + + if(!_.has(this.authStack, server)) this.authStack[server] = {}; + this.authStack[server][nick] = callback; + + dbot.say(server, nickserv, infoCommand + ' ' + nick); + } + }; + + this.listener = function(event) { + var nickserv = dbot.config.servers[event.server].nickserv, + statusRegex = this.config.servers[event.server].matcher, + acceptableState = this.config.servers[event.server].acceptableState; + + if(event.user == nickserv) { + var info = event.params.match(statusRegex); + if(info && _.has(this.authStack, event.server)) { + if(info[2] == acceptableState ) { + this.authStack[event.server][info[1]](true); + } else { + this.authStack[event.server][info[1]](false); + } + } + } + }.bind(this); + this.on = 'NOTICE'; +}; + +exports.fetch = function(dbot) { + return new nickserv(dbot); +};