convert stock to slash command

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

View File

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

View File

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

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 ." docker run --rm -ti -v $(pwd):/tmp/python/app python:alpine sh -c "cd /tmp/python ; pip install -q black; black ."