currently playing and server info

This commit is contained in:
reality 2013-10-28 14:38:35 +00:00
parent 70a2a77cc0
commit dc0785fe2e
2 changed files with 47 additions and 9 deletions

View File

@ -59,6 +59,23 @@ var steam = function(dbot) {
callback(true, null); callback(true, null);
} }
}); });
},
'getProfile': function(steamid, callback) {
request.get(this.ApiRoot + 'ISteamUser/GetPlayerSummaries/v0002/', {
'qs': {
'key': this.config.api_key,
'steamids': steamid,
'format': 'json'
},
'json': true
}, function(err, res, body) {
if(_.has(body, 'response') && _.has(body.response, 'players')) {
callback(null, body.response.players[0]);
} else {
callback(true, null);
}
});
} }
}; };
@ -72,6 +89,19 @@ var steam = function(dbot) {
} }
this.api.getSteamID(snick, function(err, steamid) { this.api.getSteamID(snick, function(err, steamid) {
this.api.getProfile(steamid, function(err, player) {
if(!err) {
if(_.has(player, 'gameextrainfo')) {
var output = dbot.t('steam_currently_playing', {
'user': user.currentNick,
'game': player.gameextrainfo
});
if(_.has(player, 'gameserverip')) {
var host = player.gameserverip.split(':');
output += ' (Host: ' + host[0] + ' Port: ' + host[1] + ')';
}
event.reply(output);
} else {
this.api.getRecentlyPlayed(steamid, function(err, games) { this.api.getRecentlyPlayed(steamid, function(err, games) {
if(!err) { if(!err) {
if(games.total_count != 0) { if(games.total_count != 0) {
@ -88,6 +118,11 @@ var steam = function(dbot) {
event.reply('something went wrong'); event.reply('something went wrong');
} }
}); });
}
} else {
event.reply('something went wrong');
}
}.bind(this));
}.bind(this)); }.bind(this));
} }
}; };

View File

@ -4,5 +4,8 @@
}, },
"steam_not_played": { "steam_not_played": {
"en": "{user} didn't play anything recently :'(" "en": "{user} didn't play anything recently :'("
},
"steam_currently_playing": {
"en": "{user} is currently playing {game}"
} }
} }