mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Add commands for deadlines
This commit is contained in:
parent
693fab7833
commit
fccf4efa1f
10 changed files with 183 additions and 3 deletions
68
data/embeds/deadlines.py
Normal file
68
data/embeds/deadlines.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import json
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
|
||||
from discord import Embed, Colour
|
||||
from functions.stringFormatters import get_edu_year
|
||||
from typing import Dict
|
||||
|
||||
"""
|
||||
Sample json structure:
|
||||
{
|
||||
"1": {
|
||||
"ad1": {
|
||||
"proj1": 123456789
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
@dataclass
|
||||
class Deadline:
|
||||
course: str
|
||||
name: str
|
||||
t: int
|
||||
passed: bool
|
||||
|
||||
def __str__(self) -> str:
|
||||
v = f"{self.course} - {self.name}: <t:{self.t}:R>"
|
||||
|
||||
if self.passed:
|
||||
v = f"~~v~~"
|
||||
|
||||
return v
|
||||
|
||||
|
||||
class Deadlines:
|
||||
data: Dict
|
||||
|
||||
def __init__(self):
|
||||
with open("files/deadlines.json") as f:
|
||||
self.data = json.load(f)
|
||||
|
||||
def to_embed(self) -> Embed:
|
||||
embed = Embed(colour=Colour.dark_gold())
|
||||
embed.set_author(name="Aanstaande Deadlines")
|
||||
|
||||
now = time.time()
|
||||
|
||||
if not self.data:
|
||||
embed.description = "Er staan geen deadlines gepland."
|
||||
return embed
|
||||
|
||||
courses: Dict
|
||||
for year, courses in self.data.items():
|
||||
content = []
|
||||
|
||||
deadlines: Dict[str, int]
|
||||
for course, deadlines in courses.items():
|
||||
for deadline, t in deadlines.items():
|
||||
content.append(Deadline(course, deadline, t, t < now))
|
||||
|
||||
content.sort(key=lambda x: x.t)
|
||||
content = map(lambda x: str(x), content)
|
||||
|
||||
embed.add_field(name=get_edu_year(int(year)), value="\n".join(content))
|
||||
|
||||
return embed
|
||||
Loading…
Add table
Add a link
Reference in a new issue