forked from z4ika/fonline-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
86 lines (69 loc) · 2.21 KB
/
bot.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const token = process.env.TOKEN;
const serverAddress = process.env.SERVER_ADDRESS;
const serverPort = process.env.SERVER_PORT;
const net = require('net');
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client(
{
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
],
});
client.on("ready", function()
{
bot_FOnline();
});
client.login(token);
let buff = Buffer.from( [0xFF, 0xFF, 0xFF, 0xFF] );
let onlineLast = 0;
function bot_FOnline()
{
try
{
var connection = new net.Socket();
connection.setTimeout(10000);
connection.connect(serverPort, serverAddress, function()
{
connection.write(buff);
});
connection.on('data', function (data)
{
var buffer = Buffer.from(' ', "hex" );
buffer = Buffer.concat([buffer, Buffer.from(data, "hex" )]);
online = buffer.readUInt32LE(0);
uptimeRaw = buffer.readUInt32LE(4);
if (online != '')
{
console.log( (new Date).toLocaleTimeString() + " Online: " + online);
var date = new Date( Math.round( uptimeRaw * 1000 ) );
uptimeString = date.getHours() + "h";
change = Math.abs(onlineLast - online);
if( onlineLast < online && (online - onlineLast) > 5 )
changeString = `+${change} ⇑`;
else if( onlineLast < online )
changeString = `+${change} ⇗`;
else if( onlineLast > online && (onlineLast - online) > 5 )
changeString = `-${change} ⇓`;
else if( onlineLast > online )
changeString = `-${change} ⇘`;
else
changeString = `-`;
client.user.setActivity(`O: ${online} | CH: ${changeString} | UP: ${uptimeString}`);
onlineLast = online;
}
connection.destroy();
});
connection.on('error', function (err)
{
client.user.setActivity("Bad omen! Can't reach Core!")
connection.destroy();
});
setTimeout(bot_FOnline, 60000);
}
catch (error)
{
console.log(error);
}
}