2021-09-26 22:12:52 +02:00
|
|
|
from discord.ext import commands
|
2022-02-03 01:43:54 +01:00
|
|
|
from discord.commands import slash_command, ApplicationContext, Option
|
2021-09-26 22:12:52 +02:00
|
|
|
|
2021-11-29 21:48:30 +01:00
|
|
|
from data import schedule
|
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
|
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
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
dag: Option(str, description="Dag", required=False, default=None)
|
|
|
|
):
|
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,
|
|
|
|
day: Option(str, description="Dag", required=False, default=None)
|
|
|
|
):
|
2021-11-29 21:48:30 +01:00
|
|
|
"""It's late and I really don't want to refactor the original right now"""
|
|
|
|
if day is not None:
|
|
|
|
day = day.lower()
|
|
|
|
|
|
|
|
date = les.find_target_date(day)
|
|
|
|
|
|
|
|
# Person explicitly requested a weekend-day
|
|
|
|
if day is not None and day.lower() in ("morgen", "overmorgen") and date.weekday() > 4:
|
2022-02-03 01:43:54 +01:00
|
|
|
return await ctx.respond(f"{capitalize(day)} is het weekend.", ephemeral=True)
|
2021-11-29 21:48:30 +01:00
|
|
|
|
|
|
|
date = skip_weekends(date)
|
|
|
|
|
|
|
|
s = schedule.Schedule(date, int(config.get("year")), int(config.get("semester")), day is not None)
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-09-26 22:12:52 +02:00
|
|
|
|
|
|
|
def setup(client: Didier):
|
|
|
|
client.add_cog(SchoolSlash(client))
|