Merge pull request #143 from stijndcl/ufora

Create command to link to Ufora courses
pull/144/head
Stijn De Clercq 2022-10-18 22:40:13 +02:00 committed by GitHub
commit 969c66e2bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -136,7 +136,7 @@ class Fun(commands.Cog):
@commands.hybrid_command(name="xkcd") @commands.hybrid_command(name="xkcd")
@app_commands.rename(comic_id="id") @app_commands.rename(comic_id="id")
async def xkcd(self, ctx: commands.Context, comic_id: Optional[int] = None): async def xkcd(self, ctx: commands.Context, comic_id: Optional[int] = None):
"""Fetch comic `#id` from xkcd """Fetch comic `#id` from xkcd.
If no argument to `id` is passed, this fetches today's comic instead. If no argument to `id` is passed, this fetches today's comic instead.
""" """

View File

@ -116,10 +116,22 @@ class School(commands.Cog):
mention_author=False, mention_author=False,
) )
@commands.hybrid_command(name="ufora")
async def ufora(self, ctx: commands.Context, course: str):
"""Link the Ufora page for a course."""
async with self.client.postgres_session as session:
ufora_course = await ufora_courses.get_course_by_name(session, course)
if ufora_course is None:
return await ctx.reply(f"Found no course matching `{course}`", ephemeral=True)
return await ctx.reply(
f"https://ufora.ugent.be/d2l/le/content/{ufora_course.course_id}/home", mention_author=False
)
@study_guide.autocomplete("course") @study_guide.autocomplete("course")
async def _study_guide_course_autocomplete( @ufora.autocomplete("course")
self, _: discord.Interaction, current: str async def _course_autocomplete(self, _: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
) -> list[app_commands.Choice[str]]:
"""Autocompletion for the 'course'-parameter""" """Autocompletion for the 'course'-parameter"""
return self.client.database_caches.ufora_courses.get_autocomplete_suggestions(current) return self.client.database_caches.ufora_courses.get_autocomplete_suggestions(current)