-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
60 lines (53 loc) · 2.07 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
52
53
54
55
56
57
58
59
60
const Discord = require("discord.js");
const Client = new Discord.Client();
const DBL = require("dblapi.js");
var fs = require('fs')
//Logins the bot to discord
var data = fs.readFileSync('config.txt', 'utf8');
const config = JSON.parse(data);
console.log(config.serverip)
Client.login(config.token);
var net = require('net');
//Sets Server IP and port to ping
var hosts = [[config.serverip, config.serverport]];
Client.on('ready', async message=>{
//Sends an editable message that will change depending on your server status
const msg = Client.channels.cache.get(config.channelid).send("Getting Server Status ...").then((msg)=>{
function intervalFunc() {
hosts.forEach(function(item) {
var sock = new net.Socket();
sock.setTimeout(2500);
//ONLINE
sock.on('connect', function() {
//If server is online logs console
console.log(item[0]+':'+item[1]+' is up.');
//Edits the message
msg.edit('Website is Online ✅')
sock.destroy();
//OFFLINE
}).on('error', function(e) {
//If server is offline logs console
console.log(item[0]+':'+item[1]+' is down: ' + e.message);
//Edits the message
msg.edit('Website is Offline ❌')
//Sends message to user to tell them server is offline
Client.users.cache.get(config.yourid).send('Website is Offline ❌');
//SERVER TIMEOUT
}).on('timeout', function(e) {
//If server is offline - timesout logs console
console.log(item[0]+':'+item[1]+' is down: timeout');
//Edits the message
msg.edit('Website is Offline ❌')
//Sends message to user to tell them server is offline
Client.users.cache.get(config.yourid).send('Website is Offline ❌');
}).connect(item[1], item[0]);
});
}
setInterval(intervalFunc, 5500);
})
})
//LOGS console if sucesfully launches and adds a status
Client.on('ready', ()=>{
console.log("BOT is online!")
Client.user.setActivity('STATUS')
});