3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-04 18:09:30 +01:00
This commit is contained in:
reality 2013-08-24 17:39:04 +00:00
parent 16607a68d2
commit ec72489300
2 changed files with 53 additions and 13 deletions

View File

@ -1,20 +1,46 @@
var _ = require('underscore')._; var _ = require('underscore')._,
async = require('async');
var pages = function(dbot) { var pages = function(dbot) {
var pages = { var pages = {
'/notify': function(req, res) { '/notify': function(req, res) {
res.render('servers', { res.render('servers', {
'name': dbot.config.name,
'servers': _.keys(dbot.config.servers) 'servers': _.keys(dbot.config.servers)
}); });
}, },
'/notify/:server': function(req, res) { '/notify/:server': function(req, res) {
var server = req.params.server; var server = req.params.server,
res.render('channels', { userCount = {},
'name': dbot.config.name, users = [];
'server': server,
'channels': _.keys(dbot.instance.connections[server].channels) this.db.scan('notifies', function(notify) {
if(!_.has(userCount, notify.user)) {
userCount[notify.user] = 0;
} else {
userCount[notify.user]++;
}
}, function() {
userCount = _.map(userCount, function(value, key) {
return {
'id': key,
'count': value
}
});
async.eachSeries(userCount, function(userCount, next) {
dbot.api.users.getUser(userCount.id, function(user) {
userCount['name'] = user.primaryNick;
users.push(userCount);
next();
});
}, function() {
res.render('channels', {
'server': server,
'users': users,
'channels': _.keys(dbot.instance.connections[server].channels)
});
});
}); });
}, },
@ -23,8 +49,9 @@ var pages = function(dbot) {
user = req.user, user = req.user,
notifies = this.pending[user.id]; notifies = this.pending[user.id];
async.eachSeries
res.render('missing_notifies', { res.render('missing_notifies', {
'name': dbot.config.name,
'user': user.primaryNick, 'user': user.primaryNick,
'notifies': _.sortBy(notifies, 'time') 'notifies': _.sortBy(notifies, 'time')
}); });
@ -46,10 +73,23 @@ var pages = function(dbot) {
}, function(notify) { }, function(notify) {
notifies.push(notify); notifies.push(notify);
}, function(err) { }, function(err) {
res.render('notifies', { var pNickCache = {};
'name': dbot.config.name, async.eachSeries(notifies, function(notify, next) {
'server': server, if(!_.has(pNickCache, notify.user)) {
'notifies': _.sortBy(notifies, 'time') dbot.api.users.getUser(notify.user, function(user) {
pNickCache[notify.user] = user.primaryNick;
notify.user = user.primaryNick;
next();
});
} else {
notify.user = pNickCache[notify.user];
next();
}
}, function() {
res.render('notifies', {
'server': server,
'notifies': _.sortBy(notifies, 'time')
});
}); });
}); });
} }

View File

@ -139,7 +139,7 @@ var report = function(dbot) {
'id': id, 'id': id,
'server': event.server, 'server': event.server,
'channel': channelName, 'channel': channelName,
'user': event.user, 'user': event.rUser.id,
'time': new Date().getTime(), 'time': new Date().getTime(),
'message': message 'message': message
}, function() {}); }, function() {});