Adding the /price command to get just the value of a given amount of cargoogp

This commit is contained in:
Luke Robles 2023-12-30 20:56:59 -08:00
parent 6c369c7fe0
commit 73da0434d0
2 changed files with 64 additions and 3 deletions

View File

@ -195,6 +195,30 @@ class StarCitizen(commands.Cog):
]
return all_commodities
@commands.slash_command(
guild_ids=None,
name="price",
description="Returns the price of a given amount of a commoditys",
)
@option(
name="scu",
description="How much SCU you found",
required=True,
min_value=1,
max_value=98304,
)
async def get_price(
self,
ctx: commands.Context,
commodity: discord.Option(
str, autocomplete=discord.utils.basic_autocomplete(get_all_commodities)
),
scu: int,
):
await ctx.defer()
embed = await star_citizen.get_price(commodity=commodity, scu=scu)
await ctx.send_followup(embed=embed)
@commands.slash_command(
guild_ids=None,
name="trade",
@ -207,7 +231,7 @@ class StarCitizen(commands.Cog):
min_value=1,
max_value=98304,
)
async def calculate_trade_profies(
async def calculate_trade_profits(
self,
ctx: commands.Context,
commodity: discord.Option(
@ -216,7 +240,7 @@ class StarCitizen(commands.Cog):
scu: int,
):
await ctx.defer()
embed = await star_citizen.calculate_trade_profies(commodity=commodity, scu=scu)
embed = await star_citizen.calculate_trade_profits(commodity=commodity, scu=scu)
await ctx.send_followup(embed=embed)
@tasks.loop(seconds=5)

View File

@ -437,7 +437,7 @@ async def get_ship(ship_name):
return embed
async def calculate_trade_profies(commodity, scu=None):
async def calculate_trade_profits(commodity, scu=None):
url = "https://portal.uexcorp.space/api/all_prices/pretty_mode/1/"
headers = {"api_key": os.getenv("uexcorp_key")}
@ -504,3 +504,40 @@ async def calculate_trade_profies(commodity, scu=None):
)
return embed
async def get_price(commodity, scu):
url = "https://portal.uexcorp.space/api/all_prices/pretty_mode/1/"
headers = {"api_key": os.getenv("uexcorp_key")}
scu_string = "%s scu" % scu
embed = discord.Embed(
description="-------", color=discord.Color.blue(), type="rich"
)
response = requests.get(url, headers=headers).json()["data"]
embed.set_author(name=commodity)
embed.set_thumbnail(
url="https://media.starcitizen.tools/thumb/b/bb/Shubin_logo_circle.png/120px-Shubin_logo_circle.png"
)
# Same logic, but finding the place buying the commodity for the most
profits = {}
for systems, stations in response.items():
for station, trades in stations.items():
if "sell" in trades and commodity in trades["sell"]:
profits[station] = trades["sell"][commodity] * int(scu)
break
embed.add_field(
name="Best palce to sell %s of %s" % (scu_string, commodity),
value="%s: $%s"
% (
max(profits, key=profits.get),
"{:20,.2f}".format(profits[max(profits, key=profits.get)]).strip(),
),
inline=True,
)
return embed