summaryrefslogtreecommitdiff
path: root/includes/external/school/index.js
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-03-21 16:21:21 +0100
committerRaindropsSys <contact@minteck.org>2023-03-21 16:21:21 +0100
commit475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd (patch)
tree2cff46debf9c1e13892e7babff9deb6874ecb4b2 /includes/external/school/index.js
parent7ccc2de87f9e25c715dc09b9aba4eb5c66f80424 (diff)
downloadpluralconnect-475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd.tar.gz
pluralconnect-475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd.tar.bz2
pluralconnect-475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd.zip
Updated 26 files and added 1074 files (automated)
Diffstat (limited to 'includes/external/school/index.js')
-rw-r--r--includes/external/school/index.js32
1 files changed, 15 insertions, 17 deletions
diff --git a/includes/external/school/index.js b/includes/external/school/index.js
index c8f053c..58947ec 100644
--- a/includes/external/school/index.js
+++ b/includes/external/school/index.js
@@ -6,12 +6,19 @@ const url = config.pronote.url;
const username = config.pronote.user;
const password = config.pronote.password;
-async function getTimetable(offset) {
+async function getTimetable(offset, last) {
const timetable = lessons;
- let nextClass = timetable.filter(i => new Date(i.from.toDateString()).getTime() === new Date(new Date(new Date().toDateString()).getTime() + 86400000 * offset).getTime()).filter(i => !i.isCancelled)[0];
+ if (last) {
+ let list = timetable.filter(i => new Date(i.from.toDateString()).getTime() === new Date(new Date(new Date().toDateString()).getTime() + 86400000 * offset).getTime()).filter(i => !i.isCancelled);
+ let lastClass = list[list.length - 1];
- return nextClass ? nextClass["from"] : null;
+ return lastClass ? lastClass["to"] : null;
+ } else {
+ let nextClass = timetable.filter(i => new Date(i.from.toDateString()).getTime() === new Date(new Date(new Date().toDateString()).getTime() + 86400000 * offset).getTime()).filter(i => !i.isCancelled)[0];
+
+ return nextClass ? nextClass["from"] : null;
+ }
}
global.wakeUpTime = null;
@@ -26,20 +33,6 @@ global.firstClassTime = null;
global.firstClassClockC = null;
global.firstClassClockR = null;
-async function nightWarning() {
- if (global.sleepTimeDiff) {
- await notification("🌙 Good evening!", "You are going to sleep " + global.sleepTimeDiff + ", " + global.sleepClockC + " BST (" + global.sleepClockR + " CEST) so you can wake up " + global.wakeUpTimeDiff + ", " + global.wakeUpClockC + " BST (" + global.wakeUpClockR + " CEST). You will be reminded when it's time to go to sleep.", 3);
- } else {
- await notification("🌙 Good evening!", "You don't need to wake up at a specific time tomorrow, enjoy!", 3);
- }
-}
-
-async function nightReminder() {
- if (global.sleepTimeDiff) {
- await notification("🌙 Now let's sleep!", "You should get ready to sleep now so you can wake up " + global.wakeUpTimeDiff + ", " + global.wakeUpClockC + " BST (" + global.wakeUpClockR + " CEST).", 3);
- }
-}
-
function digits(input) {
if (input < 10) {
return "0" + input;
@@ -83,6 +76,7 @@ async function updateSleepTime(offset) {
global.firstClassTime = classTime;
global.firstClassClockC = formatHours(firstClassTime.getUTCHours() + (tzOffset - 1)) + ":" + digits(firstClassTime.getUTCMinutes());
global.firstClassClockR = formatHours(firstClassTime.getUTCHours() + tzOffset) + ":" + digits(firstClassTime.getUTCMinutes());
+ global.lastClassTime = await getTimetable(offset, true);
} else {
global.wakeUpTime = null;
global.wakeUpClockR = null;
@@ -91,6 +85,8 @@ async function updateSleepTime(offset) {
global.firstClassTime = null;
global.firstClassClockC = null;
global.firstClassClockR = null;
+
+ global.lastClassTime = null;
}
if (classTime2) {
@@ -163,6 +159,7 @@ async function display(offset) {
let date = new Date(new Date().getTime() + 86400000 * i).toISOString().split("T")[0];
json[date] = {
+ end: null,
firstClass: {
timestamp: null,
cloudburst: null,
@@ -193,6 +190,7 @@ async function display(offset) {
json[date].wakeUp.timestamp = wakeUpTime ? wakeUpTime.getTime() : null;
json[date].wakeUp.cloudburst = wakeUpClockC ?? null;
json[date].wakeUp.raindrops = wakeUpClockR ?? null;
+ json[date].end = lastClassTime ?? null;
}
console.log(json);