convert stock to slash command
This commit is contained in:
parent
bcb0a34d51
commit
1d02759572
@ -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):
|
||||||
|
10
app/stock.py
10
app/stock.py
@ -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:
|
||||||
|
@ -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 ."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user