From 130113db50722d962eeaf2a44ce98b7d0a243eac Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 31 Dec 2013 01:43:07 +0000 Subject: [PATCH] ~server --- modules/nickserv/nickserv.js | 39 +++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/modules/nickserv/nickserv.js b/modules/nickserv/nickserv.js index 0511a83..26e84f6 100644 --- a/modules/nickserv/nickserv.js +++ b/modules/nickserv/nickserv.js @@ -3,6 +3,7 @@ var _ = require('underscore')._; var nickserv = function(dbot) { this.authStack = {}; this.userStack = {}; + this.servStack = {}; this.api = { 'auth': function(server, nick, callback) { @@ -14,6 +15,17 @@ var nickserv = function(dbot) { dbot.say(server, nickserv, infoCommand + ' ' + nick + ' *'); }, + '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); + }, + 'getUserHost': function(server, nick, callback) { if(!_.has(this.userStack, server)) this.userStack[server] = {}; this.userStack[server][nick] = callback; @@ -62,6 +74,17 @@ var nickserv = function(dbot) { event.reply(dbot.t('no_hostmask', { 'nick': user })); } }); + }, + + '~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.'); + } + }); } }; @@ -100,9 +123,23 @@ var nickserv = function(dbot) { delete this.userStack[event.server][nick]; callback(host); } + } else if(event.action == '312') { + var params = event.params.split(' '), + user = params[1], + server = params[2]; + + console.log(user); + console.log(server); + console.log(this.servStack); + + if(_.has(this.servStack, event.server) && _.has(this.servStack[event.server], user)) { + var callback = this.servStack[event.server][user]; + delete this.servStack[event.server][user]; + callback(server); + } } }.bind(this); - this.on = ['NOTICE', '302', '314']; + this.on = ['NOTICE', '302', '314', '312']; }; exports.fetch = function(dbot) {