3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 22:39:26 +01:00
dbot/modules/profile/pages.js

90 lines
3.3 KiB
JavaScript
Raw Normal View History

var pages = function(dbot) {
var _ = require('underscore')._;
var connections = dbot.instance.connections;
return {
'/profile/:connection/:user': function(req, res) {
var connection = req.params.connection;
var nick = req.params.user;
dbot.api.users.resolveUser(connection, nick, function(user){
if(user){
dbot.api.profile.getProfile(connection, user.primaryNick, function(err, user, profile){
if(!err){
var stats = [];
/*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-24 02:02:50 +01:00
},
2013-01-24 20:39:28 +01:00
'/profile/:connection': function(req, res) {
dbot.api.profile.getAllProfiles(function(profiles){
var thumbnails = [];
_.each(profiles, function(profile){
var nick = dbot.api.users.getUser(profile.id, function(user){
if(user){
2013-01-24 02:02:50 +01: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-01-25 01:40:42 +01: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
res.render('profile_grid', {
'name': dbot.config.name,
'connection': req.params.connection,
'thumbnails': thumbnails,
});
});
2013-01-24 02:02:50 +01:00
});
}
}
};
exports.fetch = function(dbot) {
return pages(dbot);
};