Add slash command to send links, add normal commands for study guides & links

This commit is contained in:
Stijn De Clercq 2022-02-11 22:54:40 +01:00
parent 9819e82638
commit 0165700d9f
6 changed files with 74 additions and 3 deletions

View file

@ -1,9 +1,16 @@
from discord.ext import commands
from discord.commands import slash_command, ApplicationContext
from discord.commands import slash_command, ApplicationContext, AutocompleteContext, Option
from requests import get
from data.links import load_all_links, get_link_for
from startup.didier import Didier
links = load_all_links()
def link_autocomplete(ctx: AutocompleteContext) -> list[str]:
return [link for link in links if link.lower().startswith(ctx.value.lower())]
class OtherSlash(commands.Cog):
def __init__(self, client: Didier):
@ -18,6 +25,17 @@ class OtherSlash(commands.Cog):
else:
await ctx.respond("Uh oh API down.")
@slash_command(name="link", description="Shortcut voor nuttige links.")
async def _link_slash(self, ctx: ApplicationContext,
name: Option(str, description="Naam van de link.", required=True,
autocomplete=link_autocomplete)):
match = get_link_for(name)
if match is None:
return await ctx.respond(f"Geen match gevonden voor \"{name}\".")
return await ctx.respond(match)
def setup(client: Didier):
client.add_cog(OtherSlash(client))