Haha-Yes/events/client/uptime.js

27 lines
704 B
JavaScript
Raw Normal View History

2022-08-14 22:28:14 +02:00
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)}`);
}