Add autocomplete to the /meme function
This commit is contained in:
parent
7578257d0a
commit
672b7f0a5c
0
.gitea/workflows/build-and-push.yaml
Normal file → Executable file
0
.gitea/workflows/build-and-push.yaml
Normal file → Executable file
0
Dockerfile-test-env
Normal file → Executable file
0
Dockerfile-test-env
Normal file → Executable file
0
app/bot.py
Normal file → Executable file
0
app/bot.py
Normal file → Executable file
0
app/cogs/animal_functions.py
Normal file → Executable file
0
app/cogs/animal_functions.py
Normal file → Executable file
@ -1,8 +1,8 @@
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from discord import option
|
from discord import option
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import core_utils
|
|
||||||
import discord
|
import discord
|
||||||
|
import core_utils
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import requests
|
import requests
|
||||||
@ -168,21 +168,42 @@ class Cheeky(commands.Cog):
|
|||||||
|
|
||||||
await ctx.reply(excuse.get_excuse())
|
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(
|
@commands.slash_command(
|
||||||
guild_ids=None,
|
guild_ids=None,
|
||||||
name="meme",
|
name="meme",
|
||||||
description="Generate a dank classic meme. White bold text over an image",
|
description="Generate a dank classic meme. White bold text over an image",
|
||||||
)
|
)
|
||||||
@option(
|
async def meme(
|
||||||
name="template",
|
self,
|
||||||
description="Which meme template you want to use",
|
ctx: commands.Context,
|
||||||
required=True,
|
template: discord.Option(
|
||||||
)
|
str,
|
||||||
@option(name="top", description="The Top text to put on the meme", required=True)
|
autocomplete=discord.utils.basic_autocomplete(get_all_meme_templates),
|
||||||
@option(
|
description="The template to use",
|
||||||
name="bottom", description="The bottom text to put on the meme", required=True
|
),
|
||||||
)
|
top: discord.Option(
|
||||||
async def meme(self, ctx: commands.Context, template, top, bottom):
|
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,
|
||||||
|
),
|
||||||
|
):
|
||||||
import meme_gen
|
import meme_gen
|
||||||
|
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
|
@ -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
|
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"
|
url = "https://starcitizen.tools/Category:Ships"
|
||||||
|
|
||||||
response = requests.get(url).text
|
response = requests.get(url).text
|
||||||
soup = BeautifulSoup(response, "html.parser")
|
soup = BeautifulSoup(response, "html.parser")
|
||||||
h2_heading = soup.find("h2", text='Pages in category "Ships"')
|
h2_heading = soup.find("h2", text='Pages in category "Ships"')
|
||||||
|
return [link.text for link in h2_heading.find_next("div").find_all("a")]
|
||||||
all_ships = [link.text for link in h2_heading.find_next("div").find_all("a")]
|
|
||||||
|
|
||||||
return all_ships
|
|
||||||
|
|
||||||
@starcitizen.command(
|
@starcitizen.command(
|
||||||
guild_ids=core_utils.my_guilds,
|
guild_ids=core_utils.my_guilds,
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
import help_methods
|
|
||||||
|
|
||||||
supported_templates = sorted(
|
supported_templates = sorted(
|
||||||
list(
|
list(
|
||||||
map(
|
map(
|
||||||
@ -51,9 +49,3 @@ def get_meme_url(template, top, bottom, usesTemplate):
|
|||||||
if usesTemplate:
|
if usesTemplate:
|
||||||
meme = "{}/{}/{}/{}.{}".format(base_URL, template, top, bottom, default_format)
|
meme = "{}/{}/{}/{}.{}".format(base_URL, template, top, bottom, default_format)
|
||||||
return meme
|
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)
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user