Commit d2fda534 authored by Danny SMc's avatar Danny SMc

Finished basic commands

parent 85490f78
/*
Name: ShinexusUK IRC Helper Bot:
Author: DannySMc & Max Thor (c) Copyright
Description:
This bot was made to help the channel: #shinexusuk to help connect with the main server, this includes functions to request details from the server itself, it was the main reason to get who is online, and even the MOTD.
Name: ShinexusUK IRC Bot
Author: (c) DannySMc & (Help from MAx Thor)
Description:
This bot adds some extra functions for the server cluster including status, players, motd, and more. Also includes some random commands as well.
*/
console.log("Running ShinexusUK Server Bot!");
var irc = require('irc'),
sys = require('sys'),
unirest = require('unirest'),
ex = require('child_process').exec,
child,
pre = "!";
console.log("Connecting to IRC Channel: #shinexusuk");
var bot = new irc.Client('irc.esper.net', 'DaveBot_Shinexus', {
channels: ['#shinexusuk'],
realName: 'ShinexusUK Server Bot',
autoRejoin: true
console.log("[INFO]: Starting ShinexusUK Server IRC Bot");
var irc = require("irc"),
unirest = require("unirest"),
pre = "!";
console.log("[INFO]: Connecting to IRC");
var bot = new irc.Client("irc.esper.net", "ShinexusBot", {
channels: ["#shinexusuk"],
realName: "ShinexusUK Server Bot",
autoRejoin: true
});
console.log("Connected!");
console.log("[INFO]: Connected");
var proxy = "https://mcapi.us/server/status?ip=185.38.149.35&port=25578",
survival = "https://mcapi.us/server/status?ip=185.38.148.138&port=25594",
creative = "https://mcapi.us/server/status?ip=185.38.148.138&port=25609";
function getAdmins(){
fs.readFile('./settings/admins.txt', encoding="UTF-8", function(err, data){
if(err) throw err;
global; admins;
admins = data.split("\n");
});
}
// Get server data
function getproxy(to) {
function getproxy(to, func) {
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!");
main = response["raw_body"];
pdata = JSON.parse(main);
getsurvival(to, pdata, func);
});
}
function getsurvival(to, pdata) {
function getsurvival(to, pdata, func) {
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!");
main = response["raw_body"];
sdata = JSON.parse(main);
getcreative(to, pdata, sdata, func);
});
}
function getcreative(to, pdata, sdata) {
function getcreative(to, pdata, sdata, func) {
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 = response["raw_body"];
cdata = JSON.parse(main);
if (func == "status") {
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+".");
} else if (func == "players") {
bot.say(to, "[Total]: "+(Number(sdata.players.now)+Number(cdata.players.now))+"/150, [Survival]: "+sdata.players.now+", [Creative]: "+cdata. players.now+".");
}
});
}
// Main logic:
function parsemessage(msg, to) {
function parsemessage(msg, to, from) {
// Execute files
function pu(o,t,f){if(o)throw o;if(f)throw f;bot.say(to,t)}
if (msg.substring(0,1) == pre) {
// Get array
msgs = msg.split(' ');
// Run Login
if (msgs[0] == pre+"help") {
bot.say(to, "Help & Commands can be found here: https://server.dannysmc.com/bots.html");
} else if (msgs[0] == pre+"status") {
// Get status of server, should return online/offline - player count for each server - motd
console.log("Processing...");
getproxy(to);
getproxy(to, "status");
} else if (msgs[0] == pre+"software") {
......@@ -107,12 +115,19 @@ function parsemessage(msg, to) {
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
// Should return the player list for each server
getproxy(to, "players");
} else if (msgs[0] == pre+"motd") {
// Should return the message of the day.
var Request = unirest.get(survival);
Request.header('Accept', 'application/json').end(function (response) {
main = response["raw_body"];
sdata = JSON.parse(main);
bot.say(to, "MOTD: "+sdata.motd);
});
} else if (msgs[0] == pre+"define") {
......@@ -124,31 +139,37 @@ function parsemessage(msg, to) {
.header("Accept", "text/plain")
.end(function (result) {
a = result.body['list'];
a = result.body['list'];
if(a.length >= 1){
if(a.length >= 1){
q = result.body['list'][0];
q = result.body['list'][0];
def = q['definition'].replace("\n","");
def = q['definition'].replace("\n","");
if(def.length >= 300){
def = def.substring(0, 300)+"...";
}
if(def.length >= 300){
def = def.substring(0, 300)+"...";
}
bot.say(to, "Definition of "+term+": "+def+" (http://urbandictionary.com/"+term+")");
bot.say(to, "Definition of "+term+": "+def+" (http://urbandictionary.com/"+term+")");
}else{
}else{
bot.say(to, "Can't find a definiton for "+term);
bot.say(to, "Can't find a definiton for "+term);
}
});
}
});
} else if (msgs[0] == pre+"ip") {
bot.say(to, "ShinexusUK IP Address: shinexusuk.nitrous.it");
// Display Server IP Address
bot.say(to, "ShinexusUK IP Address: shinexusuk.nitrous.it");
} else if (msgs[0] == pre+"rules") {
// Display rules
bot.say(to, "ShinexusUK Server Rules: 1. No stealing, 2. No griefing other players or server buildings, 3. No using others computers without permission, 4. No racist or any other type of disrespectful language, 5. We are a community, if you can't play along, you WILL be banned.");
} else {
var errormsgs = [
......@@ -173,15 +194,17 @@ function parsemessage(msg, to) {
// Listen for joins
bot.addListener("join", function(channel, who) {
// Welcome them in!
bot.say(channel, who + ": Welcome to ShinexusUK, I am an automated helper bot, do "+pre+"help for options.");
// Welcome new members
bot.say(channel,"Welcome "+ who +" to the ShinexusUK Channel. I am an automated bot with all kinds of knowledge. Use: "+pre+"help for help. I can get the status of the servers or even the player count!");
});
// 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);
parsemessage(message, to, from);
});
// Prevent crashes
......
dannysmc95
\ No newline at end of file
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