This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (47 loc) · 1.58 KB
/
index.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
/**
*
* THIS PROJECT IS DISCONTINUED! The Code still here for archivation purposes, though it WON'T WORK ANYMORE. Please refer to the readme.md.
*/
const Discord = require("discord.js");
const client = new Discord.Client();
const md5 = require("crypto-js/md5");
const fetch = require("node-fetch");
const { token, ip, port } = require("./config.json");
client.once("ready", async () => {
console.log(`Logged in as ${client.user.tag}`);
console.log("Successfully started up!\n\n");
await client.user.setPresence({
activity: { name: "Starting...", type: "PLAYING" },
status: "idle",
});
checkOnlinePlayers();
setInterval(checkOnlinePlayers, 60000);
});
client.login(token);
async function checkOnlinePlayers() {
const hashedAddress = md5(`${ip}:${port}`);
const response = await fetch(`https://sls.helight.dev/game/${hashedAddress}`);
if (response.status === 404) {
return console.error(
"Server is offline or the provided IP and/or port is invalid."
);
} else if (response.status.toString().match(/5../)) {
return console.warn(
"Something is wrong with the Server / Gateway, please try again later."
);
}
const responsejson = await response.json();
const date = new Date();
console.log(
`[${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}] ${ip} queried. ${
responsejson.players
}/${responsejson.maxPlayers} players online.`
);
await client.user.setPresence({
activity: {
name: `${responsejson.players.toString()}/${responsejson.maxPlayers.toString()}`,
type: "PLAYING",
},
status: "online",
});
}