Created
October 3, 2017 14:53
-
-
Save boazcstrike/39ef45377f74e75bb1d8e604fbcab323 to your computer and use it in GitHub Desktop.
A simple discord bot that pings the pubg servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Discord = require('discord.io'); | |
var logger = require('winston'); | |
var auth = require('./auth.json'); | |
var ping = require('ping'); | |
const fs = require("fs"); | |
var hosts = ["13.228.0.251", "46.51.216.14", "46.137.255.254", "52.74.0.2", "52.76.0.2", "52.76.191.252", "52.77.63.252", "52.221.255.252","54.151.128.2", "54.169.0.2", "54.169.191.253", "54.179.0.2", "54.179.191.252", "54.251.63.255","54.254.128.1", "54.255.0.2", "122.248.255.254", "175.41.146.190", "13.54.63.252", "52.62.63.252", "52.64.63.253", "52.64.191.252", "52.65.63.252", "54.66.0.2", "54.66.191.252", "54.79.127.252", "54.153.191.252", "54.206.127.254", "54.206.128.2", "54.252.88.8", "54.253.0.1"]; | |
var msglg = ""; | |
// Configure logger settings | |
logger.remove(logger.transports.Console); | |
logger.add(logger.transports.Console, { | |
colorize: true | |
}); | |
logger.level = 'debug'; | |
// Initialize Discord Bot | |
var bot = new Discord.Client({ | |
token: auth.token, | |
autorun: true | |
}); | |
//connect to discord | |
bot.on('ready', function (evt) { | |
logger.info('Connected'); | |
logger.info('Logged in as: '); | |
logger.info(bot.username + ' - (' + bot.id + ')'); | |
}); | |
//client on message | |
bot.on('message', function (user, userID, channelID, message, evt) { | |
if (message.substring(0, 1) == '!') { //!ping | |
var args = message.substring(1).split(' '); | |
var cmd = args[0]; | |
args = args.splice(1); | |
switch(cmd) { | |
case 'help': | |
bot.sendMessage({ | |
to: channelID, | |
message: '```PUBG SEA servers down? \nType .ping\nType .1 until .4 to view Singapore servers\.5 until .8 to view Australian Servers\.pingt for hosts latency```' | |
}); | |
break; | |
} | |
} | |
if (message.substring(0, 1) == '.') { //.ping | |
var args = message.substring(1).split(' '); | |
var cmd = args[0]; | |
args = args.splice(1); | |
if(cmd == 'ping'){ | |
msglg += "```First 18 servers are Singapore Servers, the rest are Australian Servers. (Type .ping again if nothing shows up)"; | |
hosts.forEach(function(host){ | |
ping.sys.probe(host, function(isAlive){ | |
msglg += isAlive ? '\n' + host + ': active' : '\n' + host + ' down'; | |
}); | |
}); | |
msglg += "```"; | |
bot.sendMessage({ | |
to: channelID, | |
message: msglg | |
}); | |
msglg = ""; | |
} | |
else if(cmd === 'pingt'){ | |
msglg += "```First 18 servers are Singapore Servers, the rest are Australian Servers. (Type .pingt again if nothing shows up)"; | |
hosts.forEach(function (host) { | |
ping.promise.probe(host) | |
.then(function (max) { | |
msglg += max["host"] +': ' + max["time"] + 'ms; Status: '; | |
if(max['alive'] == 1){ | |
msglg += 'online'; | |
}else if(max['alive'] == 0){ | |
msglg += 'offline'; | |
} | |
msglg += '\n'; | |
}) | |
.done(); | |
}) | |
msglg += "```"; | |
bot.sendMessage({ | |
to: channelID, | |
message: msglg | |
}); | |
msglg = ""; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment