forked from Bbeniz/Le_vide
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathautoUptime.js
46 lines (42 loc) · 1.46 KB
/
autoUptime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const axios = require('axios');
const { config } = global.GoatBot;
const { log, getText } = global.utils;
if (global.timeOutUptime != undefined)
clearTimeout(global.timeOutUptime);
if (!config.autoUptime.enable)
return;
const PORT = config.dashBoard?.port || (!isNaN(config.serverUptime.port) && config.serverUptime.port) || 3001;
let myUrl = config.autoUptime.url || `https://${process.env.REPL_OWNER
? `${process.env.REPL_SLUG}.${process.env.REPL_OWNER}.repl.co`
: process.env.API_SERVER_EXTERNAL == "https://api.glitch.com"
? `${process.env.PROJECT_DOMAIN}.glitch.me`
: `localhost:${PORT}`}`;
myUrl.includes('localhost') && (myUrl = myUrl.replace('https', 'http'));
myUrl += '/uptime';
let status = 'ok';
setTimeout(async function autoUptime() {
try {
await axios.get(myUrl);
if (status != 'ok') {
status = 'ok';
log.info("UPTIME", "Bot is online");
// Custome notification here
}
}
catch (e) {
const err = e.response?.data || e;
if (status != 'ok')
return;
status = 'failed';
if (err.statusAccountBot == "can't login") {
log.err("UPTIME", "Can't login account bot");
// Custome notification here
}
else if (err.statusAccountBot == "block spam") {
log.err("UPTIME", "Your account is blocked");
// Custome notification here
}
}
global.timeOutUptime = setInterval(autoUptime, config.autoUptime.timeInterval);
}, (config.autoUptime.timeInterval || 180) * 1000);
log.info("AUTO UPTIME", getText("autoUptime", "sucautoUptimecess", myUrl));