Add autocomplete to the /meme function

This commit is contained in:
Luke Robles 2024-05-03 10:50:11 -07:00
parent 633fe2bf25
commit a734913085
7 changed files with 33 additions and 24 deletions

0
.gitea/workflows/build-and-push.yaml Normal file → Executable file
View File

0
Dockerfile-test-env Normal file → Executable file
View File

0
app/bot.py Normal file → Executable file
View File

0
app/cogs/animal_functions.py Normal file → Executable file
View File

View File

@ -1,8 +1,8 @@
from bs4 import BeautifulSoup
from discord import option
from discord.ext import commands
import core_utils
import discord
import core_utils
import os
import random
import requests
@ -168,21 +168,42 @@ class Cheeky(commands.Cog):
await ctx.reply(excuse.get_excuse())
async def get_all_meme_templates(ctx: discord.AutocompleteContext):
"""
get all the meme templates
"""
return sorted(
list(
map(
lambda x: x["id"],
requests.get("https://api.memegen.link/templates/").json(),
)
)
)
@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",
async def meme(
self,
ctx: commands.Context,
template: discord.Option(
str,
autocomplete=discord.utils.basic_autocomplete(get_all_meme_templates),
description="The template to use",
),
top: discord.Option(
str, description="The text to appear at the top of the meme", required=True
),
bottom: discord.Option(
str,
description="The text to appear at the bottom of the meme",
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.defer()

View File

@ -76,14 +76,10 @@ class StarCitizen(commands.Cog):
returns a list of all ships in the game, which can then be passed to the /ship command for auto complete
"""
url = "https://starcitizen.tools/Category:Ships"
response = requests.get(url).text
soup = BeautifulSoup(response, "html.parser")
h2_heading = soup.find("h2", text='Pages in category "Ships"')
all_ships = [link.text for link in h2_heading.find_next("div").find_all("a")]
return all_ships
return [link.text for link in h2_heading.find_next("div").find_all("a")]
@starcitizen.command(
guild_ids=core_utils.my_guilds,

View File

@ -1,7 +1,5 @@
import requests
import help_methods
supported_templates = sorted(
list(
map(
@ -51,9 +49,3 @@ def get_meme_url(template, top, bottom, usesTemplate):
if usesTemplate:
meme = "{}/{}/{}/{}.{}".format(base_URL, template, top, bottom, default_format)
return meme
def get_meme_help():
return "{}\nYou must supply a valid template for the meme. Templates are one of the following: \n```{}```".format(
help_methods.get_help_message("meme"), ", ".join(supported_templates)
)