2022-03-11 14:11:59 +01:00
|
|
|
import json
|
|
|
|
|
|
|
|
from discord import SlashCommandGroup
|
2021-09-26 22:12:52 +02:00
|
|
|
from discord.ext import commands
|
2022-02-11 22:11:20 +01:00
|
|
|
from discord.commands import slash_command, ApplicationContext, Option, AutocompleteContext
|
2021-09-26 22:12:52 +02:00
|
|
|
|
2021-11-29 21:48:30 +01:00
|
|
|
from data import schedule
|
2022-02-11 22:11:20 +01:00
|
|
|
from data.courses import load_courses, find_course_from_name
|
2021-11-05 23:36:12 +01:00
|
|
|
from data.embeds.food import Menu
|
2021-11-29 21:37:04 +01:00
|
|
|
from data.embeds.deadlines import Deadlines
|
2022-03-11 14:11:59 +01:00
|
|
|
from data.menus import leaderboards
|
2021-11-29 21:48:30 +01:00
|
|
|
from functions import les, config
|
|
|
|
from functions.stringFormatters import capitalize
|
|
|
|
from functions.timeFormatters import skip_weekends
|
2021-09-26 22:12:52 +02:00
|
|
|
from startup.didier import Didier
|
|
|
|
|
|
|
|
|
2022-02-11 22:11:20 +01:00
|
|
|
# Preload autocomplete constants to allow for smoother results
|
|
|
|
courses = load_courses()
|
|
|
|
days = ["Morgen", "Overmorgen", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag"]
|
|
|
|
|
|
|
|
|
|
|
|
def day_autocomplete(ctx: AutocompleteContext) -> list[str]:
|
|
|
|
return [day for day in days if day.lower().startswith(ctx.value.lower())]
|
|
|
|
|
|
|
|
|
|
|
|
def course_autocomplete(ctx: AutocompleteContext) -> list[str]:
|
|
|
|
return [course for course in courses if course.lower().startswith(ctx.value.lower())]
|
|
|
|
|
|
|
|
|
2021-09-26 22:12:52 +02:00
|
|
|
class SchoolSlash(commands.Cog):
|
|
|
|
def __init__(self, client: Didier):
|
|
|
|
self.client: Didier = client
|
|
|
|
|
2022-02-03 01:43:54 +01:00
|
|
|
@slash_command(name="eten", description="Menu in de UGent resto's op een bepaalde dag")
|
|
|
|
async def _food_slash(self, ctx: ApplicationContext,
|
2022-02-11 22:11:20 +01:00
|
|
|
dag: Option(str, description="Dag", required=False, default=None, autocomplete=day_autocomplete)
|
2022-02-03 01:43:54 +01:00
|
|
|
):
|
2021-11-05 23:36:12 +01:00
|
|
|
embed = Menu(dag).to_embed()
|
2022-02-03 01:43:54 +01:00
|
|
|
await ctx.respond(embed=embed)
|
2021-09-26 22:12:52 +02:00
|
|
|
|
2021-11-29 21:37:04 +01:00
|
|
|
@slash_command(name="deadlines", description="Aanstaande deadlines")
|
2022-02-03 01:43:54 +01:00
|
|
|
async def _deadlines_slash(self, ctx: ApplicationContext):
|
2021-11-29 21:37:04 +01:00
|
|
|
embed = Deadlines().to_embed()
|
2022-02-03 01:43:54 +01:00
|
|
|
await ctx.respond(embed=embed)
|
2021-11-29 21:37:04 +01:00
|
|
|
|
2022-02-03 01:43:54 +01:00
|
|
|
@slash_command(name="les", description="Lessenrooster voor [Dag] (default vandaag)",)
|
|
|
|
async def _schedule_slash(self, ctx: ApplicationContext,
|
2022-02-11 22:11:20 +01:00
|
|
|
dag: Option(str, description="Dag", required=False, default=None, autocomplete=day_autocomplete)
|
2022-02-03 01:43:54 +01:00
|
|
|
):
|
2021-11-29 21:48:30 +01:00
|
|
|
"""It's late and I really don't want to refactor the original right now"""
|
2022-02-11 22:11:20 +01:00
|
|
|
if dag is not None:
|
|
|
|
dag = dag.lower()
|
2021-11-29 21:48:30 +01:00
|
|
|
|
2022-02-11 22:11:20 +01:00
|
|
|
date = les.find_target_date(dag)
|
2021-11-29 21:48:30 +01:00
|
|
|
|
|
|
|
# Person explicitly requested a weekend-day
|
2022-02-11 22:11:20 +01:00
|
|
|
if dag is not None and dag.lower() in ("morgen", "overmorgen") and date.weekday() > 4:
|
|
|
|
return await ctx.respond(f"{capitalize(dag)} is het weekend.", ephemeral=True)
|
2021-11-29 21:48:30 +01:00
|
|
|
|
|
|
|
date = skip_weekends(date)
|
|
|
|
|
2022-02-11 22:11:20 +01:00
|
|
|
s = schedule.Schedule(date, int(config.get("year")), int(config.get("semester")), dag is not None)
|
2021-11-29 21:48:30 +01:00
|
|
|
|
|
|
|
if s.semester_over:
|
2022-02-03 01:43:54 +01:00
|
|
|
return await ctx.respond("Het semester is afgelopen.", ephemeral=True)
|
2021-11-29 21:48:30 +01:00
|
|
|
|
|
|
|
# DM only shows user's own minor
|
2022-02-03 01:43:54 +01:00
|
|
|
if ctx.guild is None:
|
|
|
|
minor_roles = [*schedule.find_minor(self.client, ctx.interaction.user.id)]
|
|
|
|
return await ctx.respond(embed=s.create_schedule(minor_roles=minor_roles).to_embed())
|
2021-11-29 21:48:30 +01:00
|
|
|
|
2022-02-03 01:43:54 +01:00
|
|
|
return await ctx.respond(embed=s.create_schedule().to_embed())
|
2021-11-29 21:48:30 +01:00
|
|
|
|
2022-02-11 22:11:20 +01:00
|
|
|
@slash_command(name="fiche", description="Zoek de studiefiche voor een vak.")
|
|
|
|
async def _study_guide_slash(self, ctx: ApplicationContext,
|
2022-02-11 22:26:23 +01:00
|
|
|
vak: Option(str, description="Naam van het vak. Afkortingen werken ook, maar worden niet geautocompletet.",
|
2022-02-11 22:11:20 +01:00
|
|
|
required=True, autocomplete=course_autocomplete)):
|
|
|
|
# Find code corresponding to the search query
|
|
|
|
course = find_course_from_name(vak, courses)
|
|
|
|
|
|
|
|
# Code not found
|
|
|
|
if course is None:
|
|
|
|
return await ctx.respond(f"Onbekend vak: \"{vak}\".", ephemeral=True)
|
|
|
|
|
|
|
|
# Get the guide for the current year
|
|
|
|
year = 2018 + int(config.get("year"))
|
|
|
|
return await ctx.respond(f"https://studiekiezer.ugent.be/studiefiche/nl/{course.code}/{year}")
|
|
|
|
|
2022-03-11 14:11:59 +01:00
|
|
|
_compbio_group = SlashCommandGroup("compbio", "Commands voor compbio opdrachten")
|
|
|
|
|
|
|
|
@_compbio_group.command(name="leaderboard", description="Gesorteerd en ingevuld leaderboard")
|
2022-03-12 21:03:01 +01:00
|
|
|
async def _compbio_lb_slash(self, ctx: ApplicationContext,
|
|
|
|
benchmark: Option(int, "De specifieke benchmark om op te halen (default k=600)", choices=[6, 10, 50, 600], default=600)):
|
2022-03-12 10:31:41 +01:00
|
|
|
await ctx.response.defer()
|
2022-03-12 21:03:01 +01:00
|
|
|
lb = leaderboards.CompbioLeaderboard(ctx, kmer=benchmark)
|
2022-03-11 14:11:59 +01:00
|
|
|
await lb.respond()
|
|
|
|
|
|
|
|
@_compbio_group.command(name="submit", description="Link een Dodona-submission aan jouw username")
|
|
|
|
async def _compbio_submit_slash(self, ctx: ApplicationContext,
|
|
|
|
submission: Option(int, description="Id van je Dodona indiening.", required=True)):
|
2022-03-12 10:31:41 +01:00
|
|
|
await ctx.response.defer(ephemeral=True)
|
|
|
|
|
2022-03-11 14:11:59 +01:00
|
|
|
with open("files/compbio_benchmarks_2.json", "r") as fp:
|
|
|
|
file = json.load(fp)
|
|
|
|
|
|
|
|
submission = str(submission)
|
|
|
|
|
|
|
|
if submission in file:
|
2022-03-12 10:31:41 +01:00
|
|
|
return await ctx.send_followup("❌ Deze submission is al aan iemand gelinkt.")
|
2022-03-11 14:11:59 +01:00
|
|
|
|
|
|
|
with open("files/compbio_benchmarks_2.json", "w") as fp:
|
|
|
|
file[submission] = ctx.user.id
|
|
|
|
json.dump(file, fp)
|
|
|
|
|
2022-03-12 10:31:41 +01:00
|
|
|
return await ctx.send_followup(f"✅ Submission **{submission}** is aan jouw naam gelinkt.")
|
2022-03-11 14:11:59 +01:00
|
|
|
|
2021-09-26 22:12:52 +02:00
|
|
|
|
|
|
|
def setup(client: Didier):
|
|
|
|
client.add_cog(SchoolSlash(client))
|