summaryrefslogtreecommitdiff
path: root/alarm/index.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2023-01-10 14:54:04 +0100
committerMinteck <contact@minteck.org>2023-01-10 14:54:04 +0100
commit99c1d9af689e5325f3cf535c4007b3aeb8325229 (patch)
treee663b3c2ebdbd67c818ac0c5147f0ce1d2463cda /alarm/index.js
parent9871b03912fc28ad38b4037ebf26a78aa937baba (diff)
downloadpluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.gz
pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.bz2
pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.zip
Update - This is an automated commit
Diffstat (limited to 'alarm/index.js')
-rw-r--r--alarm/index.js107
1 files changed, 0 insertions, 107 deletions
diff --git a/alarm/index.js b/alarm/index.js
deleted file mode 100644
index a601ab6..0000000
--- a/alarm/index.js
+++ /dev/null
@@ -1,107 +0,0 @@
-const axios = require('axios');
-const pronote = require('pronote-api');
-const config = require('../includes/app.json');
-
-const url = config.pronote.url;
-const username = config.pronote.user;
-const password = config.pronote.password;
-
-async function getTimetable() {
- const session = await pronote.login(url, username, password);
- const timetable = await session.timetable();
-
- let nextClass = timetable.filter(i => !i.isCancelled)[0];
-
- return nextClass ? nextClass["from"] : null;
-}
-
-async function notification(title, content, priority) {
- await fetch("https://" + config.ntfy.server, {
- method: "POST",
- body: JSON.stringify({
- topic: config.ntfy.topic,
- message: content,
- title: title,
- tags: [ "alarm" ],
- priority: priority
- }),
- headers: {
- "Authorization": "Basic " + Buffer.from(config.ntfy.user + ":" + config.ntfy.password).toString("base64"),
- "Content-Type": "application/json"
- }
- })
-}
-
-global.wakeUpTime = null;
-global.wakeUpTimeDiff = null;
-global.sleepTime = null;
-global.sleepTimeDiff = null;
-global.sleepClockR = null;
-global.sleepClockC = null;
-global.wakeUpClockC = null;
-global.wakeUpClockR = 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;
- } else {
- return input;
- }
-}
-
-async function updateSleepTime() {
- let classTime = await getTimetable();
-
- if (classTime) {
- global.wakeUpTime = new Date(classTime.getTime() - 5100000);
- global.sleepTime = new Date(global.wakeUpTime.getTime() - 27000000);
-
- let diff = (wakeUpTime - new Date().getTime()) / 1000;
- let diffHours = Math.floor(diff / 3600);
- let diffMinutes = Math.floor((diff - diffHours * 3600) / 60);
-
- global.wakeUpTimeDiff = "in " + diffHours + " hour" + (diffHours > 1 ? "s" : "") + (diffMinutes > 0 ? " and " + diffMinutes + " minute" + (diffMinutes > 1 ? "s" : "") : "");
-
- let diff2 = (sleepTime - new Date().getTime()) / 1000;
- let diffHours2 = Math.floor(diff2 / 3600);
- let diffMinutes2 = Math.floor((diff2 - diffHours2 * 3600) / 60);
-
- global.sleepTimeDiff = "in " + diffHours2 + " hour" + (diffHours2 > 1 ? "s" : "") + (diffMinutes2 > 0 ? " and " + diffMinutes2 + " minute" + (diffMinutes2 > 1 ? "s" : "") : "");
-
- global.sleepClockR = (sleepTime.getUTCHours() + 2) + ":" + digits(sleepTime.getUTCMinutes());
- global.sleepClockC = (sleepTime.getUTCHours() + 1) + ":" + digits(sleepTime.getUTCMinutes());
- global.wakeUpClockR = (wakeUpTime.getUTCHours() + 2) + ":" + digits(wakeUpTime.getUTCMinutes());
- global.wakeUpClockC = (wakeUpTime.getUTCHours() + 1) + ":" + digits(wakeUpTime.getUTCMinutes());
- } else {
- global.wakeUpTime = null;
- global.wakeUpTimeDiff = null;
- global.sleepTime = null;
- global.sleepTimeDiff = null;
- }
-
- console.log(global.wakeUpTime, "Waking up " + global.wakeUpTimeDiff + " (" + global.wakeUpClockR + "/" + global.wakeUpClockC + "), sleeping " + global.sleepTimeDiff + " (" + global.sleepClockR + "/" + global.sleepClockC + ")");
-}
-
-(async () => {
- //await notification("Test notification", "Testing notification latency, you can safely ignore this notification.", 3);
- setInterval(async () => {
- await updateSleepTime();
- }, 3600000);
-
- await updateSleepTime();
- await nightReminder();
-})() \ No newline at end of file