2013-01-22 21:44:45 +01:00
|
|
|
var pages = function(dbot) {
|
|
|
|
var _ = require('underscore')._;
|
|
|
|
var connections = dbot.instance.connections;
|
|
|
|
|
|
|
|
return {
|
|
|
|
'/profile/:connection/:user': function(req, res) {
|
|
|
|
var connection = req.params.connection;
|
2013-04-20 23:51:36 +02:00
|
|
|
var nick = req.params.user;
|
2013-01-22 21:44:45 +01:00
|
|
|
|
2014-09-04 16:48:20 +02:00
|
|
|
dbot.api.users.resolveUser(connection, nick, function(err, user){
|
2013-04-20 23:51:36 +02:00
|
|
|
if(user){
|
|
|
|
dbot.api.profile.getProfile(connection, user.primaryNick, function(err, user, profile){
|
|
|
|
if(!err){
|
|
|
|
var stats = [];
|
2013-01-22 21:44:45 +01:00
|
|
|
|
2013-04-20 23:51:36 +02:00
|
|
|
/*TODO(@samstudio8)
|
|
|
|
* stats functionality currently disabled as it has not been databanked
|
|
|
|
*/
|
|
|
|
//var stats = dbot.api.stats.getUserChansStats(connection, user.primaryNick, [
|
|
|
|
// "lines", "words", "lincent", "wpl", "in_mentions"]
|
|
|
|
//);
|
|
|
|
|
|
|
|
res.render('profile', {
|
|
|
|
'name': dbot.config.name,
|
|
|
|
'connection': connection,
|
|
|
|
'primary': user.primaryNick,
|
|
|
|
'profile': profile.profile,
|
|
|
|
'stats': stats.channels,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
res.render('error', {
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
res.render('not_found', {
|
|
|
|
});
|
|
|
|
}
|
2013-01-22 21:44:45 +01:00
|
|
|
});
|
2013-01-24 02:02:50 +01:00
|
|
|
},
|
|
|
|
|
2013-01-24 20:39:28 +01:00
|
|
|
'/profile/:connection': function(req, res) {
|
2013-04-20 23:51:36 +02:00
|
|
|
dbot.api.profile.getAllProfiles(function(profiles){
|
|
|
|
var thumbnails = [];
|
|
|
|
_.each(profiles, function(profile){
|
2014-09-04 16:48:20 +02:00
|
|
|
var nick = dbot.api.users.getUser(profile.id, function(err, user){
|
2013-04-20 23:51:36 +02:00
|
|
|
if(user){
|
2013-01-24 02:02:50 +01:00
|
|
|
|
2013-04-20 23:51:36 +02:00
|
|
|
/*TODO(@tmenari / @samstudio8)
|
|
|
|
* if username has a quote array and no avatar:
|
|
|
|
* search their quote array for a jpg, png, jpeg or gif
|
|
|
|
* set this as their new avatar
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(profile.profile.avatar){
|
|
|
|
thumbnails.push({
|
|
|
|
"avatar": profile.profile.avatar,
|
|
|
|
"nick": user.primaryNick
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 01:40:42 +01:00
|
|
|
});
|
2013-04-20 23:51:36 +02:00
|
|
|
});
|
2013-01-25 01:40:42 +01:00
|
|
|
|
2013-04-20 23:51:36 +02:00
|
|
|
process.nextTick(function(){
|
|
|
|
thumbnails.sort(function(a, b) {
|
|
|
|
var x = a.nick.toLowerCase();
|
|
|
|
var y = b.nick.toLowerCase();
|
|
|
|
if(x > y) return 1;
|
|
|
|
if(x < y) return -1;
|
|
|
|
return 0;
|
|
|
|
});
|
2013-01-25 01:46:25 +01:00
|
|
|
|
2013-04-20 23:51:36 +02:00
|
|
|
res.render('profile_grid', {
|
|
|
|
'name': dbot.config.name,
|
|
|
|
'connection': req.params.connection,
|
|
|
|
'thumbnails': thumbnails,
|
|
|
|
});
|
|
|
|
});
|
2013-01-24 02:02:50 +01:00
|
|
|
});
|
2013-01-22 21:44:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return pages(dbot);
|
|
|
|
};
|