From 1d207a0a01e04042be7f4bbda97c9cbe05308f81 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Wed, 8 Feb 2023 09:29:10 -0800 Subject: [PATCH] Convert wallpaper to slash command and fix post market price check for stock --- app/bot.py | 20 ++++++++++---------- app/cogs/cheeky_functions.py | 23 +++++++++++++++-------- app/stock.py | 2 +- app/wallpaper.py | 14 +++++--------- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/app/bot.py b/app/bot.py index 5c89d718..331ccea0 100755 --- a/app/bot.py +++ b/app/bot.py @@ -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") diff --git a/app/cogs/cheeky_functions.py b/app/cogs/cheeky_functions.py index 8ec5abc5..161d2a34 100755 --- a/app/cogs/cheeky_functions.py +++ b/app/cogs/cheeky_functions.py @@ -131,16 +131,23 @@ 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") async def donate(self, ctx: commands.Context): diff --git a/app/stock.py b/app/stock.py index 6e633ef7..9c5a97c3 100755 --- a/app/stock.py +++ b/app/stock.py @@ -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"], diff --git a/app/wallpaper.py b/app/wallpaper.py index c57f9e32..c9efb524 100755 --- a/app/wallpaper.py +++ b/app/wallpaper.py @@ -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