whats all this then ~scrobbliest

This commit is contained in:
reality 2013-10-29 20:30:50 +00:00
parent 9d7093e6f2
commit 5541981d4e
2 changed files with 45 additions and 1 deletions

View File

@ -126,7 +126,7 @@ var lastfm = function(dbot) {
'json': true 'json': true
}, function(err, res, body) { }, function(err, res, body) {
if(_.has(body, 'error') && body.error == 6 || body.error == 7) { if(_.has(body, 'error') && body.error == 6 || body.error == 7) {
callback('no_user', user, null); callback('no_user', null);
} else if(_.has(body, 'user')) { } else if(_.has(body, 'user')) {
callback(null, body.user); callback(null, body.user);
} else { } else {
@ -165,6 +165,47 @@ var lastfm = function(dbot) {
}); });
}, },
'~scrobbliest': function(event) {
dbot.api.profile.getAllProfilesWith('lastfm', function(profiles) {
if(profiles) {
var plays = [];
async.each(profiles, function(profile, done) {
this.api.getInfo(profile.profile.lastfm, function(err, lProfile) {
if(!err) {
plays.push({
'user': profile.id,
'plays': parseInt(lProfile.playcount)
});
}
done();
});
}.bind(this), function() {
var scrobbliest = _.chain(plays)
.sortBy(function(p) { return p.plays; })
.reverse()
.first(10)
.value();
async.each(scrobbliest, function(item, done) {
dbot.api.users.getUser(item.user, function(user) {
item.user = user;
done();
});
}, function() {
var output = dbot.t('lfm_scrobbliest');
_.each(scrobbliest, function(item) {
output += item.user.currentNick + ' (' +
item.plays.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")+ '), ';
});
event.reply(output.slice(0, -2));
});
}.bind(this));
} else {
event.reply('no suitable profiles');
}
}.bind(this));
},
'~suggestion': function(event) { '~suggestion': function(event) {
this.api.getListening(event.rProfile.lastfm, function(err, track) { this.api.getListening(event.rProfile.lastfm, function(err, track) {
if(!err) { if(!err) {

View File

@ -19,5 +19,8 @@
}, },
"lfm_profile": { "lfm_profile": {
"en": "{user} has played {plays} tracks since {date} - {link}" "en": "{user} has played {plays} tracks since {date} - {link}"
},
"lfm_scrobbliest": {
"en": "Users with most plays: "
} }
} }