2013-01-07 13:27:24 +01:00
|
|
|
var pages = function(dbot) {
|
2013-01-15 16:10:28 +01:00
|
|
|
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 {
|
2013-04-30 21:33:26 +02:00
|
|
|
'/users': function(req, res) {
|
2013-01-07 13:27:24 +01:00
|
|
|
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;
|
2013-01-21 20:22:52 +01:00
|
|
|
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)) {
|
2013-01-08 07:14:58 +01:00
|
|
|
|
2013-01-28 00:37:35 +01:00
|
|
|
//TODO(samstudio8): Stats API Functionality
|
|
|
|
var chanData = dbot.api.stats.getChanStats(connection, channel, ["week"]);
|
2013-01-24 23:17:56 +01:00
|
|
|
var chanFreq = [];
|
2013-01-28 00:37:35 +01:00
|
|
|
var chanFreqLabel = [];
|
2013-01-26 19:11:28 +01:00
|
|
|
|
|
|
|
if(chanData){
|
2013-01-28 00:37:35 +01:00
|
|
|
var cur_ptr;
|
2013-01-26 19:11:28 +01:00
|
|
|
for(var i=0; i <= 6; i++){
|
2013-01-28 00:37:35 +01:00
|
|
|
cur_ptr = ((i+1)+chanData.fields.week.raw.ptr) % 7;
|
2013-01-26 19:11:28 +01:00
|
|
|
for(var j=0; j <= 23; j++){
|
2013-01-28 00:37:35 +01:00
|
|
|
chanFreq.push(chanData.fields.week.raw[cur_ptr][j]);
|
2013-01-26 19:11:28 +01:00
|
|
|
}
|
2013-01-28 00:37:35 +01:00
|
|
|
chanFreqLabel.push("'"+chanData.fields.week.raw[cur_ptr].name+"'");
|
2013-01-24 23:17:56 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-26 19:11:28 +01:00
|
|
|
else{
|
|
|
|
for (var i = 0; i < 168; i++) chanFreq[i] = 0;
|
2013-01-28 00:37:35 +01:00
|
|
|
chanFreqLabel = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
2013-01-26 19:11:28 +01:00
|
|
|
}
|
2013-01-24 23:17:56 +01:00
|
|
|
|
2013-01-10 23:23:51 +01:00
|
|
|
var userData = { "active": [], "inactive": [], "offline": []};
|
2013-01-15 16:10:28 +01:00
|
|
|
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);
|
|
|
|
}
|
2013-01-10 23:23:51 +01:00
|
|
|
}
|
|
|
|
else{
|
2013-01-15 16:10:28 +01:00
|
|
|
userData.offline.push(user);
|
2013-01-10 23:23:51 +01:00
|
|
|
}
|
2013-01-08 07:14:58 +01:00
|
|
|
}
|
2013-01-15 16:10:28 +01:00
|
|
|
});
|
2013-01-10 23:23:51 +01:00
|
|
|
|
|
|
|
var userSort = function(a, b){
|
2013-01-11 23:39:32 +01:00
|
|
|
var x = a.display.toLowerCase();
|
|
|
|
var y = b.display.toLowerCase();
|
2013-01-10 23:23:51 +01:00
|
|
|
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-08 07:14:58 +01:00
|
|
|
|
2013-01-15 21:44:15 +01:00
|
|
|
var userDataSorted = (userData.active.concat(userData.inactive)).concat(userData.offline);
|
|
|
|
|
2013-01-24 23:17:56 +01:00
|
|
|
res.render('users', {
|
|
|
|
'name': dbot.config.name,
|
|
|
|
'connection': connection,
|
|
|
|
'channel': channel,
|
|
|
|
'userStats': userDataSorted,
|
|
|
|
'chanFreq': chanFreq,
|
2013-01-28 00:37:35 +01:00
|
|
|
'chanFreqLen': chanFreq.length,
|
|
|
|
"locals": {
|
|
|
|
'chanFreqLabel': chanFreqLabel,
|
|
|
|
}});
|
2013-01-24 23:17:56 +01:00
|
|
|
|
2013-01-07 13:27:24 +01:00
|
|
|
} else {
|
|
|
|
res.render_core('error', { 'name': dbot.config.name, 'message': 'No such connection or channel.' });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-01-15 14:58:13 +01:00
|
|
|
exports.fetch = function(dbot) {
|
2013-01-07 13:27:24 +01:00
|
|
|
return pages(dbot);
|
|
|
|
};
|