-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
66 lines (54 loc) · 2.11 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const Config = require("./config.json");
const DiscordBot = require('./DiscordBot.js');
const EmailFetcher = require('./EmailFetcher.js');
const BackersBot = require('./BackersBot.js');
const fetch = require('node-fetch');
function _u(u) { return u + "?rand=" + Math.random() + "-" + Date.now(); }
async function main(){
const dbot=await DiscordBot.init();
const emailFetcher=await EmailFetcher.init(dbot);
const backerBot=await BackersBot.init(dbot);
dbot.addCommand("github",{
cmd:"github",
desc:"Link github repo"
},()=>"https://github.com/jMonkeyEngine/jmonkeyengine");
dbot.addCommand("home",{
cmd:"home",
desc:"Link homepage"
},()=>"https://jmonkeyengine.org");
dbot.addCommand("store",{
cmd:"store",
desc:"Link store"
},()=>"https://store.jmonkeyengine.org");
dbot.addCommand("hub",{
cmd:"hub",
desc:"Link forum"
},()=>"https://hub.jmonkeyengine.org");
dbot.addCommand("containers",{
cmd:"containers",
desc:"Show health of running containers"
}, (args, msg) => {
const url = _u(Config.statusUrl);
fetch(url, { headers: {"Pragma": "no-cache", "Cache-Control": 'no-cache' } }).then(res => res.json()).then(body => {
let empty = true;
for (let key in body) {
let emoji = ":thinking: ";
empty = false;
try {
if (!body[key].status) throw "Undefined status";
if (body[key].status == "healthy") emoji = ":white_check_mark: ";
else if (body[key].status == "unhealthy") emoji = ":x:"
msg.reply(`${emoji} **${key}**: ${body[key].status} `);
} catch (e1) {
msg.reply(`${emoji} **${key}**: unknown`);
console.error(e1);
}
}
if (empty) msg.reply(":moyai: **monitor is down**");
}).catch((e) => {
console.error(e);
msg.reply(":moyai: **monitor is down**");
});
});
}
main();