diff --git a/app/cogs/star_citizen.py b/app/cogs/star_citizen.py new file mode 100644 index 00000000..8e587893 --- /dev/null +++ b/app/cogs/star_citizen.py @@ -0,0 +1,27 @@ +from discord import option +from discord.ext import commands +import star_citizen + + +class StarCitizen(commands.Cog): + def __init__(self, bot): + self.bot: commands.Bot = bot + + @commands.slash_command( + guild_ids=None, + name="ship", + description="Query the star citizen database about a ship", + ) + @option( + name="ship", + description="Ship you want info on, supports relatively fuzzy matching, eg. 890 instead of 890 jump", + required=True, + ) + async def star_citizen(self, ctx: commands.Context, ship): + await ctx.defer() + embed = await star_citizen.get_ship(ship_name=ship) + await ctx.send_followup(embed=embed) + + +def setup(bot): + bot.add_cog(StarCitizen(bot)) diff --git a/app/requirements.txt b/app/requirements.txt index 85f66d01..acaedb15 100755 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -9,4 +9,5 @@ openai owotext pandas requests -wolframalpha +rsi-scraper +wolframalpha \ No newline at end of file diff --git a/app/star_citizen.py b/app/star_citizen.py new file mode 100644 index 00000000..2c0644bb --- /dev/null +++ b/app/star_citizen.py @@ -0,0 +1,55 @@ +from bs4 import BeautifulSoup +from rsi_scraper import Ship +import requests +import discord +import pprint + + +async def get_ship(ship_name): + base_url = "https://robertspaceindustries.com" + wiki_url = "https://starcitizen.tools/" + + ship = await Ship(name=ship_name).get_ships_pages_async() + ship = ship[0] + pp = pprint.PrettyPrinter(indent=4) + pp.pprint(ship) + + ship_picture = ship["media"][0]["images"]["wallpaper_thumb"] + wiki_ship_name = ship["url"].split("/")[-1].split("-")[0] + + headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)"} + response = requests.get(wiki_url + wiki_ship_name, headers=headers).text + soup = BeautifulSoup(response, "html.parser") + + try: + ingame_price = soup.find( + "div", {"class": "data-buycost infobox-data infobox-col2"} + ) + children = ingame_price.findChildren("div") + price_lambda = list(filter(lambda x: ("aUEC" in x.text), children)) + ingame_price = price_lambda[0].text + except Exception: + ingame_price = "No in-game price available" + + pledge_price = soup.find( + "div", {"class": "data-pledgecost infobox-data infobox-col4"} + ) + children = pledge_price.findChildren("div") + real_money_price = list(filter(lambda x: ("$" in x.text), children)) + + embed = discord.Embed( + description="-------", color=discord.Color.teal(), type="rich" + ) + embed.set_thumbnail(url=ship_picture) + embed.set_author(name="Star Citizen API Info about the %s" % ship["name"]) + embed.add_field(name="**Ingame Price**", value=ingame_price, inline=False) + embed.add_field( + name="**Pledge Price**", value=real_money_price[0].text, inline=False + ) + embed.add_field(name="**Description**", value=ship["description"], inline=False) + embed.add_field( + name="**Cargo Capacity**", value="%s SCU" % ship["cargocapacity"], inline=True + ) + embed.add_field(name="**Crew Size**", value=ship["max_crew"], inline=True) + + return embed