2013-06-23 13:37:01 +02:00
|
|
|
var _ = require('underscore')._,
|
|
|
|
async = require('async');
|
2013-06-19 02:06:52 +02:00
|
|
|
|
|
|
|
var pages = function(dbot) {
|
2013-06-19 22:00:35 +02:00
|
|
|
this.warnings = dbot.db.warnings;
|
|
|
|
|
2013-06-19 02:06:52 +02:00
|
|
|
return {
|
2013-06-19 22:00:35 +02:00
|
|
|
'/warning': function(req, res) {
|
|
|
|
res.render('servers', {
|
2013-06-19 02:06:52 +02:00
|
|
|
'name': dbot.config.name,
|
2013-06-23 13:37:01 +02:00
|
|
|
'servers': _.keys(dbot.config.servers)
|
2013-06-19 02:06:52 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-06-19 22:00:35 +02:00
|
|
|
'/warning/:server': function(req, res) {
|
2013-06-23 13:37:01 +02:00
|
|
|
var server = req.params.server,
|
|
|
|
userIds = [],
|
|
|
|
userNicks = [];
|
2013-06-19 02:06:52 +02:00
|
|
|
|
2013-06-23 13:37:01 +02:00
|
|
|
this.db.search('warnings', { 'server': server }, function(warning) {
|
|
|
|
if(!_.include(userIds, warning.warnee)) userIds.push(warning.warnee);
|
|
|
|
}, function(err) {
|
|
|
|
async.eachSeries(userIds, function(id, callback) {
|
|
|
|
dbot.api.users.getUser(id, function(user) {
|
|
|
|
userNicks.push(user.primaryNick);
|
|
|
|
callback(false);
|
|
|
|
});
|
|
|
|
}, function(err) {
|
|
|
|
res.render('users', {
|
|
|
|
'name': dbot.config.name,
|
|
|
|
'server': server,
|
|
|
|
'users': userNicks
|
|
|
|
});
|
2013-06-19 02:06:52 +02:00
|
|
|
});
|
2013-06-23 13:37:01 +02:00
|
|
|
});
|
2013-06-19 02:06:52 +02:00
|
|
|
},
|
|
|
|
|
2013-06-19 22:00:35 +02:00
|
|
|
'/warning/:server/:user': function(req, res) {
|
2013-06-19 02:06:52 +02:00
|
|
|
var server = req.params.server,
|
|
|
|
user = req.params.user;
|
|
|
|
|
2013-06-23 13:37:01 +02:00
|
|
|
dbot.api.users.resolveUser(server, user, function(user) {
|
|
|
|
var warnings = [];
|
|
|
|
this.db.search('warnings', {
|
2013-06-19 22:00:35 +02:00
|
|
|
'server': server,
|
2013-06-23 13:37:01 +02:00
|
|
|
'warnee': user.id
|
|
|
|
}, function(warning) {
|
|
|
|
warnings.push(warning);
|
|
|
|
}, function(err) {
|
|
|
|
async.eachSeries(warnings, function(warning, callback) {
|
|
|
|
dbot.api.users.getUser(warning.warner, function(user) {
|
|
|
|
warning.warner = user.primaryNick;
|
|
|
|
callback(false);
|
|
|
|
});
|
|
|
|
}, function(err) {
|
|
|
|
res.render('warnings', {
|
|
|
|
'name': dbot.config.name,
|
|
|
|
'server': server,
|
|
|
|
'warnings': warnings
|
|
|
|
});
|
|
|
|
});
|
2013-06-19 02:06:52 +02:00
|
|
|
});
|
2013-06-23 13:37:01 +02:00
|
|
|
}.bind(this));
|
2013-06-19 02:06:52 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return pages(dbot);
|
|
|
|
};
|