diff --git a/app/cogs/actual_utils.py b/app/cogs/actual_utils.py index 8a9e1d73..d6fb8502 100644 --- a/app/cogs/actual_utils.py +++ b/app/cogs/actual_utils.py @@ -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): diff --git a/app/stock.py b/app/stock.py index a7174406..e39e1425 100755 --- a/app/stock.py +++ b/app/stock.py @@ -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 diff --git a/format_code.sh b/format_code.sh index 87a39e44..417a0cb9 100755 --- a/format_code.sh +++ b/format_code.sh @@ -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 ."