mirror of https://github.com/stijndcl/didier
Customize les reminder per minor
parent
1ee9900891
commit
04d03fa2cb
|
@ -203,7 +203,7 @@ class Tasks(commands.Cog):
|
|||
continue
|
||||
|
||||
# Create embed once because this can be heavy
|
||||
if "embed" in category:
|
||||
if "embed" in category and category["embed_once"]:
|
||||
embed = category["embed"]()
|
||||
else:
|
||||
embed = None
|
||||
|
@ -219,6 +219,13 @@ class Tasks(commands.Cog):
|
|||
if "embed" not in category:
|
||||
await userInstance.send(random.choice(category["messages"]))
|
||||
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)
|
||||
|
||||
with open("files/lastTasks.json", "w") as fp:
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from typing import Optional
|
||||
|
||||
from data import schedule
|
||||
from functions import les, config
|
||||
from functions.database import remind
|
||||
|
@ -13,11 +15,15 @@ class Reminders:
|
|||
|
||||
self._les = [int(user[0]) for user in rows if user[2]]
|
||||
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]
|
||||
|
||||
def lesEmbed(self):
|
||||
def les_embed(self, minor: Optional[int] = None):
|
||||
dt = les.find_target_date()
|
||||
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()
|
||||
|
|
|
@ -3,10 +3,13 @@ from dacite import from_dict
|
|||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, timedelta
|
||||
from discord import Colour, Embed
|
||||
from discord.ext import commands
|
||||
|
||||
from enums.platform import Platform, get_platform
|
||||
from functions.timeFormatters import fromArray, intToWeekday, timeFromInt
|
||||
from settings import COC_ID
|
||||
import json
|
||||
from typing import Dict, Optional, List
|
||||
from typing import Dict, Optional, List, Tuple
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -235,7 +238,7 @@ class Schedule:
|
|||
|
||||
return slots_today
|
||||
|
||||
def create_schedule(self):
|
||||
def create_schedule(self, minor_roles: Optional[List[int]] = None):
|
||||
"""
|
||||
Create the schedule for the current week
|
||||
"""
|
||||
|
@ -247,6 +250,10 @@ class Schedule:
|
|||
|
||||
# Find minor slots
|
||||
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 = []
|
||||
for course in minor["schedule"]:
|
||||
# Go over every course
|
||||
|
@ -398,3 +405,16 @@ class ScheduleEmbed(LesEmbed):
|
|||
return ""
|
||||
|
||||
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,
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"minors": [
|
||||
{
|
||||
"name": "Beveiliging en parallelle systemen",
|
||||
"role": 891744461405687808,
|
||||
"online_links": {
|
||||
"zoom": "https://ufora.ugent.be/d2l/ext/rp/439235/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826"
|
||||
},
|
||||
|
@ -95,6 +96,7 @@
|
|||
},
|
||||
{
|
||||
"name": "Elektrotechniek en Telecommunicatie",
|
||||
"role": 891744390035415111,
|
||||
"schedule": [
|
||||
{
|
||||
"course": "Inleiding tot Telecommunicatie",
|
||||
|
@ -170,6 +172,7 @@
|
|||
},
|
||||
{
|
||||
"name": "Onderwijs",
|
||||
"role": -1,
|
||||
"schedule": []
|
||||
}
|
||||
],
|
||||
|
|
|
@ -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
|
||||
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
|
||||
# Ex: 123,456,789
|
||||
_guilds = os.getenv("SLASHTESTGUILDS", "").replace(" ", "")
|
||||
|
|
Loading…
Reference in New Issue