didier/cogs/school.py

68 lines
2.5 KiB
Python
Raw Normal View History

2021-08-08 18:24:53 +02:00
from data import schedule
from decorators import help
import discord
from discord.ext import commands
from enums.help_categories import Category
2021-08-08 18:24:53 +02:00
from functions import config, eten, les
2021-08-08 18:24:11 +02:00
from functions.timeFormatters import intToWeekday
class School(commands.Cog):
def __init__(self, client):
self.client = client
# Don't allow any commands to work when locked
def cog_check(self, ctx):
return not self.client.locked
@commands.command(name="Eten", aliases=["Food", "Menu"], usage="[Dag]*")
# @commands.check(checks.allowedChannels)
@help.Category(category=Category.School)
async def eten(self, ctx, *day):
2021-08-08 18:24:11 +02:00
day_dt = les.find_target_date(day if day else None)
day = intToWeekday(day_dt.weekday())
# Create embed
menu = eten.etenScript(day)
embed = discord.Embed(colour=discord.Colour.blue())
embed.set_author(name="Menu voor {}".format(day))
if "gesloten" in menu[0].lower():
embed.description = "Restaurant gesloten"
else:
embed.add_field(name="Soep:", value=menu[0], inline=False)
embed.add_field(name="Hoofdgerechten:", value=menu[1], inline=False)
if menu[2]:
embed.add_field(name="Groenten:", value=menu[2], inline=False)
embed.set_footer(text="Omwille van de coronamaatregelen is er een beperkter aanbod, en kan je enkel nog eten afhalen. Ter plaatse eten is niet meer mogelijk.")
await ctx.send(embed=embed)
@commands.command(name="Les", aliases=["Class", "Classes", "Sched", "Schedule"], usage="[Jaargang]* [Dag]*")
# @commands.check(checks.allowedChannels)
@help.Category(category=Category.School)
async def les(self, ctx, day=None):
2021-08-08 18:24:11 +02:00
date = les.find_target_date(day)
2021-08-08 18:12:16 +02:00
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())
@commands.command(name="Pin", usage="[Message]")
@help.Category(category=Category.School)
async def pin(self, ctx, message: discord.Message):
# In case people abuse, check if they're blacklisted
blacklist = []
if ctx.author.id in blacklist:
return
if message.is_system():
return await ctx.send("Dus jij wil system messages pinnen?\nMag niet.")
await message.pin(reason="Didier Pin door {}".format(ctx.author.display_name))
await ctx.message.add_reaction("")
def setup(client):
client.add_cog(School(client))