Updating apex function to use tracker network

This commit is contained in:
Luke Robles 2023-09-25 10:35:18 -07:00
parent db313adb51
commit 016c29e584
2 changed files with 58 additions and 95 deletions

View File

@ -1,117 +1,80 @@
import datetime
import discord
import os
import requests
def get_player(player):
# player = player.lower()
# url = "https://public-api.tracker.gg/v2/apex/standard/profile/origin/" + player
# headers = {
# "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)",
# "accept": "application/json",
# "TRN-Api-Key": os.getenv("tracker_network_token"),
# }
url = "https://public-api.tracker.gg/v2/apex/standard/profile/origin/" + player
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)",
"accept": "application/json",
"TRN-Api-Key": os.getenv("tracker_network_token"),
}
url = (
"https://api.mozambiquehe.re/bridge?auth=%s&player=%s&platform=PC&merge=True"
% (
os.getenv("apex_api_key"),
player,
)
)
# print(url)
response = requests.get(url).json()
response = requests.get(url).json()["data"]
# Build the embed
embed = discord.Embed(description="-------", color=discord.Color.red(), type="rich")
embed.set_thumbnail(url=response["global"]["rank"]["rankImg"])
embed.set_author(name="Apex stats for %s" % response["global"]["name"])
embed.add_field(
name="**Rank**",
value="%s, %s"
% (
response["global"]["rank"]["rankName"],
response["global"]["rank"]["rankScore"],
),
inline=False,
)
embed.add_field(
name="**Current level**",
value="%s, %s%% of the way to next level"
% (
response["global"]["level"],
response["global"]["toNextLevelPercent"],
),
inline=False,
embed.set_thumbnail(url=response["platformInfo"]["avatarUrl"])
embed.set_author(
name="Apex stats for %s" % response["platformInfo"]["platformUserId"],
icon_url=response["segments"][0]["stats"]["peakRankScore"]["metadata"][
"iconUrl"
],
)
gameplay_stats = {
"kills": "Total kills",
"kd": "K/D",
"executions": "Executions",
"revives": "Revies",
"games_played": "Games Played",
"headshots": "Headshots",
}
embed.add_field(name="Totals", value="-------", inline=False)
for stat, readable in gameplay_stats.items():
embed.add_field(
name="**%s**" % readable,
value=response["total"][stat]["value"],
name="**Current Rank**",
value=response["segments"][0]["stats"]["peakRankScore"]["displayName"],
inline=True,
)
embed.add_field(name="Account Wide stats", value="-----", inline=False)
stats_we_care_about = ["wins", "level", "kills", "damage", "headshots", "revives"]
for stat in stats_we_care_about:
embed.add_field(
name="Stats per legend", value="---------------------", inline=False
name="**%s**" % response["segments"][0]["stats"][stat]["displayName"],
value=response["segments"][0]["stats"][stat]["displayValue"],
inline=True,
)
legends = response["legends"]["all"]
for legend in legends:
if "data" in response["legends"]["all"][legend] and legend != "Global":
data = response["legends"]["all"][legend]["data"]
smush = {x["key"]: x for x in data}
try:
legends_kills = smush["specialEvent_kills"]["value"] or 0
legends_damage = smush["specialEvent_damage"]["value"] or 0
legends_wins = smush["specialEvent_wins"]["value"] or 0
all_legends = response["segments"][1:]
# Calculate their most effective legends
embed.add_field(name="Bests", value="-----", inline=False)
embed.add_field(
name=legend,
value="Total kills: %s\nTotal Damage: %s\nTotal Wins: %s"
% (legends_kills, legends_damage, legends_wins),
name="**Legend with most kills**",
value="%s: %s"
% (
find_best(all_legends, key="kills")["metadata"]["name"],
find_best(all_legends, key="kills")["stats"]["kills"]["displayValue"],
),
)
embed.add_field(
name="**Legend with most wins**",
value="%s: %s"
% (
find_best(all_legends, key="wins")["metadata"]["name"],
find_best(all_legends, key="wins")["stats"]["wins"]["displayValue"],
),
)
embed.add_field(
name="**Legend with most damage**",
value="%s: %s"
% (
find_best(all_legends, key="damage")["metadata"]["name"],
find_best(all_legends, key="damage")["stats"]["damage"]["displayValue"],
),
)
embed.add_field(
name="**Legend with most revives**",
value="%s: %s"
% (
find_best(all_legends, key="revives")["metadata"]["name"],
find_best(all_legends, key="revives")["stats"]["revives"]["displayValue"],
),
)
except Exception as e:
print("%s threw an exception on %s" % (legend, e))
pass
# 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
@ -123,4 +86,4 @@ def find_best(blob, key):
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])
return max(blob, key=lambda x: x["stats"][key]["value"] if key in x else 0)

0
app/cogs/stable_diffusion.py Executable file → Normal file
View File