From 5560f967440cdb05f81de77026aadfee56b92616 Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 14 Sep 2014 19:02:45 +0000 Subject: [PATCH] get users with given vhost --- modules/atheme/atheme.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index ba8ddcd..fc81d76 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -6,6 +6,7 @@ var _ = require('underscore')._; var atheme = function(dbot) { this.flagStack = {}; + this.hostStack = {}; this.api = { 'getChannelFlags': function(server, channel, callback) { @@ -28,6 +29,28 @@ var atheme = function(dbot) { delete this.flagStack[server][channel]; } }.bind(this), 10000); + }, + + 'getVHosts': function(server, mask, callback) { + if(!_.has(this.hostStack, server)) this.hostStack[server] = {}; + if(_.has(this.hostStack[server], mask)) { // Already an active host call + this.hostStack[server][channel].callbacks.push(callback); + } else { + this.hostStack[server][mask] = { + 'users': [], + 'callbacks': [ callback ] + }; + } + + dbot.say(server, 'hostserv', 'LISTVHOST ' + mask); + setTimeout(function() { // Delete callback if no response + if(_.has(this.hostStack[server], mask)) { + _.each(this.hostStack[server][mask].callbacks, function(callback) { + callback(true, null); + }); + delete this.hostStack[server][mask]; + } + }.bind(this), 10000); } }; @@ -66,6 +89,22 @@ var atheme = function(dbot) { delete this.flagStack[event.server][end[1]]; } } + } else if(event.user === 'HostServ') { + _.each(this.hostStack[event.server], function(el, mask) { + if(event.params.match(mask)) { + var user = event.params.match(/- ([^ ]+)/), + end = event.params.match(/matches for pattern/); + + if(user) { + this.hostStack[event.server][mask].users.push(user[1]); + } else if(end) { + _.each(this.hostStack[event.server][mask].callbacks, function(callback) { + callback(null, this.hostStack[event.server][mask].users); + }, this); + delete this.hostStack[event.server][mask]; + } + } + }, this); } }.bind(this); this.on = 'NOTICE';