convert stock to slash command

This commit is contained in:
Luke Robles 2022-10-19 09:11:18 -07:00
parent d0b517bbd4
commit e58ee7d728
3 changed files with 25 additions and 22 deletions

View File

@ -127,20 +127,28 @@ class ActualUtils(commands.Cog):
await ctx.send(embed=result)
@commands.command(name="stock")
async def stock(self, ctx: commands.Context):
msg = ctx.message.content
if len(msg.split()) < 2:
import help_methods
await ctx.send(help_methods.get_help_message("stock"))
@commands.slash_command(
guld_ids=None,
name="stock",
description="Enter one or many stock tickers to get info about them",
)
@option(
name="symbols", description="Stocks to look up the price for", required=True
)
@option(
name="verbose",
description="Return extended info about the stocks",
type=bool,
default=False,
)
async def stock(self, ctx, symbols, verbose):
import stock
results = stock.parse_message(msg)
results = stock.parse_message(symbols, verbose)
await ctx.defer()
for res in results:
await ctx.reply(embed=res)
await ctx.send_followup(embed=res)
def setup(bot):

View File

@ -3,20 +3,14 @@ import os
import requests
def parse_message(msg):
split_msg = msg.split()
verbose = False
def parse_message(symbols, verbose):
embeds = []
bad_tickers = []
if set(["-v", "--verbose"]) & set(split_msg):
verbose = True
for s in split_msg[1:]:
# Skip flags
if s[0] != "-":
try:
embeds.append(get_stock(s, verbose=verbose))
except:
bad_tickers.append(s)
for s in symbols.split():
try:
embeds.append(get_stock(s, verbose=verbose))
except:
bad_tickers.append(s)
if bad_tickers:
embeds.append(_make_error_embed(bad_tickers))
return embeds

View File

@ -1 +1,2 @@
find . -name "*sync-conflict*" -delete
docker run --rm -ti -v $(pwd):/tmp/python/app python:alpine sh -c "cd /tmp/python ; pip install -q black; black ."