2021-04-05 15:27:58 +02:00
import random
2021-08-06 20:52:56 +02:00
from data import constants , schedule
2020-10-13 21:02:40 +02:00
from decorators import help
import discord
from discord . ext import commands
from enums . courses import years
from enums . help_categories import Category
2021-08-06 20:52:56 +02:00
from functions import checks , eten , les , les_rework
2020-10-13 21:02:40 +02:00
import json
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]* " )
2021-02-08 18:25:25 +01:00
# @commands.check(checks.allowedChannels)
2020-10-13 21:02:40 +02:00
@help.Category ( category = Category . School )
async def eten ( self , ctx , * day ) :
2020-10-23 22:20:40 +02:00
day = les . getWeekDay ( None if len ( day ) == 0 else day ) [ 1 ]
2020-10-13 21:02:40 +02:00
# 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 )
2020-10-23 21:34:10 +02:00
@commands.command ( name = " Les " , aliases = [ " Class " , " Classes " , " Sched " , " Schedule " ] , usage = " [Jaargang]* [Dag]* " )
2021-02-08 18:25:25 +01:00
# @commands.check(checks.allowedChannels)
2020-10-13 21:02:40 +02:00
@help.Category ( category = Category . School )
2021-08-06 20:52:56 +02:00
async def les ( self , ctx , day = None ) :
date = les_rework . find_target_date ( day )
s = schedule . Schedule ( date , day is not None )
2021-05-14 02:08:28 +02:00
return
# parsed = les.parseArgs(day)
#
# # Invalid arguments
# if not parsed[0]:
# return await ctx.send(parsed[1])
#
# day, dayDatetime, semester, year = parsed[1:]
#
# # Customize the user's schedule
# schedule = self.customizeSchedule(ctx, year, semester)
#
# # Create the embed
# embed = les.createEmbed(day, dayDatetime, semester, year, schedule)
#
# await ctx.send(embed=embed)
2020-12-11 16:10:22 +01:00
2020-10-13 21:02:40 +02:00
# Add all the user's courses
def customizeSchedule ( self , ctx , year , semester ) :
2020-10-23 22:12:05 +02:00
schedule = les . getSchedule ( semester , year )
2020-10-23 22:01:51 +02:00
2020-10-23 23:50:37 +02:00
COC = self . client . get_guild ( int ( constants . CallOfCode ) )
if COC is None :
return schedule
member = COC . get_member ( ctx . author . id )
2020-10-13 21:02:40 +02:00
for role in member . roles :
for univYear in years :
for course in univYear :
if course . value [ " year " ] < year and course . value [ " id " ] == role . id and course . value [ " semester " ] == semester :
with open ( " files/schedules/ {} {} .json " . format ( course . value [ " year " ] , course . value [ " semester " ] ) ,
" r " ) as fp :
sched2 = json . load ( fp )
for val in sched2 :
if val [ " course " ] == course . value [ " name " ] :
val [ " custom " ] = course . value [ " year " ]
schedule . append ( val )
return schedule
2021-02-08 18:46:15 +01:00
@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
2021-06-02 15:52:53 +02:00
if message . is_system ( ) :
return await ctx . send ( " Dus jij wil system messages pinnen? \n Mag niet. " )
2021-02-08 18:46:15 +01:00
await message . pin ( reason = " Didier Pin door {} " . format ( ctx . author . display_name ) )
2021-06-02 15:52:53 +02:00
await ctx . message . add_reaction ( " ✅ " )
2021-02-08 18:46:15 +01:00
2020-10-13 21:02:40 +02:00
def setup ( client ) :
client . add_cog ( School ( client ) )