Fix /stock timeouts

This commit is contained in:
Luke Robles 2024-02-07 14:41:27 -08:00
parent abaf678577
commit 6eac04c67f
2 changed files with 9 additions and 10 deletions

View File

@ -190,9 +190,8 @@ class ActualUtils(commands.Cog):
results = stock.parse_message(symbols, verbose)
await ctx.defer()
original_message = await ctx.followup.send("Standby")
for res in results:
await original_message.edit(content="", embed=res)
await ctx.respond(embed=res)
def setup(bot):

View File

@ -94,8 +94,8 @@ def get_stock(share_name, verbose=False):
pass
try:
request = yf.Ticker(share_name).info
except requests.exceptions.HTTPError:
request = yf.Ticker(share_name).fast_info
except Exception as e:
raise ValueError("Invalid symbol %s: empty response from Yahoo" % share_name)
change_symbol = "+"
@ -103,7 +103,7 @@ def get_stock(share_name, verbose=False):
meme_url = "https://i.ytimg.com/vi/if-2M3K1tqk/hqdefault.jpg"
# If stock price has gone down since open, use red and a sad stonk meme
current_change = request["currentPrice"] - request["regularMarketOpen"]
current_change = request["lastPrice"] - request["open"]
if current_change < 0:
change_symbol = "-"
embed_color = 15158332
@ -111,17 +111,17 @@ def get_stock(share_name, verbose=False):
embed = discord.Embed(description="-------", color=embed_color, type="rich")
embed.set_thumbnail(url=meme_url)
embed.set_author(name=request["shortName"])
embed.set_author(name=share_name)
embed.add_field(
name="Current price",
value="$%s" % request["currentPrice"],
value="$" + format(request["lastPrice"], ",.2f"),
inline=False,
)
embed.add_field(
name="Opening price",
value="$%s" % request["regularMarketOpen"],
value="$" + format(request["open"], ",.2f"),
inline=False,
)
embed.add_field(
@ -129,7 +129,7 @@ def get_stock(share_name, verbose=False):
value="$%.2f (%.7f%%)"
% (
current_change,
current_change * 100 / request["regularMarketOpen"],
current_change * 100 / request["open"],
),
inline=False,
)
@ -140,7 +140,7 @@ def get_stock(share_name, verbose=False):
chart_url = "https://www.marketwatch.com/investing/stock"
if "-" in share_name:
chart_url = "https://coinmarketcap.com/currencies"
share_name = request["shortName"].split()[0].lower()
share_name = share_name.split()[0].lower()
embed.add_field(
name="Link to stock price",
value="%s/%s" % (chart_url, share_name),