From 41ee5a74a6901e0117d6186585e343ef5bd1ca21 Mon Sep 17 00:00:00 2001 From: supositware Date: Thu, 16 Jun 2022 13:29:07 +0200 Subject: [PATCH] Status page for uptime kuma --- .env.example | 4 +++- events/ready.js | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index eb18a070..50a24937 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,5 @@ token=your.token clientId=botClientId -guildId=DevGuildId \ No newline at end of file +guildId=DevGuildId +uptimeURL=uptimeKumaOrWhateverStatusThingYouUseOrJustLeaveEmpty +uptimeInterval=60 \ No newline at end of file diff --git a/events/ready.js b/events/ready.js index be4c2a21..5f81021d 100644 --- a/events/ready.js +++ b/events/ready.js @@ -1,4 +1,7 @@ const { exec } = require('node:child_process'); +const https = require('node:https'); +require('dotenv').config(); +const { uptimeURL, uptimeInterval } = process.env; module.exports = { name: 'ready', @@ -15,6 +18,7 @@ module.exports = { resolve(stdout); }); }); + const commandSize = client.commands.size; const clientTag = client.user.tag; const guildSize = client.guilds.cache.size; @@ -26,7 +30,19 @@ module.exports = { console.log(`Ready to serve in \x1b[33m${channelSize}\x1b[0m channels on \x1b[33m${guildSize}\x1b[0m servers.`); console.log(`${client.readyAt}`); console.log(`There is \x1b[33m${commandSize}\x1b[0m command loaded.`); - console.log(`Running yt-dlp \x1b[33m${ytdlpVersion}\x1b[0m`); + 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