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 discord
import os import os
import requests import requests
def get_player(player): def get_player(player):
# player = player.lower() url = "https://public-api.tracker.gg/v2/apex/standard/profile/origin/" + player
# url = "https://public-api.tracker.gg/v2/apex/standard/profile/origin/" + player headers = {
# headers = { "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)",
# "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)", "accept": "application/json",
# "accept": "application/json", "TRN-Api-Key": os.getenv("tracker_network_token"),
# "TRN-Api-Key": os.getenv("tracker_network_token"), }
# }
url = ( response = requests.get(url).json()["data"]
"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()
# Build the embed # Build the embed
embed = discord.Embed(description="-------", color=discord.Color.red(), type="rich") embed = discord.Embed(description="-------", color=discord.Color.red(), type="rich")
embed.set_thumbnail(url=response["global"]["rank"]["rankImg"]) embed.set_thumbnail(url=response["platformInfo"]["avatarUrl"])
embed.set_author(name="Apex stats for %s" % response["global"]["name"]) embed.set_author(
embed.add_field( name="Apex stats for %s" % response["platformInfo"]["platformUserId"],
name="**Rank**", icon_url=response["segments"][0]["stats"]["peakRankScore"]["metadata"][
value="%s, %s" "iconUrl"
% ( ],
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,
) )
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( embed.add_field(
name="**%s**" % readable, name="**Current Rank**",
value=response["total"][stat]["value"], value=response["segments"][0]["stats"]["peakRankScore"]["displayName"],
inline=True, 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( 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: all_legends = response["segments"][1:]
legends_kills = smush["specialEvent_kills"]["value"] or 0 # Calculate their most effective legends
legends_damage = smush["specialEvent_damage"]["value"] or 0 embed.add_field(name="Bests", value="-----", inline=False)
legends_wins = smush["specialEvent_wins"]["value"] or 0
embed.add_field( embed.add_field(
name=legend, name="**Legend with most kills**",
value="Total kills: %s\nTotal Damage: %s\nTotal Wins: %s" value="%s: %s"
% (legends_kills, legends_damage, legends_wins), % (
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 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 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