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

@ -2,6 +2,7 @@ import discord
from discord.ext import commands
from data.embeds.snipe import EditSnipe, DeleteSnipe
from data.links import get_link_for
from data.menus import custom_commands
from data.snipe import Action, Snipe
from decorators import help
@ -17,6 +18,19 @@ class Other(commands.Cog):
def cog_check(self, _):
return not self.client.locked
@commands.command(name="Link", usage="[Naam]")
@help.Category(category=Category.Other)
async def link(self, ctx, name: str):
"""
Send commonly used links
"""
match = get_link_for(name)
if match is None:
return await ctx.reply(f"Geen match gevonden voor \"{name}\".", mention_author=False, delete_after=15)
return await ctx.reply(match, mention_author=False)
@commands.command(name="Custom")
@help.Category(category=Category.Didier)
async def list_custom(self, ctx):

View file

@ -1,4 +1,5 @@
from data import schedule
from data.courses import find_course_from_name
from data.embeds.deadlines import Deadlines
from data.embeds.food import Menu
from decorators import help
@ -85,6 +86,23 @@ class School(commands.Cog):
await message.pin(reason=f"Didier Pin door {ctx.author.display_name}")
await ctx.message.add_reaction("")
@commands.command(name="Fiche", usage="[Vak]", aliases=["guide", "studiefiche"])
@help.Category(category=Category.School)
async def study_guide(self, ctx, name: str):
"""
Send links to study guides
"""
# Find code corresponding to the search query
course = find_course_from_name(name)
# Code not found
if course is None:
return await ctx.reply(f"Onbekend vak: \"{name}\".", mention_author=False, delete_after=15)
# Get the guide for the current year
year = 2018 + int(config.get("year"))
return await ctx.reply(f"https://studiekiezer.ugent.be/studiefiche/nl/{course.code}/{year}", mention_author=False)
@commands.command(name="Deadlines", aliases=["dl"])
@help.Category(category=Category.School)
async def deadlines(self, ctx):

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))