Adding best and favorite classes+weapons to the API blob

This commit is contained in:
Luke Robles 2023-03-16 11:30:20 -07:00
parent c82766cbbc
commit d6202e3892

View File

@ -1,4 +1,4 @@
import requests, json, pprint, discord
import requests, json, pprint, discord, datetime
def get_player(player):
@ -25,7 +25,6 @@ def get_player(player):
# )
gameplay_stats = {
"bestClass": "Best Class",
"mvp": "Times you were an MVP",
"matchesPlayed": "Total games played",
"kills": "Total Kills",
@ -48,6 +47,7 @@ def get_player(player):
"repairs": "Total vehicle damage repaired",
"squadmateRevive": "Squad mate revives",
"vehiclesDestroyed": "Total vehicles destroyed",
# "bestClass": ":trophy:Best Class:trophy:",
}
for stat, readable in gameplay_stats.items():
@ -56,4 +56,41 @@ def get_player(player):
value=response[stat],
inline=True,
)
best_weapon = find_best(response["weapons"], "kills")
embed.add_field(
name=":trophy:**Best Weapon**:trophy:",
value="%s,\nkills: %s,\naccuracy: %s\nHeadshots:%s"
% (
best_weapon["weaponName"],
best_weapon["kills"],
best_weapon["accuracy"],
best_weapon["headshotKills"],
),
inline=True,
)
favorite_class = find_best(response["classes"], "secondsPlayed")
embed.add_field(
name=":trophy:**Favorite Class**:trophy:",
value="%s,\nKDR: %s,\nTime Played: %s"
% (
favorite_class["characterName"],
favorite_class["killDeath"],
str(datetime.timedelta(seconds=favorite_class["secondsPlayed"])),
),
inline=True,
)
return embed
def find_best(blob, key):
"""
find_bset(blob, key)
blob should be the list within the request you want to find the best of,
must be one of [weapopns, vehicles, classes, gamemodes, maps, gadgets], eg response["weapons"],
and the key to use to make that distinction, for example, for weapons, you could use kills
"""
return max(blob, key=lambda x: x[key])