Commit eefa3f50 authored by Danny SMc's avatar Danny SMc

Fixed status command

parent 81ade863
......@@ -15,7 +15,7 @@ var irc = require('irc'),
console.log("Connecting to IRC Channel: #shinexusuk");
var bot = new irc.Client('irc.esper.net', 'ShinexusUK', {
channels: ['#testchannel1'],
channels: ['#shinexusuk'],
realName: 'ShinexusUK Server Bot',
autoRejoin: true
});
......@@ -27,33 +27,61 @@ var proxy = "https://mcapi.us/server/status?ip=185.38.149.35&port=25578",
// Get server data
function getservers(name) {
if (name == "proxy") {
var Request = unirest.get(proxy);
Request.header('Accept', 'application/json').end(function (response) {
main = response["raw_body"];
data = JSON.parse(main);
console.log(data["motd"]);
return data.motd;
});
} else if (name == "creative") {
var Request = unirest.get(creative);
Request.header('Accept', 'application/json').end(function (response) {
main = response["raw_body"];
data = JSON.parse(main);
return data;
});
} else if (name == "survival") {
var Request = unirest.get(survival);
Request.header('Accept', 'application/json').end(function (response) {
main = response["raw_body"];
data = JSON.parse(main);
return data;
});
}
function getproxy(to) {
var Request = unirest.get(proxy);
Request.header('Accept', 'application/json').end(function (response) {
main = response["raw_body"];
pdata = JSON.parse(main);
getsurvival(to, pdata);
console.log("Completed proxy!");
});
}
function getsurvival(to, pdata) {
var Request = unirest.get(survival);
Request.header('Accept', 'application/json').end(function (response) {
main = response["raw_body"];
sdata = JSON.parse(main);
getcreative(to, pdata, sdata);
console.log("Completed survival!");
});
}
function getcreative(to, pdata, sdata) {
var Request = unirest.get(creative);
Request.header('Accept', 'application/json').end(function (response) {
main = response["raw_body"];
cdata = JSON.parse(main);
console.log("Completed creative!");
if (pdata["online"].toString() == "true") {
pon = "Online";
} else {
pon = "Offline";
}
if (sdata["online"].toString() == "true") {
son = "Online";
} else {
son = "Offline";
}
if (cdata["online"].toString() == "true") {
con = "Online";
} else {
con = "Offline";
}
bot.say(to, "[Proxy]: "+pon+", [Survival]: "+son+", [Creative]: "+con+".");
/*bot.say(to, "Proxy: "+pdata.players.now);
bot.say(to, "Survival: "+sdata.players.now);
bot.say(to, "Creative: "+cdata.players.now);*/
});
}
// Main logic:
......@@ -72,24 +100,13 @@ function parsemessage(msg, to) {
} else if (msgs[0] == pre+"status") {
// Get status of server, should return online/offline - player count for each server - motd
server = getservers("proxy");
console.log("HHH"+server);
console.log("Processing...");
getproxy(to);
/*var data = '';
var Request = unirest.get('https://mcapi.us/server/status?ip=185.38.149.35&port=25578');
Request.header('Accept', 'application/json').end(function (response) {
main = response["raw_body"];
data = JSON.parse(main);
});
console.log(data);
console.log(data.players.now);
//bot.say(to, data.players.now.toString());
bot.say(to, data.toString());
console.log("Finished!");*/
} else if (msgs[0] == pre+"software") {
// Display Software:
bot.say(to, "The software is different for each server. The proxy server uses: BungeeCord, and then the connected servers use: Cauldron, CraftBukkit, MCPC+, FML, Forge.");
} else if (msgs[0] == pre+"players") {
// Should return the player list for each server
......@@ -109,7 +126,6 @@ function parsemessage(msg, to) {
}
}
// Listen for joins
bot.addListener("join", function(channel, who) {
// Welcome them in!
......@@ -119,6 +135,7 @@ bot.addListener("join", function(channel, who) {
// Listen for any message, PM said user when he posts
bot.addListener("message", function(from, to, message) {
//bot.say(to, "Processing...");
to = to;
parsemessage(message, to);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment