Convert wallpaper to slash command and fix post market price check for stock
This commit is contained in:
parent
8803de2ee0
commit
1d207a0a01
20
app/bot.py
20
app/bot.py
@ -65,17 +65,17 @@ async def he_just_like_me(ctx):
|
|||||||
await ctx.reply("https://imgur.com/V3k729v")
|
await ctx.reply("https://imgur.com/V3k729v")
|
||||||
|
|
||||||
|
|
||||||
@bot.listen("on_message")
|
# @bot.listen("on_message")
|
||||||
async def did_you_mean(ctx):
|
# async def did_you_mean(ctx):
|
||||||
if ctx.author.id != core_utils.my_id:
|
# if ctx.author.id != core_utils.my_id:
|
||||||
message = ctx.content
|
# message = ctx.content
|
||||||
command = ctx.content.split()[0][1:]
|
# command = ctx.content.split()[0][1:]
|
||||||
|
|
||||||
command_map = {"ask": "wolfram"}
|
# command_map = {"ask": "wolfram"}
|
||||||
if message.startswith("!"):
|
# if message.startswith("!"):
|
||||||
if command in command_map.keys():
|
# if command in command_map.keys():
|
||||||
command = command_map[command]
|
# command = command_map[command]
|
||||||
await ctx.reply("Did you mean /%s?" % command)
|
# await ctx.reply("Did you mean /%s?" % command)
|
||||||
|
|
||||||
|
|
||||||
@bot.listen("on_message")
|
@bot.listen("on_message")
|
||||||
|
@ -131,15 +131,22 @@ class Cheeky(commands.Cog):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@commands.command(name="wallpaper")
|
@commands.slash_command(
|
||||||
async def wallpaper(self, ctx: commands.Context):
|
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
|
import wallpaper
|
||||||
|
|
||||||
async with ctx.message.channel.typing():
|
await ctx.defer()
|
||||||
await ctx.reply(
|
await ctx.send_followup(
|
||||||
embed=core_utils.generate_embed(
|
embed=core_utils.generate_embed(embed_url=wallpaper.get_wall(tags))
|
||||||
embed_url=wallpaper.get_wall(ctx.message.content)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@commands.slash_command(name="donate")
|
@commands.slash_command(name="donate")
|
||||||
|
@ -111,7 +111,7 @@ def get_stock(share_name, verbose=False):
|
|||||||
embed.set_thumbnail(url=meme_url)
|
embed.set_thumbnail(url=meme_url)
|
||||||
embed.set_author(name=request["shortName"])
|
embed.set_author(name=request["shortName"])
|
||||||
|
|
||||||
if request["marketState"] == "POST":
|
if "postMarketPrice" in request:
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="After Hours price",
|
name="After Hours price",
|
||||||
value="$%s" % request["postMarketPrice"],
|
value="$%s" % request["postMarketPrice"],
|
||||||
|
@ -4,9 +4,9 @@ import requests
|
|||||||
import urllib
|
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
|
Grabs a random wallpaper from unsplash.com's random function
|
||||||
If any tags are passed in as the message, it will search for images
|
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/?"
|
unsplash_url = "https://source.unsplash.com/3840x2160/?"
|
||||||
|
|
||||||
if len(message.split()) > 2:
|
if len(tags.split()) > 2:
|
||||||
search_terms = message.split()[1:]
|
search_terms = tags.split()[1:]
|
||||||
|
|
||||||
# Turn search_terms into strings separated by commas
|
# Turn search_terms into strings separated by commas
|
||||||
joined_terms = ",".join(search_terms)
|
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
|
# Add those comma separated strings onto the end of the URL variable
|
||||||
url = unsplash_url + joined_terms
|
url = unsplash_url + joined_terms
|
||||||
|
|
||||||
elif len(message.split()) > 1:
|
|
||||||
term = message.split()[1]
|
|
||||||
url = unsplash_url + term
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
url = unsplash_url
|
url = unsplash_url + tags
|
||||||
|
|
||||||
response = requests.get(url, timeout=8).url
|
response = requests.get(url, timeout=8).url
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user