From 475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Tue, 21 Mar 2023 16:21:21 +0100 Subject: Updated 26 files and added 1074 files (automated) --- includes/external/school/index.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'includes/external/school/index.js') 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); -- cgit