Corrected issue when no option is provided
This commit is contained in:
parent
92ca0831e0
commit
880fa0e17b
1 changed files with 32 additions and 19 deletions
|
@ -54,6 +54,8 @@ app_id_map = {"portal 2": 620,
|
||||||
"fallout 4": 377160,
|
"fallout 4": 377160,
|
||||||
"fallout new vegas": 22490
|
"fallout new vegas": 22490
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_app_id(game: str):
|
def get_app_id(game: str):
|
||||||
best_match = process.extractOne(game, app_id_map.keys())
|
best_match = process.extractOne(game, app_id_map.keys())
|
||||||
if best_match[1] > 80:
|
if best_match[1] > 80:
|
||||||
|
@ -61,6 +63,7 @@ def get_app_id(game: str):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Steam:
|
class Steam:
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
@ -85,7 +88,6 @@ class Steam:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@commands.group(pass_context=True, invoke_without_command=True)
|
@commands.group(pass_context=True, invoke_without_command=True)
|
||||||
@checks.custom_perms(send_messages=True)
|
@checks.custom_perms(send_messages=True)
|
||||||
async def steam(self, ctx, member: discord.Member, *option: str):
|
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
|
# First make sure the person requested isn't the bot
|
||||||
# Need to keep up the bot's sassy attitude, right?
|
# Need to keep up the bot's sassy attitude, right?
|
||||||
if member == ctx.message.server.me:
|
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
|
return
|
||||||
# Get the user's steam id if it exists
|
# Get the user's steam id if it exists
|
||||||
try:
|
try:
|
||||||
|
@ -125,11 +128,15 @@ class Steam:
|
||||||
await self.bot.say("Sorry, I couldn't find a close match for the game {}".format(game))
|
await self.bot.say("Sorry, I couldn't find a close match for the game {}".format(game))
|
||||||
return
|
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":
|
elif option[0] == "games":
|
||||||
await self.bot.say("Currently disabled, only achievements and info are available as options")
|
await self.bot.say("Currently disabled, only achievements and info are available as options")
|
||||||
return
|
return
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
option = ['info']
|
||||||
url = "{}/ISteamUser/GetPlayerSummaries/v0002/?key={}&steamids={}".format(base_url, self.key, steam_id)
|
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
|
# 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":
|
if data['playerstats']['error'] == "Requested app has no stats":
|
||||||
await self.bot.say("{} has no achievements on the game {}".format(member.display_name, game))
|
await self.bot.say("{} has no achievements on the game {}".format(member.display_name, game))
|
||||||
elif data['playerstats']['error'] == "Profile is not public":
|
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
|
return
|
||||||
# Get all achievements for this game, making sure they actually exist
|
# Get all achievements for this game, making sure they actually exist
|
||||||
try:
|
try:
|
||||||
|
@ -185,8 +194,9 @@ class Steam:
|
||||||
return
|
return
|
||||||
# Now get all achievements that the user has achieved
|
# Now get all achievements that the user has achieved
|
||||||
successful_achievements = [data for data in all_achievements if data['achieved'] == 1]
|
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)
|
@steam.command(name='add', aliases=['link', 'create'], pass_context=True)
|
||||||
@checks.custom_perms(send_messages=True)
|
@checks.custom_perms(send_messages=True)
|
||||||
|
@ -219,7 +229,8 @@ class Steam:
|
||||||
steam_users[author.id] = {'steam_id': steam_id}
|
steam_users[author.id] = {'steam_id': steam_id}
|
||||||
|
|
||||||
config.save_content('steam_users', steam_users)
|
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)
|
@commands.command(pass_context=True)
|
||||||
@checks.custom_perms(send_messages=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!")
|
await self.bot.say("Sorry, but I don't have that user's steam account saved!")
|
||||||
return
|
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:
|
async with self.session.get(url, headers=self.headers) as response:
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
|
|
||||||
stuff_to_print = ['total_kills', 'total_deaths', 'total_wins', 'total_mvps']
|
stuff_to_print = ['total_kills', 'total_deaths', 'total_wins', 'total_mvps']
|
||||||
stats = "\n".join(
|
stats = "\n".join(
|
||||||
"{}: {}".format(d['name'], d['value']) for d in data['playerstats']['stats'] if d['name'] in stuff_to_print)
|
"{}: {}".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):
|
def setup(bot):
|
||||||
|
|
Loading…
Reference in a new issue