3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-26 20:52:39 +01:00
dbot/modules/users/pages.js

75 lines
3.0 KiB
JavaScript
Raw Normal View History

2013-01-07 13:27:24 +01:00
var pages = function(dbot) {
var _ = require('underscore')._;
2013-01-09 06:53:45 +01:00
var connections = dbot.instance.connections;
2013-01-07 13:27:24 +01:00
return {
'/connections': function(req, res) {
var connections = Object.keys(dbot.instance.connections);
res.render('connections', { 'name': dbot.config.name, 'connections': connections });
},
'/channels/:connection': function(req, res) {
var connection = req.params.connection;
if(dbot.instance.connections.hasOwnProperty(connection)) {
var channels = Object.keys(dbot.instance.connections[connection].channels);
res.render('channels', { 'name': dbot.config.name, 'connection': connection, 'channels': channels});
} else {
res.render_core('error', { 'name': dbot.config.name, 'message': 'No such connection.' });
}
},
'/users/:connection/:channel': function(req, res) {
var connection = req.params.connection;
var channel = _.unescape(req.params.channel);
2013-01-07 13:27:24 +01:00
var connections = dbot.instance.connections;
if(connections.hasOwnProperty(connection) &&
connections[connection].channels.hasOwnProperty(channel)) {
var userData = { "active": [], "inactive": [], "offline": []};
var reply = dbot.api.stats.getChanUsersStats(connection, channel, [
"lines", "words", "lincent", "wpl", "in_mentions"
]);
_.each(reply.users, function(user, userName){
if(userName != dbot.config.name){
if(user.online){
if(user.active){
userData.active.push(user);
}
else{
userData.inactive.push(user);
}
}
else{
userData.offline.push(user);
}
}
});
var userSort = function(a, b){
2013-01-11 23:39:32 +01:00
var x = a.display.toLowerCase();
var y = b.display.toLowerCase();
if(x > y) return 1;
if(x < y) return -1;
return 0;
}
userData.active.sort(userSort);
userData.inactive.sort(userSort);
userData.offline.sort(userSort);
2013-01-15 21:44:15 +01:00
var userDataSorted = (userData.active.concat(userData.inactive)).concat(userData.offline);
2013-01-07 13:27:24 +01:00
res.render('users', { 'name': dbot.config.name, 'connection': connection,
2013-01-15 21:44:15 +01:00
'channel': channel, 'nicks': userDataSorted });
2013-01-07 13:27:24 +01:00
} else {
res.render_core('error', { 'name': dbot.config.name, 'message': 'No such connection or channel.' });
}
},
};
};
exports.fetch = function(dbot) {
2013-01-07 13:27:24 +01:00
return pages(dbot);
};