From 6a089e9674de8370bdb68e2e466c324836e4ce8d Mon Sep 17 00:00:00 2001
From: Supositware <sup@libtar.de>
Date: Sun, 14 Aug 2022 22:28:14 +0200
Subject: [PATCH] Separate uptime from ready

---
 events/client/ready.js  | 16 +---------------
 events/client/uptime.js | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 15 deletions(-)
 create mode 100644 events/client/uptime.js

diff --git a/events/client/ready.js b/events/client/ready.js
index 7baf732..1dfa498 100644
--- a/events/client/ready.js
+++ b/events/client/ready.js
@@ -1,8 +1,6 @@
 import { exec } from 'node:child_process';
-import https from 'node:https';
 import dotenv from 'dotenv';
 dotenv.config();
-const { uptimeURL, uptimeInterval } = process.env;
 
 export default {
 	name: 'ready',
@@ -33,17 +31,5 @@ export default {
 		console.log(`There is \x1b[33m${commandSize}\x1b[0m command loaded.`);
 		console.log(`Running yt-dlp \x1b[33m${ytdlpVersion.replace('\n', '')}\x1b[0m`);
 		console.log('===========[ READY ]===========');
-
-		if (uptimeURL != '') {
-			pingStatus(client, 'Starting up');
-
-			setInterval(() => {
-				pingStatus(client, 'OK');
-			}, uptimeInterval * 1000);
-		}
 	},
-};
-
-async function pingStatus(client, msg) {
-	https.get(`${uptimeURL}msg=${msg}&ping=${Math.round(client.ws.ping)}`);
-}
\ No newline at end of file
+};
\ No newline at end of file
diff --git a/events/client/uptime.js b/events/client/uptime.js
new file mode 100644
index 0000000..6f27d19
--- /dev/null
+++ b/events/client/uptime.js
@@ -0,0 +1,27 @@
+import https from 'node:https';
+import dotenv from 'dotenv';
+dotenv.config();
+const { uptimeURL, uptimeInterval } = process.env;
+
+export default {
+	name: 'ready',
+	once: true,
+	async execute(client) {
+		if (uptimeURL != '') {
+			const interval = uptimeInterval ? uptimeInterval : 60;
+			console.log(`Sending uptime to ${uptimeURL} every ${interval} seconds.`);
+			pingStatus(client, 'Starting', 'Starting up');
+
+			setInterval(() => {
+				pingStatus(client, 'up', 'OK');
+			}, interval * 1000);
+		}
+		else {
+			console.error('No uptime url set up.');
+		}
+	},
+};
+
+async function pingStatus(client, status, msg) {
+	https.get(`${uptimeURL}?status=${status}&msg=${msg}&ping=${Math.round(client.ws.ping)}`);
+}
\ No newline at end of file