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

Corrected issue when no option is provided

This commit is contained in:
phxntxm 2016-08-20 00:13:13 -05:00
parent 92ca0831e0
commit 880fa0e17b

View file

@ -54,6 +54,8 @@ app_id_map = {"portal 2": 620,
"fallout 4": 377160,
"fallout new vegas": 22490
}
def get_app_id(game: str):
best_match = process.extractOne(game, app_id_map.keys())
if best_match[1] > 80:
@ -61,6 +63,7 @@ def get_app_id(game: str):
else:
return None
class Steam:
def __init__(self, bot):
self.bot = bot
@ -85,7 +88,6 @@ class Steam:
except ValueError:
return None
@commands.group(pass_context=True, invoke_without_command=True)
@checks.custom_perms(send_messages=True)
async def steam(self, ctx, member: discord.Member, *option: str):
@ -96,7 +98,8 @@ class Steam:
# First make sure the person requested isn't the bot
# Need to keep up the bot's sassy attitude, right?
if member == ctx.message.server.me:
await self.bot.say("I don't play video games anymore, I crushed everyone so badly I made everyone cry last time.")
await self.bot.say(
"I don't play video games anymore, I crushed everyone so badly I made everyone cry last time.")
return
# Get the user's steam id if it exists
try:
@ -125,11 +128,15 @@ class Steam:
await self.bot.say("Sorry, I couldn't find a close match for the game {}".format(game))
return
url = "{}/ISteamUserStats/GetPlayerAchievements/v0001/?key={}&steamid={}&appid={}".format(base_url, self.key, steam_id, app_id)
url = "{}/ISteamUserStats/GetPlayerAchievements/v0001/?key={}&steamid={}&appid={}".format(base_url,
self.key,
steam_id,
app_id)
elif option[0] == "games":
await self.bot.say("Currently disabled, only achievements and info are available as options")
return
except IndexError:
option = ['info']
url = "{}/ISteamUser/GetPlayerSummaries/v0002/?key={}&steamids={}".format(base_url, self.key, steam_id)
# Make the request and get the data in json response, all url's we're using will give a json response
@ -175,7 +182,9 @@ class Steam:
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))
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:
@ -185,8 +194,9 @@ class Steam:
return
# 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))
await self.bot.say("{} has achieved {}/{} achievements on the game {}".format(member.display_name,
len(successful_achievements),
len(all_achievements), game))
@steam.command(name='add', aliases=['link', 'create'], pass_context=True)
@checks.custom_perms(send_messages=True)
@ -219,7 +229,8 @@ class Steam:
steam_users[author.id] = {'steam_id': steam_id}
config.save_content('steam_users', steam_users)
await self.bot.say("I have just saved your steam account, you should now be able to view stats for your account!")
await self.bot.say(
"I have just saved your steam account, you should now be able to view stats for your account!")
@commands.command(pass_context=True)
@checks.custom_perms(send_messages=True)
@ -231,14 +242,16 @@ class Steam:
await self.bot.say("Sorry, but I don't have that user's steam account saved!")
return
url = "{}/ISteamUserStats/GetUserStatsForGame/v0002/?key={}&appid=730&steamid={}".format(base_url, self.key, steam_id)
url = "{}/ISteamUserStats/GetUserStatsForGame/v0002/?key={}&appid=730&steamid={}".format(base_url, self.key,
steam_id)
async with self.session.get(url, headers=self.headers) as response:
data = await response.json()
stuff_to_print = ['total_kills', 'total_deaths', 'total_wins', 'total_mvps']
stats = "\n".join(
"{}: {}".format(d['name'], d['value']) for d in data['playerstats']['stats'] if d['name'] in stuff_to_print)
await self.bot.say("CS:GO Stats for user {}: \n```\n{}```".format(member.display_name, stats.title().replace("_", " ")))
await self.bot.say(
"CS:GO Stats for user {}: \n```\n{}```".format(member.display_name, stats.title().replace("_", " ")))
def setup(bot):