-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayerCount.js
60 lines (50 loc) · 1.62 KB
/
playerCount.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
const fetch = require('node-fetch');
const getCurrentPlayers = async (message, playerCount) => {
const ips = [
'http://eu.fanix.io:5751/',
'http://eu.fanix.io:5752/',
'http://eu.fanix.io:5951/',
'http://eu.fanix.io:5952/',
'http://eu.fanix.io:5551/',
'http://eu.fanix.io:5552/',
'http://eu.fanix.io:5651/',
'http://eu.fanix.io:5652/',
];
let playerPeakData = await playerCount.findOne({
where: { id: 1 },
});
let playerPeak = JSON.parse(JSON.stringify(playerPeakData));
let currentPlayers = 0;
for (let i = 0; i < ips.length; i++) {
try {
const response = await fetch(ips[i]);
const stats = await response.json();
currentPlayers += stats.current_players;
console.log(currentPlayers);
} catch (e) {
console.log('Could not fetch\n' + e);
}
}
if (currentPlayers > playerPeak.playerPeak) {
await playerCount.update(
{
playerPeak: currentPlayers,
},
{
where: { id: 1 },
},
);
playerPeakData = await playerCount.findOne({
where: { id: 1 },
});
playerPeak = JSON.parse(JSON.stringify(playerPeakData));
console.log('Updated Peak', playerPeak.playerPeak);
}
await message.guild.channels
.find((channel) => channel.id === '678671710006018089')
.setName(`Playing: ${currentPlayers} | Peak: ${playerPeak.playerPeak}`);
console.log('PlayerCount updated');
};
module.exports = {
getCurrentPlayers,
};