freifunk-bot

Modular parser for the hackerspace door status with handlers for multiple services
git clone git://archive.git.mtrnord.blog/MTRNord/freifunk-bot.git
Log | Files | Refs | README | LICENSE

commit 8af4445f00136a81ee6b1bd8bd7d77b8409ca94a
parent 8c96c0d2489619cc765a6bee9b502e7364b7abd3
Author: Sara Hester <hester.sara@gmail.com>
Date:   Sun, 13 Dec 2015 01:07:34 +0100

Einrueckungen
Diffstat:
Mhandlers/irc.js | 244++++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 122 insertions(+), 122 deletions(-)

diff --git a/handlers/irc.js b/handlers/irc.js @@ -8,11 +8,12 @@ var bot = new irc.Client('irc.lugfl.de', 'NordlabBot', { }); var request = require('request'); var command_config = require("../commands.json"); + module.exports = { - ircEndCustom: function (meassage){ + ircEndCustom: function (meassage) { bot.disconnect(meassage); }, - ircPreload: function (){ + ircPreload: function () { bot.addListener('error', function(message) { setTimeout(function() { // console.log("wait 7sek"); @@ -30,126 +31,126 @@ module.exports = { //bot.say('#hackerspace', 'Door Bot is starting to watch on the Door Status'); }) }, - ircSend: function (door_status){ + ircSend: function (door_status) { bot.say('#hackerspace', 'Door Status changed to: ' + door_status); - // bot.send('topic','#hackerspace "Hackerspace Flensburg - Treffen jeden Montag 18:00 Uhr im Offenen Kanal Flensburg! - Tür Status"' + door_status); - // console.log("IRC Door Status Chnaged"); - }, - ircStopp: function() { - bot.disconnect('Bot was stopped!'); - }, - ircBotCommands: function(){ - bot.addListener('message', function (from, to, message) { - message = message.toLowerCase(); - for (var key in command_config["commands"]) { - if (command_config["commands"].hasOwnProperty(key)) { - // console.log("!" + JSON.stringify(command_config["commands"][key]["keyword"])); - if (message == ("!" + command_config["commands"][key]["keyword"])) { - if (command_config["commands"][key]["before"] == "from") { - if (command_config["commands"][key]["target"] == "from") { - bot.say(from, from + command_config["commands"][key]["message"]); - }else{ - bot.say(to, from + command_config["commands"][key]["message"]); - } - }else{ - if (!command_config["commands"][key]["before"]) { - if (command_config["commands"][key]["target"] == "from") { - bot.say(from, command_config["commands"][key]["message"]); - }else{ - bot.say(to, command_config["commands"][key]["message"]); - } - }else{ - if (command_config["commands"][key]["target"] == "from") { - bot.say(from, to + command_config["commands"][key]["message"]); - }else{ - bot.say(to, to + command_config["commands"][key]["message"]); - } - } - } - } - } - } - var channel = message.split(" "); - if (message == "!source " + channel[channel.length-1]){ - if (channel[channel.length-1] == "this"){ - bot.join(to); - bot.say(to, "You can find the Source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door"); - } - } - 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[channel.length-1]){ - 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(message); - bot.list(); - // console.log(channel[(channel.length-(channel.length-1))+1]); - // console.log(channel.length); - if (channel[channel.length-1] !== "this"){ - if (channel[channel.length-1] !== " ") { - bot.addListener('channellist', function (channel_list) { - for (var key in channel_list) { - if (channel_list.hasOwnProperty(key)) { - if (channel_list[key]["name"] == channel[channel.length-1]) { - // console.log("1"); - bot.join(channel[channel.length-1]); - bot.say(channel[channel.length-1], "DoorStatus is: " + door_status); - } - } + // bot.send('topic','#hackerspace "Hackerspace Flensburg - Treffen jeden Montag 18:00 Uhr im Offenen Kanal Flensburg! - Tür Status"' + door_status); + // console.log("IRC Door Status Chnaged"); + }, + ircStopp: function() { + bot.disconnect('Bot was stopped!'); + }, + ircBotCommands: function() { + bot.addListener('message', function (from, to, message) { + message = message.toLowerCase(); + for (var key in command_config["commands"]) { + if (command_config["commands"].hasOwnProperty(key)) { + // console.log("!" + JSON.stringify(command_config["commands"][key]["keyword"])); + if (message == ("!" + command_config["commands"][key]["keyword"])) { + if (command_config["commands"][key]["before"] == "from") { + if (command_config["commands"][key]["target"] == "from") { + bot.say(from, from + command_config["commands"][key]["message"]); + } else { + bot.say(to, from + command_config["commands"][key]["message"]); + } + } else { + if (!command_config["commands"][key]["before"]) { + if (command_config["commands"][key]["target"] == "from") { + bot.say(from, command_config["commands"][key]["message"]); + } else { + bot.say(to, command_config["commands"][key]["message"]); + } + } else { + if (command_config["commands"][key]["target"] == "from") { + bot.say(from, to + command_config["commands"][key]["message"]); + } else { + bot.say(to, to + command_config["commands"][key]["message"]); + } + } + } + } + } + } + var channel = message.split(" "); + if (message == "!source " + channel[channel.length-1]) { + if (channel[channel.length-1] == "this") { + bot.join(to); + bot.say(to, "You can find the Source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door"); + } + } + 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[channel.length-1]) { + 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(message); + bot.list(); + // console.log(channel[(channel.length-(channel.length-1))+1]); + // console.log(channel.length); + if (channel[channel.length-1] !== "this") { + if (channel[channel.length-1] !== " ") { + bot.addListener('channellist', function (channel_list) { + for (var key in channel_list) { + if (channel_list.hasOwnProperty(key)) { + if (channel_list[key]["name"] == channel[channel.length-1]) { + // console.log("1"); + bot.join(channel[channel.length-1]); + bot.say(channel[channel.length-1], "DoorStatus is: " + door_status); } - }); - }else{ - bot.say(from, "DoorStatus is: " + door_status); - } - }else{ - bot.join(to); - 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(); + } + } + }); + } else { + bot.say(from, "DoorStatus is: " + door_status); + } + } else { + bot.join(to); + 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', 'NordlabBot'); -} -}; -\ No newline at end of file + }) + }, + ircNick: function() { + bot.send('nick', 'NordlabBot'); + } +};