From 5541981d4ea063a424a5c1603dd4183d2ef197c4 Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 29 Oct 2013 20:30:50 +0000 Subject: [PATCH] whats all this then ~scrobbliest --- modules/lastfm/lastfm.js | 43 ++++++++++++++++++++++++++++++++++++- modules/lastfm/strings.json | 3 +++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/modules/lastfm/lastfm.js b/modules/lastfm/lastfm.js index 4503c67..8c7501a 100644 --- a/modules/lastfm/lastfm.js +++ b/modules/lastfm/lastfm.js @@ -126,7 +126,7 @@ var lastfm = function(dbot) { 'json': true }, function(err, res, body) { if(_.has(body, 'error') && body.error == 6 || body.error == 7) { - callback('no_user', user, null); + callback('no_user', null); } else if(_.has(body, 'user')) { callback(null, body.user); } 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) { this.api.getListening(event.rProfile.lastfm, function(err, track) { if(!err) { diff --git a/modules/lastfm/strings.json b/modules/lastfm/strings.json index dfdf3e6..6fed390 100644 --- a/modules/lastfm/strings.json +++ b/modules/lastfm/strings.json @@ -19,5 +19,8 @@ }, "lfm_profile": { "en": "{user} has played {plays} tracks since {date} - {link}" + }, + "lfm_scrobbliest": { + "en": "Users with most plays: " } }