Adding quantumfuel to the /ship command

This commit is contained in:
Luke Robles 2023-12-21 21:51:54 -08:00
parent f2d7ef917e
commit 003f77b93f
2 changed files with 79 additions and 2 deletions

View File

@ -310,6 +310,21 @@ class StarCitizen(commands.Cog):
await star_citizen.send_alert(self, channel=channel_id, embed=embed)
@commands.slash_command(
guild_ids=None,
name="rsifind",
description="Pull up info about a player from their RSI profile",
)
@option(
name="player",
description="The player name to search for",
required=True,
)
async def rsi_find(self, ctx: commands.Context, player: str):
await ctx.defer()
embed = await star_citizen.rsi_find(player=player)
await ctx.send_followup(embed=embed)
def setup(bot):
bot.add_cog(StarCitizen(bot))

View File

@ -1,8 +1,10 @@
from bs4 import BeautifulSoup
import requests
import discord
import os
import json
import os
import requests
import datetime
from datetime import datetime
# prints for debug
import pprint
@ -49,6 +51,53 @@ def write_incident_file(file_path, url, details):
out_file.write(json.dumps(info_dict))
async def rsi_find(player):
url = "https://api.starcitizen-api.com/%s/v1/live/user/%s" % (
os.getenv("star_citizen_token").replace('"', ""),
player,
)
response = requests.get(url).json()
embed = discord.Embed(
description="-------",
color=discord.Color.blue(),
type="rich",
title="[%s's Star Citizen Information](%s)"
% (
response["data"]["profile"]["page"]["url"],
response["data"]["profile"]["handle"],
),
)
embed.add_field(
name="Link to profile",
value=response["data"]["profile"]["page"]["url"],
inline=False,
)
embed.add_field(
name="Enlisted",
value=response["data"]["profile"]["enlisted"],
inline=False,
)
embed.set_author(
name=response["data"]["profile"]["badge"],
icon_url=response["data"]["profile"]["badge_image"],
)
embed.set_thumbnail(url=response["data"]["profile"]["image"])
embed.add_field(name="-------", value="", inline=False)
if response["data"]["organization"]["name"]:
embed.add_field(
name="Org Info",
value=response["data"]["organization"]["name"],
inline=False,
)
embed.set_image(url=response["data"]["organization"]["image"])
else:
embed.add_field(name="Org Info", value="Player is not in an org", inline=False)
return embed
async def get_ship(ship_name):
try:
wiki_ship_name = "_".join(elem for elem in ship_name.split())
@ -203,6 +252,19 @@ async def get_ship(ship_name):
embed.add_field(name="**Ship Health**", value=health, inline=True)
try:
quantum_fuel = (
soup.find("div", {"class": "infobox__label"}, string="Quantum capacity")
.findNext("span", {"class": "smwtext"})
.text
)
except Exception:
quantum_fuel = "N/A"
embed.add_field(
name="**Quantum Fuel Capacity**", value=quantum_fuel, inline=True
)
try:
top_speed = (
soup.find("div", {"class": "infobox__label"}, string="Max speed")