Customize les reminder per minor

pull/93/head
Stijn De Clercq 2021-09-26 21:24:34 +02:00
parent 1ee9900891
commit 04d03fa2cb
5 changed files with 44 additions and 5 deletions

View File

@ -203,7 +203,7 @@ class Tasks(commands.Cog):
continue continue
# Create embed once because this can be heavy # Create embed once because this can be heavy
if "embed" in category: if "embed" in category and category["embed_once"]:
embed = category["embed"]() embed = category["embed"]()
else: else:
embed = None embed = None
@ -219,6 +219,13 @@ class Tasks(commands.Cog):
if "embed" not in category: if "embed" not in category:
await userInstance.send(random.choice(category["messages"])) await userInstance.send(random.choice(category["messages"]))
else: else:
# Embed has to be customized per user
if embed is None and "embed_once" in category:
# TODO clean this up, there's a better way :)
# remind category with a before- method & setup per user
args = category["argsf"](self.client, user)
embed = category["embed"](*args)
await userInstance.send(random.choice(category["messages"]), embed=embed) await userInstance.send(random.choice(category["messages"]), embed=embed)
with open("files/lastTasks.json", "w") as fp: with open("files/lastTasks.json", "w") as fp:

View File

@ -1,3 +1,5 @@
from typing import Optional
from data import schedule from data import schedule
from functions import les, config from functions import les, config
from functions.database import remind from functions.database import remind
@ -13,11 +15,15 @@ class Reminders:
self._les = [int(user[0]) for user in rows if user[2]] self._les = [int(user[0]) for user in rows if user[2]]
self._lesMessages = ["Lessenrooster voor vandaag:"] self._lesMessages = ["Lessenrooster voor vandaag:"]
self.les = {"users": self._les, "messages": self._lesMessages, "embed": self.lesEmbed, "weekends": False, "disabled": True} self.les = {"users": self._les, "messages": self._lesMessages, "embed": self.les_embed, "argsf": schedule.find_minor, "embed_once": False, "weekends": False, "disabled": False}
self.categories = [self.nightly, self.les] self.categories = [self.nightly, self.les]
def lesEmbed(self): def les_embed(self, minor: Optional[int] = None):
dt = les.find_target_date() dt = les.find_target_date()
s = schedule.Schedule(dt, int(config.get("year")), int(config.get("semester"))) s = schedule.Schedule(dt, int(config.get("year")), int(config.get("semester")))
if minor is not None:
return s.create_schedule(minor_roles=[minor]).to_embed()
return s.create_schedule().to_embed() return s.create_schedule().to_embed()

View File

@ -3,10 +3,13 @@ from dacite import from_dict
from dataclasses import dataclass, field from dataclasses import dataclass, field
from datetime import datetime, timedelta from datetime import datetime, timedelta
from discord import Colour, Embed from discord import Colour, Embed
from discord.ext import commands
from enums.platform import Platform, get_platform from enums.platform import Platform, get_platform
from functions.timeFormatters import fromArray, intToWeekday, timeFromInt from functions.timeFormatters import fromArray, intToWeekday, timeFromInt
from settings import COC_ID
import json import json
from typing import Dict, Optional, List from typing import Dict, Optional, List, Tuple
@dataclass @dataclass
@ -235,7 +238,7 @@ class Schedule:
return slots_today return slots_today
def create_schedule(self): def create_schedule(self, minor_roles: Optional[List[int]] = None):
""" """
Create the schedule for the current week Create the schedule for the current week
""" """
@ -247,6 +250,10 @@ class Schedule:
# Find minor slots # Find minor slots
for minor in self.schedule_dict["minors"]: for minor in self.schedule_dict["minors"]:
# Customized schedule
if minor_roles is not None and minor["role"] not in minor_roles:
continue
m_slots = [] m_slots = []
for course in minor["schedule"]: for course in minor["schedule"]:
# Go over every course # Go over every course
@ -398,3 +405,16 @@ class ScheduleEmbed(LesEmbed):
return "" return ""
return "\n".join(list(f"{entry.course}: **{entry.get_link_str()}**" for entry in has_link)) return "\n".join(list(f"{entry.course}: **{entry.get_link_str()}**" for entry in has_link))
def find_minor(client: commands.Bot, userid: int) -> Tuple[Optional[int]]:
guild = client.get_guild(COC_ID)
user = guild.get_member(userid)
minors_ids = [891744461405687808, 891744390035415111]
for role in user.roles:
if role.id in minors_ids:
return role.id,
return None,

View File

@ -14,6 +14,7 @@
"minors": [ "minors": [
{ {
"name": "Beveiliging en parallelle systemen", "name": "Beveiliging en parallelle systemen",
"role": 891744461405687808,
"online_links": { "online_links": {
"zoom": "https://ufora.ugent.be/d2l/ext/rp/439235/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826" "zoom": "https://ufora.ugent.be/d2l/ext/rp/439235/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826"
}, },
@ -95,6 +96,7 @@
}, },
{ {
"name": "Elektrotechniek en Telecommunicatie", "name": "Elektrotechniek en Telecommunicatie",
"role": 891744390035415111,
"schedule": [ "schedule": [
{ {
"course": "Inleiding tot Telecommunicatie", "course": "Inleiding tot Telecommunicatie",
@ -170,6 +172,7 @@
}, },
{ {
"name": "Onderwijs", "name": "Onderwijs",
"role": -1,
"schedule": [] "schedule": []
} }
], ],

View File

@ -35,6 +35,9 @@ HOST_IPC = _to_bool(os.getenv("HOSTIPC", "false"))
READY_MESSAGE = os.getenv("READYMESSAGE", "I'M READY I'M READY I'M READY I'M READY") # Yes, this is a Spongebob reference READY_MESSAGE = os.getenv("READYMESSAGE", "I'M READY I'M READY I'M READY I'M READY") # Yes, this is a Spongebob reference
STATUS_MESSAGE = os.getenv("STATUSMESSAGE", "with your Didier Dinks.") STATUS_MESSAGE = os.getenv("STATUSMESSAGE", "with your Didier Dinks.")
# Id's of servers/channels
COC_ID: int = int(os.getenv("COC_ID", "626699611192688641"))
# Guilds to test slash commands in # Guilds to test slash commands in
# Ex: 123,456,789 # Ex: 123,456,789
_guilds = os.getenv("SLASHTESTGUILDS", "").replace(" ", "") _guilds = os.getenv("SLASHTESTGUILDS", "").replace(" ", "")