1
0
Fork 0
mirror of synced 2024-06-28 19:20:34 +12:00

Corrected some error checking on lookups

This commit is contained in:
Phxntxm 2016-08-19 18:32:24 -05:00
parent 4ce7340600
commit 846b29c1f3

View file

@ -92,7 +92,7 @@ class Steam:
Option can be achievements, games, info and will default to info"""
# Get the user's steam id if it exists
try:
steam_id = config.get_content('steam_users').get(ctx.message.author.id).get('steam_id')
steam_id = config.get_content('steam_users').get(member.id).get('steam_id')
except AttributeError:
await self.bot.say("Sorry, but I don't have that user's steam account saved!")
return
@ -155,12 +155,19 @@ class Steam:
fmt_string = "\n".join("{}: {}".format(key, value) for key, value in fmt.items() if value)
await self.bot.say("```\n{}```".format(fmt_string))
elif option[0] == 'achievements':
# First ensure that the profile is not private
# First ensure that the profile is not private, and the user has played it before
if not data['playerstats']['success']:
await self.bot.say("Sorry, {} has a private steam account! I cannot lookup their achievements!")
if data['playerstats']['error'] == "Requested app has no stats":
await self.bot.say("{} has no achievements on the game {}".format(member.display_name, game))
elif data['playerstats']['error'] == "Profile is not public"
await self.bot.say("Sorry, {} has a private steam account! I cannot lookup their achievements!".format(member.display_name))
return
# Get all achievements for this game, making sure they actually exist
try:
all_achievements = data['playerstats']['achievements']
except KeyError:
await self.bot.say("Sorry, the game {} has no achievements!".format(game))
return
# Get all achievements for this game
all_achievements = data['playerstats']['achievements']
# Now get all achievements that the user has achieved
successful_achievements = [data for data in all_achievements if data['achieved'] == 1]
await self.bot.say("{} has achieved {}/{} achievements on the game {}".format(member.display_name, len(successful_achievements), len(all_achievements), game))