Separate uptime from ready
This commit is contained in:
parent
c52b19a678
commit
6a089e9674
2 changed files with 28 additions and 15 deletions
|
@ -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)}`);
|
||||
}
|
27
events/client/uptime.js
Normal file
27
events/client/uptime.js
Normal file
|
@ -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)}`);
|
||||
}
|
Loading…
Reference in a new issue