didier/didier/cogs/school.py

57 lines
2.1 KiB
Python
Raw Normal View History

import discord
from discord import app_commands
from discord.ext import commands
from database.crud import ufora_courses
2022-08-13 00:07:48 +02:00
from database.crud.deadlines import get_deadlines
from didier import Didier
2022-08-13 00:07:48 +02:00
from didier.data.embeds.deadlines import Deadlines
2022-07-24 17:09:42 +02:00
from didier.utils.discord.flags.school import StudyGuideFlags
class School(commands.Cog):
"""School-related commands"""
client: Didier
def __init__(self, client: Didier):
self.client = client
2022-08-13 00:07:48 +02:00
@commands.hybrid_command(name="deadlines", description="Show upcoming deadlines")
async def deadlines(self, ctx: commands.Context):
"""Show upcoming deadlines"""
async with self.client.postgres_session as session:
deadlines = await get_deadlines(session)
embed = Deadlines(deadlines).to_embed()
2022-08-13 00:07:48 +02:00
await ctx.reply(embed=embed, mention_author=False, ephemeral=False)
@commands.hybrid_command(
2022-07-24 17:09:42 +02:00
name="fiche", description="Sends the link to the study guide for [Course]", aliases=["guide", "studiefiche"]
)
@app_commands.describe(course="The name of the course to fetch the study guide for (aliases work too)")
2022-07-24 17:09:42 +02:00
async def study_guide(self, ctx: commands.Context, course: str, *, flags: StudyGuideFlags):
"""Create links to study guides"""
2022-07-25 20:33:20 +02:00
async with self.client.postgres_session as session:
ufora_course = await ufora_courses.get_course_by_name(session, course)
if ufora_course is None:
2022-08-10 01:04:19 +02:00
return await ctx.reply(f"Found no course matching `{course}`", ephemeral=True)
return await ctx.reply(
2022-07-24 17:09:42 +02:00
f"https://studiekiezer.ugent.be/studiefiche/nl/{ufora_course.code}/{flags.year}",
2022-07-15 23:14:56 +02:00
mention_author=False,
)
@study_guide.autocomplete("course")
async def _study_guide_course_autocomplete(
self, _: discord.Interaction, current: str
) -> list[app_commands.Choice[str]]:
"""Autocompletion for the 'course'-parameter"""
return self.client.database_caches.ufora_courses.get_autocomplete_suggestions(current)
async def setup(client: Didier):
"""Load the cog"""
await client.add_cog(School(client))