Rewrite of the /rsifind command. Much faseter and not relying on the shitty API anymore
This commit is contained in:
parent
7ed3acc36e
commit
ce60e60209
@ -52,14 +52,12 @@ def write_incident_file(file_path, url, details):
|
||||
|
||||
|
||||
async def rsi_find(player):
|
||||
player_url = "https://api.starcitizen-api.com/%s/v1/live/user/%s" % (
|
||||
os.getenv("star_citizen_token").replace('"', ""),
|
||||
player,
|
||||
)
|
||||
response = requests.get(player_url).json()
|
||||
print(response)
|
||||
base_url = "https://robertsspaceindustries.com"
|
||||
|
||||
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(
|
||||
description="❌❌❌",
|
||||
color=discord.Color.red(),
|
||||
@ -68,70 +66,135 @@ async def rsi_find(player):
|
||||
)
|
||||
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(
|
||||
description="-------",
|
||||
color=discord.Color.blue(),
|
||||
type="rich",
|
||||
title="%s's Star citizen information" % response["data"]["profile"]["handle"],
|
||||
title="%s's Star citizen information" % player,
|
||||
)
|
||||
|
||||
embed.add_field(
|
||||
name="Link to profile",
|
||||
value=response["data"]["profile"]["page"]["url"],
|
||||
value=profile_url,
|
||||
inline=False,
|
||||
)
|
||||
embed.add_field(
|
||||
name="Player ID",
|
||||
value=response["data"]["profile"]["id"],
|
||||
value=citizen_number,
|
||||
inline=True,
|
||||
)
|
||||
embed.add_field(
|
||||
name="Enlisted",
|
||||
value=response["data"]["profile"]["enlisted"].split("T")[0],
|
||||
value=enlisted,
|
||||
inline=True,
|
||||
)
|
||||
|
||||
embed.set_author(
|
||||
name=response["data"]["profile"]["badge"],
|
||||
icon_url=response["data"]["profile"]["badge_image"],
|
||||
url=response["data"]["profile"]["page"]["url"],
|
||||
name=badge_text,
|
||||
icon_url=badge_url,
|
||||
url=profile_url,
|
||||
)
|
||||
embed.set_thumbnail(url=response["data"]["profile"]["image"])
|
||||
|
||||
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()
|
||||
embed.set_thumbnail(url=profile_photo)
|
||||
|
||||
# Org info
|
||||
if "NO MAIN ORG FOUND IN PUBLIC RECORDS" in response:
|
||||
embed.add_field(
|
||||
name="Org Info",
|
||||
value="[%s](%s)"
|
||||
% (org_response["data"]["sid"], org_response["data"]["url"]),
|
||||
value="Player is not in an org",
|
||||
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,
|
||||
)
|
||||
|
||||
embed.add_field(
|
||||
name="Rank",
|
||||
value=response["data"]["organization"]["rank"],
|
||||
value=org_rank,
|
||||
inline=True,
|
||||
)
|
||||
|
||||
embed.add_field(
|
||||
name="Number of members",
|
||||
value=org_response["data"]["members"],
|
||||
value=org_member_count,
|
||||
inline=False,
|
||||
)
|
||||
embed.set_image(url=org_response["data"]["logo"])
|
||||
else:
|
||||
embed.add_field(
|
||||
name="Org Info",
|
||||
value="Player is not in an org or it is hidden",
|
||||
inline=False,
|
||||
)
|
||||
|
||||
embed.set_image(url=org_logo)
|
||||
return embed
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user