From f3a3d426ee6f49bd7380ea074780748de736c626 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 7 Oct 2023 22:02:57 -0700 Subject: [PATCH] Adding /drugs --- app/cogs/star_citizen.py | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/app/cogs/star_citizen.py b/app/cogs/star_citizen.py index d3e808d0..e7c50ec0 100644 --- a/app/cogs/star_citizen.py +++ b/app/cogs/star_citizen.py @@ -21,6 +21,47 @@ class StarCitizen(commands.Cog): async def post_medpen_guide(self, ctx: commands.Context): await ctx.respond("https://i.redd.it/lfswlf5c13t71.png") + @commands.slash_command( + guild_ids=None, + name="drugs", + description="Returns a list of all the drugs in game sorted by their price", + ) + async def post_drugs(self, ctx: commands.Context): + headers = {"api_key": os.getenv("uexcorp_key")} + + response = requests.get( + "https://portal.uexcorp.space/api/commodities/", headers=headers + ) + + all_commodities = [x for x in response.json()["data"]] + all_drugs = { + item["name"]: item["trade_price_sell"] + for item in all_commodities + if item["kind"] == "Drug" + } + sorted_dict = dict(sorted(all_drugs.items(), key=lambda item: item[1])) + + embed = discord.Embed( + description="-------", color=discord.Color.orange(), type="rich" + ) + + embed.set_thumbnail( + url="https://i.ebayimg.com/images/g/IvQAAOSwjyhaOTZN/s-l1200.webp" + ) + embed.set_author(name="Ranking of drugs by sell price") + + # embed.add_field(name="Details", value=details.text, inline=True) + + for k, v in sorted_dict.items(): + embed.add_field( + name=k, + value="${:20,}".format(v), + inline=False, + ) + + await ctx.defer() + await ctx.send_followup(embed=embed) + async def get_all_ships(ctx: discord.AutocompleteContext): """ returns a list of all ships in the game, which can then be passed to the /ship command for auto complete