Skip to content

Commit

Permalink
Fix issue with missing favorite game mode
Browse files Browse the repository at this point in the history
  • Loading branch information
laggron42 committed May 22, 2020
1 parent 80e0cc8 commit c8c62f9
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions codmw/codmw.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,15 @@ async def cod_mw(self, ctx: commands.Context, platform: str, username: str):
if data is None:
return
game_data = data["lifetime"]["all"]["properties"]
favorite_gamemode = sorted(
[(k, v) for k, v in data["lifetime"]["mode"].items()],
key=lambda x: x[1]["properties"]["timePlayed"],
)[0][
0
] # first result, then we only keep the key, not the value
try:
favorite_gamemode = sorted(
[(k, v) for k, v in data["lifetime"]["mode"].items()],
key=lambda x: x[1]["properties"]["timePlayed"],
)[0][
0
] # first result, then we only keep the key, not the value
except IndexError:
favorite_gamemode = None
embed = discord.Embed()
embed.set_thumbnail(url="https://i.imgur.com/9xaOL9M.png")
embed.title = _("{username}'s stats").format(username=data["username"])
Expand Down Expand Up @@ -384,7 +387,8 @@ async def cod_mw(self, ctx: commands.Context, platform: str, username: str):
embed.add_field(
name=_("Best score per minute"), value=f"{round(game_data['bestSPM']):,}", inline=True,
)
embed.set_footer(text=f"Favorite gamemode: {self._get_gamemode(favorite_gamemode)}")
if favorite_gamemode:
embed.set_footer(text=f"Favorite gamemode: {self._get_gamemode(favorite_gamemode)}")
await ctx.send(embed=embed)

@cod.command(name="wz")
Expand Down

0 comments on commit c8c62f9

Please sign in to comment.