notify upgrades and whatnot

This commit is contained in:
reality 2013-08-18 15:19:15 +00:00
parent 656861f6df
commit 403fd035a7
2 changed files with 37 additions and 10 deletions

View File

@ -8,6 +8,17 @@ var report = function(dbot) {
this.pending = dbot.db.pending; this.pending = dbot.db.pending;
this.pNotify = dbot.db.pNotify; 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 = { this.api = {
'notify': function(server, channel, message) { 'notify': function(server, channel, message) {
var channel = dbot.instance.connections[server].channels[channel]; var channel = dbot.instance.connections[server].channels[channel];
@ -30,7 +41,6 @@ var report = function(dbot) {
}); });
}, function() { }, function() {
offlineUsers = perOps; offlineUsers = perOps;
console.log(offlineUsers);
_.each(offlineUsers, function(id) { _.each(offlineUsers, function(id) {
if(!this.pending[id]) this.pending[id] = []; if(!this.pending[id]) this.pending[id] = [];
this.pending[id].push({ this.pending[id].push({
@ -39,19 +49,15 @@ var report = function(dbot) {
}); });
this.pNotify[id] = true; this.pNotify[id] = true;
}.bind(this)); }.bind(this));
this.internalAPI.notify(server, _.pluck(ops, 'name'), message);
}.bind(this)); }.bind(this));
} }
}.bind(this)); }.bind(this));
},
var i = 0; 'notifyUsers': function(server, users, message) {
var notifyChannel = function(ops) { this.internalAPI.notify(server, users, message);
if(i >= ops.length) return;
dbot.say(server, ops[i].name, message);
setTimeout(function() {
i++; notifyChannel(ops);
}, 1000);
};
notifyChannel(ops);
} }
}; };

View File

@ -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<pNicks.length;i++) {
var n = _.indexOf(nicks, pNicks[i]);
if(n != -1) {
users.push(result);
nicks = _.without(nicks, nicks[n]);
break;
}
}
}, function(err) {
if(!err) {
console.log(nicks);
callback(users, nicks);
}
});
},
// Return a user record given a UUID // Return a user record given a UUID
'getUser': function(uuid, callback) { 'getUser': function(uuid, callback) {
this.db.read('users', uuid, function(err, user) { this.db.read('users', uuid, function(err, user) {