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-12-31 02:43:07 +01:00
|
|
|
this.servStack = {};
|
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;
|
2013-10-20 18:16:21 +02:00
|
|
|
dbot.say(server, nickserv, infoCommand + ' ' + nick + ' *');
|
2013-06-09 18:05:19 +02:00
|
|
|
},
|
|
|
|
|
2013-12-31 02:43:07 +01:00
|
|
|
'getUserServer': function(server, nick, callback) {
|
|
|
|
if(!_.has(this.servStack, server)) this.servStack[server] = {};
|
|
|
|
this.servStack[server][nick] = callback;
|
|
|
|
dbot.instance.connections[server].send('WHOIS ' + nick);
|
|
|
|
setTimeout(function() {
|
|
|
|
if(_.has(this.servStack[server], nick)) {
|
|
|
|
callback(false);
|
|
|
|
}
|
|
|
|
}.bind(this), 6000);
|
|
|
|
},
|
|
|
|
|
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-06-10 18:13:30 +02:00
|
|
|
setTimeout(function() {
|
2013-08-26 01:04:46 +02:00
|
|
|
if(_.has(this.userStack[server], nick)) {
|
2018-02-22 18:45:04 +01:00
|
|
|
dbot.instance.connections[server].send('WHOWAS ' + nick + ' 1');
|
2013-08-26 01:04:46 +02:00
|
|
|
setTimeout(function() {
|
|
|
|
if(_.has(this.userStack[server], nick)) {
|
|
|
|
callback(false);
|
|
|
|
}
|
2018-02-22 18:45:04 +01:00
|
|
|
}.bind(this), 2000);
|
2013-08-26 01:04:46 +02:00
|
|
|
}
|
2013-08-26 00:56:19 +02:00
|
|
|
}.bind(this), 4000);
|
2013-04-23 20:48:41 +02:00
|
|
|
}
|
|
|
|
};
|
2015-07-24 03:02:21 +02:00
|
|
|
this.api['auth'].external = true;
|
|
|
|
this.api['auth'].extMap = [ 'server', 'nick', 'callback' ];
|
2013-04-23 20:48:41 +02:00
|
|
|
|
2013-06-27 20:06:49 +02:00
|
|
|
this.commands = {
|
|
|
|
'~auth': function(event) {
|
|
|
|
var user = event.params[1] || event.user;
|
2013-10-20 18:16:21 +02:00
|
|
|
this.api.auth(event.server, user, function(isAuthed, account) {
|
2013-06-27 20:06:49 +02:00
|
|
|
if(isAuthed) {
|
2013-10-20 18:16:21 +02:00
|
|
|
if(user == account) {
|
|
|
|
event.reply(dbot.t('authed', { 'nick': user }));
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('authed_as', {
|
|
|
|
'nick': user,
|
|
|
|
'account': account
|
|
|
|
}));
|
|
|
|
}
|
2013-06-27 20:06:49 +02:00
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('not_authed', { 'nick': user }));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
'~hostmask': function(event) {
|
|
|
|
var user = event.params[1] || event.user;
|
|
|
|
this.api.getUserHost(event.server, user, function(host) {
|
|
|
|
if(host) {
|
|
|
|
event.reply(dbot.t('hostmask', {
|
|
|
|
'nick': user,
|
|
|
|
'host': host
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('no_hostmask', { 'nick': user }));
|
|
|
|
}
|
|
|
|
});
|
2013-12-31 02:43:07 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
'~server': function(event) {
|
|
|
|
var user = event.params[1] || event.user;
|
|
|
|
this.api.getUserServer(event.server, user, function(server) {
|
|
|
|
if(server) {
|
|
|
|
event.reply(user + ' is on ' + server);
|
|
|
|
} else {
|
|
|
|
event.reply('We don\'t know who ' + user + ' is.');
|
|
|
|
}
|
|
|
|
});
|
2013-06-27 20:06:49 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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) {
|
2017-07-11 16:21:59 +02:00
|
|
|
var info = event.message.match(statusRegex);
|
2013-06-09 18:05:19 +02:00
|
|
|
if(info && _.has(this.authStack, event.server)) {
|
2013-10-20 18:16:21 +02:00
|
|
|
if(info[3] == acceptableState) {
|
|
|
|
this.authStack[event.server][info[1]](true, info[2]);
|
2013-06-09 18:05:19 +02:00
|
|
|
} else {
|
2013-10-20 18:37:46 +02:00
|
|
|
this.authStack[event.server][info[1]](false, info[2]);
|
2013-06-09 18:05:19 +02:00
|
|
|
}
|
2013-04-23 20:48:41 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-09 18:05:19 +02:00
|
|
|
} else if(event.action == '302') {
|
2017-07-11 16:21:59 +02:00
|
|
|
var match = event.message.match(/(.+)=([^@]+)@(.+)$/);
|
2013-06-09 19:51:49 +02:00
|
|
|
|
2013-08-26 01:09:34 +02:00
|
|
|
if(match && 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-07-05 00:44:19 +02:00
|
|
|
var callback = this.userStack[event.server][match[1]];
|
2013-06-10 18:13:30 +02:00
|
|
|
delete this.userStack[event.server][match[1]];
|
2013-07-05 00:44:19 +02:00
|
|
|
callback(match[3].trim());
|
2013-06-09 18:55:46 +02:00
|
|
|
}
|
2013-08-26 01:04:46 +02:00
|
|
|
} else if(event.action == '314') {
|
2017-07-11 16:21:59 +02:00
|
|
|
var params = event.message.split(' '),
|
2013-08-26 01:04:46 +02:00
|
|
|
nick = params[1],
|
|
|
|
host = params[3];
|
|
|
|
|
|
|
|
if(_.has(this.userStack, event.server) && _.has(this.userStack[event.server], nick)) {
|
|
|
|
var callback = this.userStack[event.server][nick];
|
|
|
|
delete this.userStack[event.server][nick];
|
|
|
|
callback(host);
|
|
|
|
}
|
2018-02-22 18:30:15 +01:00
|
|
|
} else if(event.action == '338') {
|
2017-07-11 16:21:59 +02:00
|
|
|
var params = event.message.split(' '),
|
2018-02-22 18:45:04 +01:00
|
|
|
user = event.args[1],
|
|
|
|
host = event.args[2];
|
2013-12-31 02:43:07 +01:00
|
|
|
|
2018-02-22 18:45:04 +01:00
|
|
|
if(_.has(this.userStack, event.server) && _.has(this.userStack[event.server], user)) {
|
|
|
|
var callback = this.userStack[event.server][user];
|
|
|
|
delete this.userStack[event.server][user];
|
|
|
|
callback(host);
|
2013-12-31 02:43:07 +01:00
|
|
|
}
|
2013-04-23 20:48:41 +02:00
|
|
|
}
|
|
|
|
}.bind(this);
|
2018-02-22 18:30:15 +01:00
|
|
|
this.on = ['NOTICE', '302', '314', '338'];
|
2013-04-23 20:48:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return new nickserv(dbot);
|
|
|
|
};
|