mirror of
https://github.com/Expand-sys/mc-server-monitor
synced 2025-12-15 16:42:13 +11:00
finished ish
This commit is contained in:
parent
33a5815b35
commit
3bd14546e1
4 changed files with 52 additions and 40 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
88
index.ts
88
index.ts
|
|
@ -1,59 +1,71 @@
|
|||
console.log("starting monitor - use nohup to daemonize");
|
||||
const got = require("got");
|
||||
const Gamedig = require('gamedig');
|
||||
const mcs = require('node-mcstatus');
|
||||
|
||||
let serverstatus = 0
|
||||
runevery15seconds(1)
|
||||
function runevery15seconds(i) {
|
||||
setTimeout(() => {
|
||||
Gamedig.query({
|
||||
type: 'minecraft',
|
||||
host: 'mc.emre-personal.net',
|
||||
port: 25565,
|
||||
debug: true,
|
||||
socketTimeout: 3000
|
||||
}).then((state) => {
|
||||
console.log(state);
|
||||
if(serverstatus == 0){
|
||||
var params = {
|
||||
username: "MC-monitor",
|
||||
avatar_url: "https://i.kym-cdn.com/photos/images/newsfeed/001/338/171/d12.jpg",
|
||||
content: "Server is back online",
|
||||
}
|
||||
|
||||
fetch('https://discord.com/api/webhooks/1155727545724047400/IvcXVXZNpX10fwHhPaIZQ6OYl5XJ2f0iFoBhrYnKtGYHWR2_SMHruXyhcIZR8IsY8P8V', {
|
||||
"method":"POST",
|
||||
"headers": {"Content-Type": "application/json"},
|
||||
"body": JSON.stringify(params)
|
||||
})
|
||||
.then(res=> console.log(res))
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
serverstatus = 1
|
||||
|
||||
}).catch((error: any) => {
|
||||
console.log("Server is offline");
|
||||
console.log(error)
|
||||
if( serverstatus == 1){
|
||||
const host = `${process.env.MCADDRESS}`;
|
||||
const port = process.env.PORT;
|
||||
const options = { query: true };
|
||||
|
||||
// The `port` argument is optional and defaults
|
||||
// to 25565. The `options` argument is optional.
|
||||
mcs.statusJava(host, port, options)
|
||||
.then((result) => {
|
||||
if(!result.online && serverstatus == 1){
|
||||
console.log("offline")
|
||||
var params = {
|
||||
username: "MC-monitor",
|
||||
avatar_url: "https://i.kym-cdn.com/photos/images/newsfeed/001/338/171/d12.jpg",
|
||||
content: "Server is Offline <@247288496442703872>",
|
||||
}
|
||||
|
||||
fetch(`${process.env.WEBHOOK}`, {
|
||||
"method":"POST",
|
||||
"headers": {"Content-Type": "application/json"},
|
||||
"body": JSON.stringify(params)
|
||||
})
|
||||
.then(res=> console.log(res))
|
||||
.catch(err => console.error(err));
|
||||
serverstatus = 0
|
||||
}else if(result.online && serverstatus == 0) {
|
||||
console.log("Online")
|
||||
var params = {
|
||||
username: "MC-monitor",
|
||||
avatar_url: "https://i.kym-cdn.com/photos/images/newsfeed/001/338/171/d12.jpg",
|
||||
content: "Server is back online",
|
||||
}
|
||||
|
||||
fetch(`${process.env.WEBHOOK}`, {
|
||||
"method":"POST",
|
||||
"headers": {"Content-Type": "application/json"},
|
||||
"body": JSON.stringify(params)
|
||||
})
|
||||
.then(res=> console.log(res))
|
||||
.catch(err => console.error(err));
|
||||
serverstatus = 1;
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
var params = {
|
||||
username: "MC-monitor",
|
||||
avatar_url: "https://i.kym-cdn.com/photos/images/newsfeed/001/338/171/d12.jpg",
|
||||
content: "Server is Offline <@247288496442703872>",
|
||||
content: "Checking service is Offline",
|
||||
}
|
||||
console.log(error)
|
||||
fetch('https://discord.com/api/webhooks/1155727545724047400/IvcXVXZNpX10fwHhPaIZQ6OYl5XJ2f0iFoBhrYnKtGYHWR2_SMHruXyhcIZR8IsY8P8V', {
|
||||
fetch(`${process.env.WEBHOOK}`, {
|
||||
"method":"POST",
|
||||
"headers": {"Content-Type": "application/json"},
|
||||
"body": JSON.stringify(params)
|
||||
})
|
||||
.then(res=> console.log(res))
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
serverstatus = 0
|
||||
|
||||
|
||||
});
|
||||
runevery15seconds(++i);
|
||||
}, 5000)
|
||||
})
|
||||
runevery15seconds(++i)
|
||||
}, process.env.CHECK_TIMER)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
BIN
mc-monitor
BIN
mc-monitor
Binary file not shown.
|
|
@ -9,7 +9,7 @@
|
|||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"gamedig": "^4.1.0",
|
||||
"got": "^13.0.0"
|
||||
"got": "^13.0.0",
|
||||
"node-mcstatus": "^1.1.0"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue