Convert wallpaper to slash command and fix post market price check for stock

This commit is contained in:
Luke Robles 2023-02-08 09:29:10 -08:00
parent 8803de2ee0
commit 1d207a0a01
4 changed files with 31 additions and 28 deletions

View File

@ -65,17 +65,17 @@ async def he_just_like_me(ctx):
await ctx.reply("https://imgur.com/V3k729v")
@bot.listen("on_message")
async def did_you_mean(ctx):
if ctx.author.id != core_utils.my_id:
message = ctx.content
command = ctx.content.split()[0][1:]
# @bot.listen("on_message")
# async def did_you_mean(ctx):
# if ctx.author.id != core_utils.my_id:
# message = ctx.content
# command = ctx.content.split()[0][1:]
command_map = {"ask": "wolfram"}
if message.startswith("!"):
if command in command_map.keys():
command = command_map[command]
await ctx.reply("Did you mean /%s?" % command)
# command_map = {"ask": "wolfram"}
# if message.startswith("!"):
# if command in command_map.keys():
# command = command_map[command]
# await ctx.reply("Did you mean /%s?" % command)
@bot.listen("on_message")

View File

@ -131,15 +131,22 @@ class Cheeky(commands.Cog):
)
)
@commands.command(name="wallpaper")
async def wallpaper(self, ctx: commands.Context):
@commands.slash_command(
guild_ids=None,
name="wallpaper",
description="Queries unsplash's API for a wallpaper that matches your tags",
)
@option(
name="tags",
description="Space delimited tags you want to use as your query",
required=True,
)
async def wallpaper(self, ctx: commands.Context, tags):
import wallpaper
async with ctx.message.channel.typing():
await ctx.reply(
embed=core_utils.generate_embed(
embed_url=wallpaper.get_wall(ctx.message.content)
)
await ctx.defer()
await ctx.send_followup(
embed=core_utils.generate_embed(embed_url=wallpaper.get_wall(tags))
)
@commands.slash_command(name="donate")

View File

@ -111,7 +111,7 @@ def get_stock(share_name, verbose=False):
embed.set_thumbnail(url=meme_url)
embed.set_author(name=request["shortName"])
if request["marketState"] == "POST":
if "postMarketPrice" in request:
embed.add_field(
name="After Hours price",
value="$%s" % request["postMarketPrice"],

View File

@ -4,9 +4,9 @@ import requests
import urllib
def get_wall(message):
def get_wall(tags):
"""
get_wall(message)
get_wall(tags)
Grabs a random wallpaper from unsplash.com's random function
If any tags are passed in as the message, it will search for images
@ -14,8 +14,8 @@ def get_wall(message):
"""
unsplash_url = "https://source.unsplash.com/3840x2160/?"
if len(message.split()) > 2:
search_terms = message.split()[1:]
if len(tags.split()) > 2:
search_terms = tags.split()[1:]
# Turn search_terms into strings separated by commas
joined_terms = ",".join(search_terms)
@ -23,12 +23,8 @@ def get_wall(message):
# Add those comma separated strings onto the end of the URL variable
url = unsplash_url + joined_terms
elif len(message.split()) > 1:
term = message.split()[1]
url = unsplash_url + term
else:
url = unsplash_url
url = unsplash_url + tags
response = requests.get(url, timeout=8).url