commit a4de510ab25a88a31a3acf53322204fbc03bb307
parent 0a9a2bd9f9bb69fa33e176ae2ff228425ea1089c
Author: Marcel Radzio <marcel@radzio-sh.de>
Date: Fri, 11 Dec 2015 14:11:22 +0100
fixed IRC Bot. Bot works now
Diffstat:
| M | handlers/irc.js | | | 85 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- |
| M | main.js | | | 30 | +++++++++++++++++++++++------- |
2 files changed, 101 insertions(+), 14 deletions(-)
diff --git a/handlers/irc.js b/handlers/irc.js
@@ -1,22 +1,93 @@
var irc = require('irc');
-module.exports = {
- ircPreload: function (){
- var bot = new irc.Client('irc.lugfl.de', 'DoorBot', {
+var bot = new irc.Client('irc.lugfl.de', 'DoorBot', {
debug: true,
channels: ['#hackerspace'],
+ autoRejoin: false,
+ autoConnect: false,
messageSplit: 1000000
});
+var request = require('request');
+module.exports = {
+ ircPreload: function (){
bot.addListener('error', function(message) {
console.log('error: ', message);
+ setTimeout(function() { console.log("wait 7sek"); }, 7000);
+ irc.ircNick();
+ bot.say('NickServ', 'identify DoorBotPass');
});
+ setTimeout(function() { console.log("wait 7sek"); }, 7000);
bot.connect(10, function() {
- bot.send('msg', 'NickServ identify DoorBot');
+ bot.send('nick', 'DoorBot');
+ bot.say('NickServ', 'identify DoorBotPass');
+ bot.join('#hackerspace');
bot.say('#hackerspace', 'Door Bot is starting to watch on the Door Status');
- });
-
+ })
},
ircSend: function (door_status){
bot.say('#hackerspace', 'Door Status changed to: ' + door_status);
-
+ console.log("IRC Door Status Chnaged");
+ },
+ ircStopp: function() {
+ bot.disconnect('Bot was stopped!');
+ },
+ ircBotCommands: function(){
+ bot.addListener('message', function (from, to, message) {
+ if (message == "!help"){
+ console.log(from + ' => ' + to + ': ' + message);
+ bot.say(from, "Here is your Help!\nCommand List:\n- !help - Shows this page.\n- !DoorStatus - Shows the actual Door Status in an PM\n- !DoorStatus channel - Shows the actual Door Status in the channel drom where it was run");
+ }
+ if (message == "!DoorStatus"){
+ request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) {
+ if (!error && response.statusCode == 200) {
+ door_status = body;
+ //console.log(body);
+ }else{
+ door_status = error;
+ //console.log(error);
+ }
+ if (door_status == "geschlossen"){
+ door_status = "closed";
+ }else{
+ door_status = "open";
+ }
+ console.log(from + ' => ' + to + ': ' + message);
+ bot.say(from, "DoorStatus is: " + door_status);
+ }).setMaxListeners(0);
+ }
+ if (message == "!DoorStatus channel"){
+ request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) {
+ if (!error && response.statusCode == 200) {
+ door_status = body;
+ //console.log(body);
+ }else{
+ door_status = error;
+ //console.log(error);
+ }
+ if (door_status == "geschlossen"){
+ door_status = "closed";
+ }else{
+ door_status = "open";
+ }
+ console.log(from + ' => ' + to + ': ' + message);
+ bot.say(to, "DoorStatus is: " + door_status);
+ }).setMaxListeners(0);
+ }
+ if (message == "!kill"){
+ if ((from == "DasNordlicht") || (from == "MTRNord")) {
+ console.log(from + ' => ' + to + ': ' + message);
+ if (process.platform === "win32") {
+ var rl = require("readline").createInterface({
+ input: process.stdin,
+ output: process.stdout
+ });
+ bot.disconnect('Bot was stopped!');
+ process.exit();
+ }
+ }
+ }
+ })
+ },
+ ircNick: function() {
+ bot.send('nick', 'DoorBot');
}
};
\ No newline at end of file
diff --git a/main.js b/main.js
@@ -17,10 +17,10 @@ irc.ircPreload();
function MakePush(){
request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) {
if (!error && response.statusCode == 200) {
- var door_status = body;
+ door_status = body;
//console.log(body);
}else{
- var door_status = error;
+ door_status = error;
//console.log(error);
}
console.log("Current Real State:" + door_status + "\n");
@@ -36,14 +36,29 @@ request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, re
}
//ADD MODULE RUNTIMES DOWN HERE
pushbullet.pushbulletSend(door_status);
- irc.ircSend(door_status);
+ //irc.ircSend(door_status);
}else{
door_status2 = door_status;
}
}
console.log("WAIT!");
- sleep(9*1000);
- MakePush();
-});
+ if (process.platform === "win32") {
+ var rl = require("readline").createInterface({
+ input: process.stdin,
+ output: process.stdout
+ });
+
+ rl.on("SIGINT", function () {
+ process.emit("SIGINT");
+ });
+ }
+
+ process.on("SIGINT", function () {
+ irc.ircStopp();
+ process.exit();
+ });
+ setTimeout(function() { MakePush(); }, 10000);
+}).setMaxListeners(0);
}
-MakePush();
+irc.ircBotCommands();
+setTimeout(function() { MakePush(); }, 20000);
+\ No newline at end of file