├── config.txt
├── README.md
├── LICENSE
└── index.js
/config.txt:
--------------------------------------------------------------------------------
1 | {
2 | "token":"bot-token",
3 | "serverip":"servers-ip",
4 | "serverport":"servers-port",
5 | "channelid":"channel-ID-for-notifications",
6 | "yourid":"your-discord-id"
7 | }
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Server-Status
2 | A Discord BOT / Node JS Application that send notifications if your server (website) goes offline, also shows current status in a desired channel.
3 |
4 | #### Channel Status Preview
5 |
6 |
7 | #### DM Notification Preview
8 |
9 |
10 | # Features
11 | * DM's when server becomes unreachable.
12 | * Shows current status of your server in a channel of your choice "updates".
13 |
14 | # Installation
15 | Clone this repo and edit the config file.
16 |
17 | # Usage
18 | Once you have edited the code you can simply run it using node index.js
19 |
20 | # Upcoming Features
21 | * Email / SMS Notifications
22 | * Webhooks
23 | * LOG time when server goes down
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 PapaSnags
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 | const Client = new Discord.Client();
3 | const DBL = require("dblapi.js");
4 | var fs = require('fs')
5 | //Logins the bot to discord
6 |
7 | var data = fs.readFileSync('config.txt', 'utf8');
8 | const config = JSON.parse(data);
9 | console.log(config.serverip)
10 |
11 | Client.login(config.token);
12 |
13 |
14 | var net = require('net');
15 | //Sets Server IP and port to ping
16 | var hosts = [[config.serverip, config.serverport]];
17 | Client.on('ready', async message=>{
18 | //Sends an editable message that will change depending on your server status
19 | const msg = Client.channels.cache.get(config.channelid).send("Getting Server Status ...").then((msg)=>{
20 | function intervalFunc() {
21 | hosts.forEach(function(item) {
22 | var sock = new net.Socket();
23 | sock.setTimeout(2500);
24 | //ONLINE
25 | sock.on('connect', function() {
26 | //If server is online logs console
27 | console.log(item[0]+':'+item[1]+' is up.');
28 | //Edits the message
29 | msg.edit('Website is Online ✅')
30 | sock.destroy();
31 |
32 | //OFFLINE
33 | }).on('error', function(e) {
34 | //If server is offline logs console
35 | console.log(item[0]+':'+item[1]+' is down: ' + e.message);
36 | //Edits the message
37 | msg.edit('Website is Offline ❌')
38 | //Sends message to user to tell them server is offline
39 | Client.users.cache.get(config.yourid).send('Website is Offline ❌');
40 |
41 | //SERVER TIMEOUT
42 | }).on('timeout', function(e) {
43 | //If server is offline - timesout logs console
44 | console.log(item[0]+':'+item[1]+' is down: timeout');
45 | //Edits the message
46 | msg.edit('Website is Offline ❌')
47 | //Sends message to user to tell them server is offline
48 | Client.users.cache.get(config.yourid).send('Website is Offline ❌');
49 | }).connect(item[1], item[0]);
50 | });
51 | }
52 | setInterval(intervalFunc, 5500);
53 | })
54 | })
55 |
56 | //LOGS console if sucesfully launches and adds a status
57 | Client.on('ready', ()=>{
58 | console.log("BOT is online!")
59 | Client.user.setActivity('STATUS')
60 | });
61 |
--------------------------------------------------------------------------------