You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Haha-Yes/events/client/uptime.js

25 lines
658 B
JavaScript

import https from 'node:https';
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)}`);
}