From 403fd035a75e7b8a951edb7b9c3a783bac9999a9 Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 18 Aug 2013 15:19:15 +0000 Subject: [PATCH] notify upgrades and whatnot --- modules/report/report.js | 26 ++++++++++++++++---------- modules/users/api.js | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/modules/report/report.js b/modules/report/report.js index 1d4e88c..c20ea1c 100644 --- a/modules/report/report.js +++ b/modules/report/report.js @@ -8,6 +8,17 @@ var report = function(dbot) { this.pending = dbot.db.pending; this.pNotify = dbot.db.pNotify; + this.internalAPI = { + 'notify': function(server, users, message) { + async.eachSeries(users, function(nick, next) { + dbot.say(server, nick, message); + setTimeout(function() { + next(); + }, 1000); + }); + } + }; + this.api = { 'notify': function(server, channel, message) { var channel = dbot.instance.connections[server].channels[channel]; @@ -30,7 +41,6 @@ var report = function(dbot) { }); }, function() { offlineUsers = perOps; - console.log(offlineUsers); _.each(offlineUsers, function(id) { if(!this.pending[id]) this.pending[id] = []; this.pending[id].push({ @@ -39,19 +49,15 @@ var report = function(dbot) { }); this.pNotify[id] = true; }.bind(this)); + + this.internalAPI.notify(server, _.pluck(ops, 'name'), message); }.bind(this)); } }.bind(this)); + }, - var i = 0; - var notifyChannel = function(ops) { - if(i >= ops.length) return; - dbot.say(server, ops[i].name, message); - setTimeout(function() { - i++; notifyChannel(ops); - }, 1000); - }; - notifyChannel(ops); + 'notifyUsers': function(server, users, message) { + this.internalAPI.notify(server, users, message); } }; diff --git a/modules/users/api.js b/modules/users/api.js index c6fdae5..ab51e0e 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -25,6 +25,27 @@ var api = function(dbot) { }); }, + // Return many user records given primary nicks of aliases + 'resolveUsers': function(server, nicks, callback) { + var users = []; + this.db.search('users', { 'server': server }, function(result) { + var pNicks = result.aliases.slice(0).unshift(result.primaryNick); + for(var i=0;i