Convert trackdays to a slash command and allow you to pick a track
This commit is contained in:
parent
a1a2687da8
commit
05c0066770
@ -95,14 +95,21 @@ class ActualUtils(commands.Cog):
|
||||
|
||||
@commands.has_role("Track day gamers")
|
||||
@commands.slash_command(
|
||||
guild_ids=core_utils.my_guilds,
|
||||
# guild_ids=core_utils.my_guilds,
|
||||
guild_ids=None,
|
||||
name="trackdays",
|
||||
description="Query motorsportsreg.com for a list of trackdays going on at Buttonwillow and Thunderhill",
|
||||
)
|
||||
async def trackdays(self, ctx: commands.Context):
|
||||
@option(
|
||||
name="track",
|
||||
description="Choose a track to see the trackdays at, or leave blank for all",
|
||||
choices=["Buttonwillow", "Thunderhill", "Both"],
|
||||
default="Both",
|
||||
)
|
||||
async def trackdays(self, ctx: commands.Context, track):
|
||||
import trackdays
|
||||
|
||||
shid = await trackdays.get_msreg()
|
||||
shid = await trackdays.get_msreg(track=track)
|
||||
for track, events in shid.items():
|
||||
embed = discord.Embed(
|
||||
description=":checkered_flag: **Upcoming events at %s**:checkered_flag: "
|
||||
@ -122,7 +129,7 @@ class ActualUtils(commands.Cog):
|
||||
embed.add_field(
|
||||
name="Event URL", value=track_day["event_url"], inline=False
|
||||
)
|
||||
await ctx.send(embed=embed)
|
||||
await ctx.respond(embed=embed)
|
||||
|
||||
@commands.slash_command(
|
||||
guild_ids=None,
|
||||
|
@ -95,20 +95,30 @@ class Cheeky(commands.Cog):
|
||||
|
||||
await ctx.reply(excuse.get_excuse())
|
||||
|
||||
@commands.command(name="meme")
|
||||
async def meme(self, ctx: commands.Context):
|
||||
@commands.slash_command(
|
||||
guild_ids=None,
|
||||
name="meme",
|
||||
description="Generate a dank classic meme. White bold text over an image",
|
||||
)
|
||||
@option(
|
||||
name="template",
|
||||
description="Which meme template you want to use",
|
||||
required=True,
|
||||
)
|
||||
@option(name="top", description="The Top text to put on the meme", required=True)
|
||||
@option(
|
||||
name="bottom", description="The bottom text to put on the meme", required=True
|
||||
)
|
||||
async def meme(self, ctx: commands.Context, template, top, bottom):
|
||||
|
||||
import meme_gen
|
||||
|
||||
await ctx.message.delete()
|
||||
try:
|
||||
await ctx.send(
|
||||
await ctx.defer()
|
||||
await ctx.send_followup(
|
||||
embed=core_utils.generate_embed(
|
||||
embed_url=meme_gen.parse_message(ctx.message.content)
|
||||
embed_url=meme_gen.parse_message(template, top, bottom)
|
||||
)
|
||||
)
|
||||
except discord.errors.HTTPException:
|
||||
await ctx.send(meme_gen.get_meme_help())
|
||||
|
||||
@commands.command(name="define", aliases=["ud"])
|
||||
async def define(self, ctx: commands.Context):
|
||||
|
@ -13,10 +13,7 @@ supported_templates = sorted(
|
||||
)
|
||||
|
||||
|
||||
def parse_message(message):
|
||||
if len(message.split()) <= 2:
|
||||
return get_meme_help()
|
||||
|
||||
def parse_message(template, top, bottom):
|
||||
escaped_chars = {
|
||||
"_": "__",
|
||||
" ": "_",
|
||||
@ -28,16 +25,10 @@ def parse_message(message):
|
||||
"''": '"',
|
||||
}
|
||||
|
||||
# Unwrap message from discord
|
||||
template = message.split()[1]
|
||||
text = message.replace("!meme {}".format(template), "").lstrip().split(",")
|
||||
upper = text[0].split(";")[0].lstrip()
|
||||
lower = text[0].split(";")[1].lstrip()
|
||||
|
||||
# Escape special characters in upper/lower text
|
||||
# Escape special characters in top/bottom text
|
||||
for char, escaped in escaped_chars.items():
|
||||
upper = upper.replace(char, escaped)
|
||||
lower = lower.replace(char, escaped)
|
||||
top = top.replace(char, escaped)
|
||||
bottom = bottom.replace(char, escaped)
|
||||
|
||||
usesTemplate = True
|
||||
if template.startswith("http"):
|
||||
@ -45,10 +36,10 @@ def parse_message(message):
|
||||
elif template not in supported_templates:
|
||||
return "Template not supported!"
|
||||
|
||||
return get_meme_url(template, upper, lower, usesTemplate)
|
||||
return get_meme_url(template, top, bottom, usesTemplate)
|
||||
|
||||
|
||||
def get_meme_url(template, upper, lower, usesTemplate):
|
||||
def get_meme_url(template, top, bottom, usesTemplate):
|
||||
# TODO: Implement format as a parameter?
|
||||
base_URL = "https://memegen.link"
|
||||
custom_URL = "{}/custom".format(base_URL)
|
||||
@ -56,10 +47,10 @@ def get_meme_url(template, upper, lower, usesTemplate):
|
||||
|
||||
# Generate meme url
|
||||
meme = "{}/{}/{}.{}?alt={}".format(
|
||||
custom_URL, upper, lower, default_format, template
|
||||
custom_URL, top, bottom, default_format, template
|
||||
)
|
||||
if usesTemplate:
|
||||
meme = "{}/{}/{}/{}.{}".format(base_URL, template, upper, lower, default_format)
|
||||
meme = "{}/{}/{}/{}.{}".format(base_URL, template, top, bottom, default_format)
|
||||
return meme
|
||||
|
||||
|
||||
|
@ -4,7 +4,7 @@ import httpx
|
||||
import xmltodict
|
||||
|
||||
|
||||
async def get_msreg():
|
||||
async def get_msreg(track):
|
||||
base_url = "https://api.motorsportreg.com/rest/calendars/organization"
|
||||
orgs = {
|
||||
"speeddistrict": "2E22740B-E8C9-9FB9-21406A496429A28B",
|
||||
@ -19,6 +19,12 @@ async def get_msreg():
|
||||
}
|
||||
events = {}
|
||||
client = httpx.AsyncClient()
|
||||
|
||||
if track == "Both":
|
||||
tracks_we_care_about = ["buttonwillow", "thunderhill"]
|
||||
else:
|
||||
tracks_we_care_about = [track.lower()]
|
||||
|
||||
for org_name, org_id in orgs.items():
|
||||
xml_blob = await client.get(
|
||||
"%s/%s?exclude_cancelled=true&postalcode=94549&radius=500"
|
||||
@ -31,7 +37,6 @@ async def get_msreg():
|
||||
|
||||
try:
|
||||
for event in json_blob["event"]:
|
||||
tracks_we_care_about = ["buttonwillow", "thunderhill"]
|
||||
if any(x in event["name"].lower() for x in tracks_we_care_about):
|
||||
event_object = {
|
||||
"event_name": event["name"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user