Rewrite of the /rsifind command. Much faseter and not relying on the shitty API anymore

This commit is contained in:
Luke Robles 2024-01-01 17:13:29 -08:00
parent 7ed3acc36e
commit ce60e60209

View File

@ -52,14 +52,12 @@ def write_incident_file(file_path, url, details):
async def rsi_find(player): async def rsi_find(player):
player_url = "https://api.starcitizen-api.com/%s/v1/live/user/%s" % ( base_url = "https://robertsspaceindustries.com"
os.getenv("star_citizen_token").replace('"', ""),
player,
)
response = requests.get(player_url).json()
print(response)
if not response["data"]: profile_url = "%s/citizens/%s" % (base_url, player)
response = requests.get(profile_url).text
if "NAVIGATING UNCHARTED TERRITORY" in response:
embed = discord.Embed( embed = discord.Embed(
description="❌❌❌", description="❌❌❌",
color=discord.Color.red(), color=discord.Color.red(),
@ -68,70 +66,135 @@ async def rsi_find(player):
) )
return embed return embed
soup = BeautifulSoup(response, "html.parser")
profile_photo = soup.find("div", class_="thumb").findNext("img")["src"]
if "avatar_default_big" not in profile_photo:
profile_photo = base_url + profile_photo
handle = (
soup.find("span", class_="label", string="Handle name")
.findNext("strong", class_="value")
.text
)
citizen_number = (
soup.find("span", class_="label", string="UEE Citizen Record")
.findNext("strong", class_="value")
.text
)
enlisted = (
soup.find("span", class_="label", string="Enlisted")
.findNext("strong", class_="value")
.text
)
badge_url = (
soup.find("p", class_="entry")
.findNext("span", class_="icon")
.findNext("img")["src"]
)
badge_text = (
soup.find("p", class_="entry")
.findNext("span", class_="icon")
.findNext("span", class_="value")
.text
)
embed = discord.Embed( embed = discord.Embed(
description="-------", description="-------",
color=discord.Color.blue(), color=discord.Color.blue(),
type="rich", type="rich",
title="%s's Star citizen information" % response["data"]["profile"]["handle"], title="%s's Star citizen information" % player,
) )
embed.add_field( embed.add_field(
name="Link to profile", name="Link to profile",
value=response["data"]["profile"]["page"]["url"], value=profile_url,
inline=False, inline=False,
) )
embed.add_field( embed.add_field(
name="Player ID", name="Player ID",
value=response["data"]["profile"]["id"], value=citizen_number,
inline=True, inline=True,
) )
embed.add_field( embed.add_field(
name="Enlisted", name="Enlisted",
value=response["data"]["profile"]["enlisted"].split("T")[0], value=enlisted,
inline=True, inline=True,
) )
embed.set_author( embed.set_author(
name=response["data"]["profile"]["badge"], name=badge_text,
icon_url=response["data"]["profile"]["badge_image"], icon_url=badge_url,
url=response["data"]["profile"]["page"]["url"], url=profile_url,
) )
embed.set_thumbnail(url=response["data"]["profile"]["image"]) embed.set_thumbnail(url=profile_photo)
embed.add_field(name="-------", value="", inline=False)
if "sid" in response["data"]["organization"]:
org_url = "https://api.starcitizen-api.com/%s/v1/live/organization/%s" % (
os.getenv("star_citizen_token").replace('"', ""),
response["data"]["organization"]["sid"],
)
org_response = requests.get(org_url).json()
# Org info
if "NO MAIN ORG FOUND IN PUBLIC RECORDS" in response:
embed.add_field( embed.add_field(
name="Org Info", name="Org Info",
value="[%s](%s)" value="Player is not in an org",
% (org_response["data"]["sid"], org_response["data"]["url"]), inline=False,
)
return embed
if soup.find("div", class_="main-org right-col visibility-R"):
embed.add_field(
name="Org Info",
value="Player has hidden their org from their profile",
inline=False,
)
else:
org_div = soup.find("div", class_="main-org right-col visibility-V")
org_div = soup.find("div", class_="main-org right-col visibility-V")
org_url = base_url + org_div.findNext("a")["href"]
org_response = requests.get(org_url).text
org_soup = BeautifulSoup(org_response, "html.parser")
org_name = (
org_div.find("span", string="Spectrum Identification (SID)")
.findNext("strong")
.text
)
org_rank = (
org_div.find("span", string="Organization rank").findNext("strong").text
)
org_logo = (
base_url
+ org_soup.find("div", class_="logo noshadow").findNext("img")["src"]
)
org_member_count = (
org_soup.find("div", class_="logo noshadow")
.findNext("span", class_="count")
.text
)
embed.add_field(name="-------", value="", inline=False)
embed.add_field(
name="Org Info",
value="[%s](%s)" % (org_name, org_url),
inline=True, inline=True,
) )
embed.add_field( embed.add_field(
name="Rank", name="Rank",
value=response["data"]["organization"]["rank"], value=org_rank,
inline=True, inline=True,
) )
embed.add_field( embed.add_field(
name="Number of members", name="Number of members",
value=org_response["data"]["members"], value=org_member_count,
inline=False, inline=False,
) )
embed.set_image(url=org_response["data"]["logo"]) embed.set_image(url=org_logo)
else:
embed.add_field(
name="Org Info",
value="Player is not in an org or it is hidden",
inline=False,
)
return embed return embed