99 lines
3.2 KiB
Python
Executable File
99 lines
3.2 KiB
Python
Executable File
import requests
|
|
import discord
|
|
import datetime
|
|
|
|
|
|
def get_player(player):
|
|
player = player.lower()
|
|
url = (
|
|
"https://api.gametools.network/bf2042/stats/?raw=false&format_values=true&name="
|
|
+ player
|
|
+ "&platform=pc&skip_battlelog=false"
|
|
)
|
|
headers = {
|
|
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)",
|
|
"accept": "application/json",
|
|
}
|
|
response = requests.get(url, headers=headers).json()
|
|
|
|
# Build the embed
|
|
embed = discord.Embed(
|
|
description="-------", color=discord.Color.teal(), type="rich"
|
|
)
|
|
embed.set_thumbnail(url=response["avatar"])
|
|
embed.set_author(name="Battlefield 2042 stats for %s" % response["userName"])
|
|
# embed.add_field(
|
|
# name="**Rank**", value="%s, %s" % (rank_number, rank_title), inline=False
|
|
# )
|
|
|
|
gameplay_stats = {
|
|
"mvp": "Times you were an MVP",
|
|
"matchesPlayed": "Total games played",
|
|
"kills": "Total Kills",
|
|
"deaths": "Total Deaths",
|
|
"killDeath": "KDR",
|
|
"wins": "All Time Wins",
|
|
"loses": "All Time Loses",
|
|
"winPercent": "Win/loss percentage",
|
|
"accuracy": "Accuracy percentage",
|
|
"killsPerMinute": "Kills per Minute",
|
|
"damagePerMinute": "Damage per Minute",
|
|
"killsPerMatch": "Avg kills per game",
|
|
"damagePerMatch": "Avg damage per game",
|
|
"headShots": "Total Head shots",
|
|
"headshots": "Kills via Head Shot as a Percentage",
|
|
"timePlayed": "Total time played",
|
|
"revives": "Total # of revives",
|
|
"heals": "Total amount healed",
|
|
"resupplies": "Total # of ammo resupplies",
|
|
"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():
|
|
embed.add_field(
|
|
name="**%s**" % readable,
|
|
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_best(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])
|