mirror of
https://github.com/reality/dbot.git
synced 2024-12-24 11:42:36 +01:00
notify upgrades and whatnot
This commit is contained in:
parent
656861f6df
commit
403fd035a7
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
'getUser': function(uuid, callback) {
|
||||
this.db.read('users', uuid, function(err, user) {
|
||||
|
Loading…
Reference in New Issue
Block a user