3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-18 08:32:42 +01:00
dbot/modules/warning/pages.js

79 lines
2.6 KiB
JavaScript
Raw Normal View History

var _ = require('underscore')._,
async = require('async');
var pages = function(dbot) {
this.warnings = dbot.db.warnings;
return {
'/warning': function(req, res) {
res.render('servers', {
'name': dbot.config.name,
'servers': _.keys(dbot.config.servers)
});
2014-10-21 17:08:55 +02:00
console.log('YE');
},
'/warning/:server': function(req, res) {
var server = req.params.server,
userIds = [],
userNicks = [];
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) {
2014-09-04 16:48:20 +02:00
dbot.api.users.getUser(id, function(err, user) {
2014-09-05 15:51:51 +02:00
if(user) {
userNicks.push(user.primaryNick);
} else {
userNicks.push(id);
}
callback(false);
});
}, function(err) {
res.render('users', {
'name': dbot.config.name,
'server': server,
'users': userNicks
});
});
});
},
2013-07-29 22:50:48 +02:00
'/warning/:server/:uid': function(req, res) {
var server = req.params.server,
2013-07-29 22:50:48 +02:00
user = req.params.uid;
2014-10-21 17:08:55 +02:00
console.log('YE YE');
2014-09-04 16:19:23 +02:00
dbot.api.users.resolveUser(server, user, function(err, user) {
var warnings = [];
2014-10-21 17:08:55 +02:00
if(user) {
this.db.search('warnings', {
'server': server,
'warnee': user.id
}, function(warning) {
warnings.push(warning);
}, function(err) {
async.eachSeries(warnings, function(warning, callback) {
2014-09-04 16:48:20 +02:00
dbot.api.users.getUser(warning.warner, function(err, user) {
warning.warner = user.primaryNick;
callback(false);
});
}, function(err) {
res.render('warnings', {
'name': dbot.config.name,
'server': server,
'warns': warnings
});
});
});
2014-10-21 17:08:55 +02:00
}
}.bind(this));
}
};
};
exports.fetch = function(dbot) {
return pages(dbot);
};