mirror of https://github.com/stijndcl/didier
Show custom embed for weekends
parent
a198a83153
commit
e9ea063876
|
@ -4,7 +4,8 @@ import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from enums.help_categories import Category
|
from enums.help_categories import Category
|
||||||
from functions import config, eten, les
|
from functions import config, eten, les
|
||||||
from functions.timeFormatters import intToWeekday
|
from functions.stringFormatters import capitalize
|
||||||
|
from functions.timeFormatters import intToWeekday, skip_weekends
|
||||||
|
|
||||||
|
|
||||||
class School(commands.Cog):
|
class School(commands.Cog):
|
||||||
|
@ -21,6 +22,7 @@ class School(commands.Cog):
|
||||||
@help.Category(category=Category.School)
|
@help.Category(category=Category.School)
|
||||||
async def eten(self, ctx, *day):
|
async def eten(self, ctx, *day):
|
||||||
day_dt = les.find_target_date(day if day else None)
|
day_dt = les.find_target_date(day if day else None)
|
||||||
|
day_dt = skip_weekends(day_dt)
|
||||||
day = intToWeekday(day_dt.weekday())
|
day = intToWeekday(day_dt.weekday())
|
||||||
|
|
||||||
# Create embed
|
# Create embed
|
||||||
|
@ -44,6 +46,13 @@ class School(commands.Cog):
|
||||||
@help.Category(category=Category.School)
|
@help.Category(category=Category.School)
|
||||||
async def les(self, ctx, day=None):
|
async def les(self, ctx, day=None):
|
||||||
date = les.find_target_date(day)
|
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:
|
||||||
|
return await ctx.send(f"{capitalize(day)} is het weekend.")
|
||||||
|
|
||||||
|
date = skip_weekends(date)
|
||||||
|
|
||||||
s = schedule.Schedule(date, int(config.get("year")), int(config.get("semester")), day is not None)
|
s = schedule.Schedule(date, int(config.get("year")), int(config.get("semester")), day is not None)
|
||||||
return await ctx.send(embed=s.create_schedule().to_embed())
|
return await ctx.send(embed=s.create_schedule().to_embed())
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from functions.timeFormatters import dateTimeNow, weekdayToInt, forward_to_weekday
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
|
def find_target_date(arg: Optional[str]) -> datetime:
|
||||||
|
"""
|
||||||
|
Find the requested date out of the user's arguments
|
||||||
|
"""
|
||||||
|
# Start at current date
|
||||||
|
day: datetime = dateTimeNow()
|
||||||
|
|
||||||
|
# If no offset was provided, check the time
|
||||||
|
# otherwise the argument overrides it
|
||||||
|
if arg is None:
|
||||||
|
# When the command is used after 6 pm, show schedule
|
||||||
|
# for the next day instead
|
||||||
|
if day.hour > 18:
|
||||||
|
day += timedelta(days=1)
|
||||||
|
elif 0 <= (weekday := weekdayToInt(arg)) <= 4: # Weekday provided
|
||||||
|
day = forward_to_weekday(day, weekday)
|
||||||
|
elif arg.lower() == "morgen": # Tomorrow's schedule
|
||||||
|
day += timedelta(days=1)
|
||||||
|
elif arg.lower() == "overmorgen": # Day after tomorrow's schedule
|
||||||
|
day += timedelta(days=2)
|
||||||
|
|
||||||
|
return day
|
Loading…
Reference in New Issue