From c51bc4bb323eb661e540bc10f0e8e4ec11d50a91 Mon Sep 17 00:00:00 2001 From: Myx Date: Sat, 14 Oct 2023 20:27:09 +0200 Subject: [PATCH] Added next play time to html page --- bot.ts | 4 ++++ client/web/client.js | 12 +++++++++++ client/web/index.html | 34 ++++++++++++++++++++----------- client/web/logo.svg | 47 +++++++++++++++++++++++++++++++++++++++++++ client/webserver.ts | 6 ++++++ 5 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 client/web/logo.svg diff --git a/bot.ts b/bot.ts index 38f4bfa..8438c69 100644 --- a/bot.ts +++ b/bot.ts @@ -14,6 +14,7 @@ import * as schedule from 'node-schedule'; dotenv.config(); +export var nextPlayBackTime: string = ''; const minTime = parseInt(process.env.INTERVALMIN_MINUTES!, 10); // Minimum interval in minutes const maxTime = convertHoursToMinutes(parseInt(process.env.INTERVALMAX_HOURS!, 10)); // Maximum interval in minutes const voiceChannelRetries = parseInt(process.env.VOICECHANNELRETRIES!, 10); // Number of retries to find a voice channel with members in it @@ -113,6 +114,8 @@ function scheduleNextJoin(){ log(randomInterval); + nextPlayBackTime = new Date(new Date().getTime() + randomInterval * 60000).toLocaleTimeString(); + const minutes = randomInterval % 60; const hours = Math.floor(randomInterval / 60); @@ -130,6 +133,7 @@ function log(waitTime: number){ const nextJoinTime = new Date(currentTime.getTime() + waitTime * 60000); const minutes = waitTime % 60; const hours = Math.floor(waitTime / 60); + console.log( LoggerColors.Cyan, ` Wait time: ${waitTime} minutes, diff --git a/client/web/client.js b/client/web/client.js index 9347f11..dccb80f 100644 --- a/client/web/client.js +++ b/client/web/client.js @@ -1,3 +1,14 @@ +function loadNextPlaybackTime() { + fetch('/nextplaybacktime') + .then(response => response.text()) + .then(data => { + const nextPlaybackTime = document.getElementById('nextPlaybackTime'); + nextPlaybackTime.textContent = `Playing next time: ${data}`; + } + ) + .catch(error => console.error('Error:', error)); +} + function loadFiles() { // Fetch the JSON data from the /sounds endpoint fetch('/sounds') @@ -51,6 +62,7 @@ function loadFiles() { // Call loadFiles when the script is loaded loadFiles(); +loadNextPlaybackTime(); document.getElementById('uploadForm').addEventListener('submit', function(event) { event.preventDefault(); diff --git a/client/web/index.html b/client/web/index.html index 60a8383..d36c920 100644 --- a/client/web/index.html +++ b/client/web/index.html @@ -11,22 +11,32 @@
-
-
-
-
-

Upload Sound

-
- File: - + Logo +
+
+
+ +
+

Upload Sound

+
+ File: + +
+
- -
- + +
+

Info

+
+
+
+
+ +

Uploaded Files

-
+
diff --git a/client/web/logo.svg b/client/web/logo.svg new file mode 100644 index 0000000..326a26a --- /dev/null +++ b/client/web/logo.svg @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/client/webserver.ts b/client/webserver.ts index 7fbc61d..479c24f 100644 --- a/client/webserver.ts +++ b/client/webserver.ts @@ -1,3 +1,4 @@ +import { nextPlayBackTime } from './../bot'; import express from 'express'; import multer, { diskStorage } from 'multer'; import path from 'path'; @@ -11,6 +12,7 @@ const storage = diskStorage({ } }); + const upload = multer({ storage: storage, limits: { fileSize: 1 * 1024 * 1024 }, @@ -41,6 +43,10 @@ app.get('/sounds', (_req, res) => { }); }); +app.get('/nextplaybacktime', (_req, res) => { + res.send(nextPlayBackTime); +}); + app.delete('/sounds/:filename', (req, res) => { const fs = require('fs'); const directoryPath = path.join(__dirname, '../sounds');