Commit d785bfcb authored by Danny SMc's avatar Danny SMc

Update 2

parent 00f5dfc6
......@@ -7,10 +7,25 @@
*/
console.log("[INFO]: Starting ShinexusUK Server IRC Bot");
var irc = require("irc"),
unirest = require("unirest");
fs = require("fs");
// Get Log Name:
var d = new Date(),
n = d.getTime(),
logname = "bot_log_" + n.toString();
function addlog(text) {
var newstr = text + "\n";
fs.appendFile("./data/" + logname + ".log", newstr, function(err) {
if (err) return console.log(err);
});
}
console.log("[INFO]: Starting ShinexusUK Server IRC Bot");
addlog("[INFO]: Starting ShinexusUK Server IRC Bot");
var pre = "!",
mute = false;
......@@ -19,6 +34,7 @@ var pre = "!",
admin = "dannysmc95";
console.log("[INFO]: Connecting to IRC");
addlog("[INFO]: Connecting to IRC");
var bot = new irc.Client("irc.esper.net", "ShinexusBot", {
channels: ["#shinexusuk"],
......@@ -27,6 +43,7 @@ var bot = new irc.Client("irc.esper.net", "ShinexusBot", {
});
console.log("[INFO]: Connected");
addlog("[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",
......@@ -76,11 +93,12 @@ function getcreative(to, pdata, sdata, func) {
} else {
con = "Offline";
}
bot.say(to, "Please note this can be delayed, due to servers restarting etc, it can take a few moments before the query port is initialised. Current server statuses:");
bot.say(to, "[Proxy]: "+pon+", [Survival]: "+son+", [Creative]: "+con+".");
} else if (func == "players") {
bot.say(to, "Please note this can be delayed, due to servers restarting etc, it can take a few moments before the query port is initialised. Current player count:");
bot.say(to, "[Total]: "+(Number(sdata.players.now)+Number(cdata.players.now))+"/150, [Survival]: "+sdata.players.now+", [Creative]: "+cdata. players.now+".");
}
......@@ -95,6 +113,7 @@ function parsemessage(msg, to, from) {
// Get array
msgs = msg.split(' ');
addlog("[COMMAND]: " + msg);
if (mute == false || msgs[0] == pre+"unmute") {
......@@ -231,7 +250,8 @@ function parsemessage(msg, to, from) {
"Lrn 2 typ,",
"Error 404: Command not found,",
"Great game",
"cAPS LOCK IS ON. cOMMANDS MAY BE cASE-sENSITIVE."
"cAPS LOCK IS ON. cOMMANDS MAY BE cASE-sENSITIVE.",
"[clippy]: It looks like you are trying to enter a command, would you like some help with that?"
];
bot.say(to, errormsgs[Math.floor(Math.random() * errormsgs.length)]);
......@@ -254,8 +274,25 @@ bot.addListener("message", function(from, to, message) {
parsemessage(message, to, from);
});
// Listen for console commands
var stdin = process.openStdin();
stdin.addListener("data", function(d) {
var inp = d.toString().substring(0, d.length-1);
// Do stuff with inp ( the input)
});
// Listen for PM's.
bot.addListener("pm", function(nick, text, message) {
if(text == "Hi"){
bot.say(nick, "Hello!");
}
});
// Prevent crashes
process.on('uncaughtException', function(err){
console.error(err.stack);
console.log("Node NOT Exiting.");
addlog(err.stack);
console.error(err.stack);
console.log("Node NOT Exiting.");
});
\ 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