2013-06-09 18:55:46 +02:00
|
|
|
var _ = require('underscore')._;
|
|
|
|
|
2013-04-23 20:48:41 +02:00
|
|
|
var nickserv = function(dbot) {
|
|
|
|
this.authStack = {};
|
2013-06-09 18:05:19 +02:00
|
|
|
this.userStack = {};
|
2013-04-23 20:48:41 +02:00
|
|
|
|
|
|
|
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);
|
2013-06-09 18:05:19 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'getUserHost': function(server, nick, callback) {
|
|
|
|
if(!_.has(this.userStack, server)) this.userStack[server] = {};
|
|
|
|
this.userStack[server][nick] = callback;
|
2013-06-09 18:06:58 +02:00
|
|
|
dbot.instance.connections[server].send('USERHOST ' + nick);
|
2013-04-23 20:48:41 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.listener = function(event) {
|
2013-06-09 18:05:19 +02:00
|
|
|
if(event.action == 'NOTICE') {
|
|
|
|
var nickserv = dbot.config.servers[event.server].nickserv,
|
|
|
|
statusRegex = this.config.servers[event.server].matcher,
|
|
|
|
acceptableState = this.config.servers[event.server].acceptableState;
|
2013-04-23 21:07:23 +02:00
|
|
|
|
2013-06-09 18:05:19 +02:00
|
|
|
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);
|
|
|
|
}
|
2013-04-23 20:48:41 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-09 18:05:19 +02:00
|
|
|
} else if(event.action == '302') {
|
2013-06-09 19:42:41 +02:00
|
|
|
var match = event.params.match(/:(.+)=([^@]+)@(.+)$/);
|
2013-06-09 19:51:49 +02:00
|
|
|
|
|
|
|
if(match[1]) match[1] = match[1].replace('\*', '');
|
2013-06-09 18:55:46 +02:00
|
|
|
if(match && _.has(this.userStack, event.server) && _.has(this.userStack[event.server], match[1])) {
|
2013-06-09 19:42:41 +02:00
|
|
|
this.userStack[event.server][match[1]](match[3].trim());
|
2013-06-09 18:55:46 +02:00
|
|
|
}
|
2013-04-23 20:48:41 +02:00
|
|
|
}
|
|
|
|
}.bind(this);
|
2013-06-09 18:10:57 +02:00
|
|
|
this.on = ['NOTICE', '302'];
|
2013-04-23 20:48:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return new nickserv(dbot);
|
|
|
|
};
|