-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (57 loc) · 2.24 KB
/
index.js
File metadata and controls
57 lines (57 loc) · 2.24 KB
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
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const http = __importStar(require("request"));
const discord = __importStar(require("discord.js"));
const bot = new discord.Client;
const config = {
"token": "", //The token of your discord bot.
"guild": "", //The guild (id) with those \/ channels.
"devteam": "", // A admin / dev role that is allowed to force an update of the player count with 5m=update.
"refreshtime": 30, // how often the player count is updated in seconds.
"servers": [
"",
//"name ip:port DiscordVoiceChannelID"
]
};
console.log(`Starting bot...\n Created by Whit3Xlightning (https://whitelightning.dev)`);
bot.on("message", message => {
if (message.content == "5m=update" && message.member.roles.has(config.devteam)) {
if (message.deletable) {
message.delete();
}
updatePlayers();
message.reply("Forced a update of the player count(s).");
}
});
bot.login(config.token);
let updatePlayerInterval = setInterval(() => updatePlayers(), config.refreshtime * 1000);
function updatePlayers() {
config.servers.forEach(server => {
var args = server.split(" ");
let guild = bot.guilds.get(config.guild);
if (guild) {
var channel = guild.channels.get(args[2]);
}
http.get(`http://${args[1]}/dynamic.json`, { json: true }, (err, res, data) => {
if (err) {
if (err.code == "ECONNREFUSED" || err.code == "ETIMEDOUT") {
if (channel) {
channel.setName(`${args[0]}: Offline`);
return;
}
}
}
if (channel) {
channel.setName(`${data.clients} / ${data.sv_maxclients}`);
}
console.log(`${new Date().toISOString()}: ${data.clients} / ${data.sv_maxclients}`);
});
});
}