forked from GitHub/dbot
games command
This commit is contained in:
parent
e8c0d54b02
commit
055e865628
@ -77,53 +77,108 @@ var steam = function(dbot) {
|
|||||||
callback(true, null);
|
callback(true, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
'getLibrary': function(steamid, callback) {
|
||||||
|
request.get(this.ApiRoot + 'IPlayerService/GetOwnedGames/v0001/', {
|
||||||
|
'qs': {
|
||||||
|
'key': this.config.api_key,
|
||||||
|
'steamid': steamid,
|
||||||
|
'format': 'json',
|
||||||
|
'include_appinfo': 1
|
||||||
|
},
|
||||||
|
'json': true
|
||||||
|
}, function(err, res, body) {
|
||||||
|
if(_.has(body, 'response') && _.has(body.response, 'game_count')) {
|
||||||
|
callback(null, body.response);
|
||||||
|
} else {
|
||||||
|
callback(true, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.commands = {
|
this.commands = {
|
||||||
|
'~games': function(event) {
|
||||||
|
var u1 = event.rUser,
|
||||||
|
s1 = event.rProfile.sid,
|
||||||
|
u2 = event.res[0].user,
|
||||||
|
s2 = event.res[0].sid;
|
||||||
|
|
||||||
|
this.api.getLibrary(s1, function(err, l1) {
|
||||||
|
if(!err) {
|
||||||
|
this.api.getLibrary(s2, function(err, l2) {
|
||||||
|
if(!err) {
|
||||||
|
var g1 = _.pluck(l1.games, 'name'),
|
||||||
|
g2 = _.pluck(l2.games, 'name'),
|
||||||
|
common = _.filter(g1, function(game) {
|
||||||
|
return _.include(g2, game);
|
||||||
|
}),
|
||||||
|
examples = [];
|
||||||
|
_.times(5, function() {
|
||||||
|
var choice = _.random(0, common.length - 1);
|
||||||
|
if(!_.include(examples, common[choice])) {
|
||||||
|
examples.push(common[choice]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
event.reply(dbot.t('steam_games', {
|
||||||
|
'u1': u1.currentNick,
|
||||||
|
'u2': u2.currentNick,
|
||||||
|
'count': common.length,
|
||||||
|
'examples': examples.join(', ')
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
event.reply('Unable to fetch steam library :\'(');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
event.reply('Unable to fetch steam library :\'(');
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
'~game': function(event) {
|
'~game': function(event) {
|
||||||
var user = event.rUser,
|
var user = event.rUser,
|
||||||
snick = event.rProfile.steam;
|
snick = event.rProfile.steam,
|
||||||
|
sid = event.rProfile.sid;
|
||||||
if(event.res[0]) {
|
if(event.res[0]) {
|
||||||
user = event.res[0].user;
|
user = event.res[0].user;
|
||||||
snick = event.res[0].snick;
|
snick = event.res[0].snick;
|
||||||
|
sid = event.res[0].sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.api.getSteamID(snick, function(err, steamid) {
|
this.api.getProfile(sid, function(err, player) {
|
||||||
this.api.getProfile(steamid, function(err, player) {
|
if(!err && player) {
|
||||||
if(!err && player) {
|
if(_.has(player, 'gameextrainfo')) {
|
||||||
if(_.has(player, 'gameextrainfo')) {
|
var output = dbot.t('steam_currently_playing', {
|
||||||
var output = dbot.t('steam_currently_playing', {
|
'user': user.currentNick,
|
||||||
'user': user.currentNick,
|
'game': player.gameextrainfo
|
||||||
'game': player.gameextrainfo
|
});
|
||||||
});
|
if(_.has(player, 'gameserverip')) {
|
||||||
if(_.has(player, 'gameserverip')) {
|
var host = player.gameserverip.split(':');
|
||||||
var host = player.gameserverip.split(':');
|
output += ' (Server: ' + host[0] + ' Port: ' + host[1] + ')';
|
||||||
output += ' (Server: ' + host[0] + ' Port: ' + host[1] + ')';
|
|
||||||
}
|
|
||||||
event.reply(output);
|
|
||||||
} else {
|
|
||||||
this.api.getRecentlyPlayed(steamid, function(err, games) {
|
|
||||||
if(!err) {
|
|
||||||
if(games.total_count != 0) {
|
|
||||||
event.reply(dbot.t('steam_last_played', {
|
|
||||||
'user': user.currentNick,
|
|
||||||
'game': games.games[0].name
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
event.reply(dbot.t('steam_not_played', {
|
|
||||||
'user': user.currentNick
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
event.reply('Unknown Steam Username');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
event.reply(output);
|
||||||
} else {
|
} else {
|
||||||
event.reply('Unknown Steam Username');
|
this.api.getRecentlyPlayed(sid, function(err, games) {
|
||||||
|
if(!err) {
|
||||||
|
if(games.total_count != 0) {
|
||||||
|
event.reply(dbot.t('steam_last_played', {
|
||||||
|
'user': user.currentNick,
|
||||||
|
'game': games.games[0].name
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
event.reply(dbot.t('steam_not_played', {
|
||||||
|
'user': user.currentNick
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
event.reply('Unknown Steam Username');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -131,26 +186,41 @@ var steam = function(dbot) {
|
|||||||
_.each(this.commands, function(command) {
|
_.each(this.commands, function(command) {
|
||||||
command.resolver = function(event, callback) {
|
command.resolver = function(event, callback) {
|
||||||
if(event.rProfile && _.has(event.rProfile, 'steam')) {
|
if(event.rProfile && _.has(event.rProfile, 'steam')) {
|
||||||
if(event.params[1]) {
|
this.api.getSteamID(event.rProfile.steam, function(err, sid) {
|
||||||
this.internalAPI.getSteam(event.server, event.params[1], function(user, snick) {
|
if(!err) {
|
||||||
if(user && snick) {
|
event.rProfile.sid = sid; // oh god ew
|
||||||
event.res.push({
|
if(event.params[1]) {
|
||||||
'user': user,
|
this.internalAPI.getSteam(event.server, event.params[1], function(user, snick) {
|
||||||
'snick': snick
|
if(user && snick) {
|
||||||
});
|
this.api.getSteamID(snick, function(err, sid) {
|
||||||
callback(false);
|
if(!err) {
|
||||||
|
event.res.push({
|
||||||
|
'user': user,
|
||||||
|
'snick': snick,
|
||||||
|
'sid': sid
|
||||||
|
});
|
||||||
|
callback(false);
|
||||||
|
} else {
|
||||||
|
event.reply('Unknown Steam ID');
|
||||||
|
callback(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if(!user) {
|
||||||
|
event.reply('Unknown user.');
|
||||||
|
} else {
|
||||||
|
event.reply(user.currentNick + ': Set a steam "vanity url" with "~set steam username"');
|
||||||
|
}
|
||||||
|
callback(true);
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
} else {
|
} else {
|
||||||
if(!user) {
|
callback(false);
|
||||||
event.reply('Unknown user.');
|
|
||||||
} else {
|
|
||||||
event.reply(user.currentNick + ': Set a steam "vanity url" with "~set steam username"');
|
|
||||||
}
|
|
||||||
callback(true);
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
} else {
|
event.reply('Unknown Steam ID');
|
||||||
callback(false);
|
}
|
||||||
}
|
}.bind(this));
|
||||||
} else {
|
} else {
|
||||||
event.reply(event.user + ': Set a steam "vanity url" with "~set steam username"');
|
event.reply(event.user + ': Set a steam "vanity url" with "~set steam username"');
|
||||||
callback(true);
|
callback(true);
|
||||||
|
@ -7,5 +7,8 @@
|
|||||||
},
|
},
|
||||||
"steam_currently_playing": {
|
"steam_currently_playing": {
|
||||||
"en": "{user} is currently playing {game}"
|
"en": "{user} is currently playing {game}"
|
||||||
|
},
|
||||||
|
"steam_games": {
|
||||||
|
"en": "{u1} and {u2} have {count} games in common, including: {examples}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user