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 b15193599da4bda9b17b0107999da973d81049e0
parent beb25541e48bb7288cc1889ca979e272e0b9cdf7
Author: Marcel <MTRNord@users.noreply.github.com>
Date:   Sun, 13 Dec 2015 01:33:55 +0100

Merge pull request #2 from S4ra/patch-1

Add Rechtschreib fixes von S4ra
Diffstat:
MREADME.md | 15+++++++--------
Mcommands.json | 12++++++------
Mhandlers/irc.js | 244++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mmain.js | 18++++++++++--------
4 files changed, 145 insertions(+), 144 deletions(-)

diff --git a/README.md b/README.md @@ -1,6 +1,6 @@ Nordlab Bot =========== -Modular parser for the hackerspace door status with handlers for multiple services and IRC Bot for the Nordlab e.V. +Modular parser for the hackerspace door status with handlers for multiple services and IRC Bot for the Nordlab e.V. How to install ============== @@ -16,16 +16,16 @@ Commands ======== ```!help | !hilfe``` - Lists all commands in a PM<br> ```!doorstatus``` - Send an PM with the actual Door Status<br> -```!doorstatus [arg]``` - If the arg is <b>"this"</b>) it sends in the actual channel the Door Status or is there an <b>existing channel as argument</b> it sends to the channel which is the argument<br> +```!doorstatus [arg]``` - If the arg is <b>"this"</b> it sends in the actual channel the Door Status or is there an <b>existing channel as argument</b> it sends to the channel which is the argument<br> ```!where``` - Send an PM with the address of the Hackerspace<br> ```!who``` - Send an PM with information about who can go to the Hackerspace<br> ```!when``` - Send an PM with information about when the Hackerspace usually is open<br> -```!source``` - Send an PM with the Link of this Repo. If you add <b>"this"</b> after it you can post it in the actual channel<br> -```!license``` - Send an PM with the link of the Bot license<br> +```!source``` - Send an PM with the link of this repo. If you add <b>"this"</b> after it you can post it in the actual channel<br> +```!license``` - Send an PM with the link of the bot license<br> ```!afk``` - Send in the actual channel that you are A(way) F(rom) K(eyboard)<br> -```!alone``` - Send in the actual channel that you are Alone in the channel<br> -```!freifunk``` - Send in the actual channel a link with an Meme about Freifunk<br> +```!alone``` - Send in the actual channel that you are alone in the channel<br> +```!freifunk``` - Send in the actual channel a link with an meme about Freifunk<br> Updates ======= -The Bot pulls the repo every day at 2am (if not deativated) and restarts the bot. So it is always UpTo-Date :)<br> -\ No newline at end of file +The Bot pulls the repo every day at 2am (if not deativated) and restarts the bot. So it is always UpTo-Date :)<br> diff --git a/commands.json b/commands.json @@ -2,37 +2,37 @@ "commands": [ { "keyword": "help", - "message": "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\n- !where - Shows the address of the Nordlab e.V.\n- !who - Shows who is allowed to come to the Nordlab e.V.\n- !when - Shows who the Nordlab e.V. Hackerspace usually is open\n- !source - Shows where the source of this bot is.\n- !license - What is the license of the bot?????????", + "message": "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 from where it was run\n- !where - Shows the address of the Nordlab e.V.\n- !who - Shows who is allowed to come to the Nordlab e.V.\n- !when - Shows who the Nordlab e.V. Hackerspace usually is open\n- !source - Shows where the source of this bot is.\n- !license - What is the license of the bot?????????", "argument": "1", "target": "from" }, { "keyword": "hilfe", - "message": "Hier ist die Hilfe!\nBefehl-liste:\n- !hilfe - Zeigt diese Seite.\n- !DoorStatus - Sendet eine PM mit dem aktuellen Status\n- !DoorStatus channel - Sendet in den Channel wo der Befehl ausgeführt wurde den aktuellen Status\n- !where - Zeigt die Addresse vom Nordlab e.V.\n- !who - Zeigt wer alles kommen darf Nordlab e.V.\n- !when - Zeigt wann der Nordlab e.V. Hackerspace geöffnet hat\n- !source - Zeigt wo die Source des Bot's sind.\n- !license - HILFE! Welche Lizenz hat der Bot?????????", + "message": "Hier ist die Hilfe!\nBefehl-Liste:\n- !hilfe - Zeigt diese Seite an.\n- !DoorStatus - Sendet eine PM mit dem aktuellen Status\n- !DoorStatus channel - Sendet in den Channel wo der Befehl ausgeführt wurde den aktuellen Status\n- !where - Zeigt die Addresse vom Nordlab e.V.\n- !who - Zeigt wer alles in den Nordlab e.V. kommen darf\n- !when - Zeigt wann der Nordlab e.V. Hackerspace geöffnet hat\n- !source - Zeigt wo die Sourcen des Bot's sind.\n- !license - HILFE! Welche Lizenz hat der Bot?????????", "argument": "1", "target": "from" }, { "keyword": "where", - "message": "You can find the Hackerspace in:\nOffener Kanal Flensburg\nSt.-Jürgen-Straße 95\n24937 Flensburg\nAt the very Top of the building", + "message": "You can find the Hackerspace in:\nOffener Kanal Flensburg\nSt.-Jürgen-Straße 95\n24937 Flensburg\nAt the very top of the building", "argument": "0", "target": "from" }, { "keyword": "who", - "message": "Everybody can come to the Norlab e.V.", + "message": "Everybody can come to the Nordlab e.V.", "argument": "0", "target": "from" }, { "keyword": "when", - "message": "The Hackerpace of Norlab e.V. is usually opened every Monday at 6pm o'clock.", + "message": "The Hackerpace of Nordlab e.V. is usually opened every Monday at 6pm o'clock.", "argument": "0", "target": "from" }, { "keyword": "source", - "message": "You can find the Source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door", + "message": "You can find the source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door", "argument": "0", "target": "from" }, 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'); + } +}; diff --git a/main.js b/main.js @@ -6,6 +6,9 @@ var argv = require('yargs').argv; var pushbullet = require('./handlers/pushbullet.js'); var irc = require('./handlers/irc.js'); +//Constants +var SIGINT = "SIGINT"; + function sleep(milliseconds) { var start = new Date().getTime(); @@ -52,12 +55,12 @@ request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, re output: process.stdout }).setMaxListeners(0); - rl.on("SIGINT", function () { - process.emit("SIGINT"); + rl.on(SIGINT, function () { + process.emit(SIGINT); }).setMaxListeners(0); } - process.on("SIGINT", function () { + process.on(SIGINT, function () { irc.ircStopp(); process.exit(); }).setMaxListeners(0); @@ -68,7 +71,7 @@ irc.ircBotCommands(); if (!argv.noupdate) { var j = schedule.scheduleJob('* 2 * * *', function(){ console.log('Start Update!'); - bot.ircEndCustom('Start Update! Coming back in a few Senconds!'); + bot.ircEndCustom('Start update! Coming back in a few Seconds!'); git.pull(function(err, update) { if(update && update.summary.changes) { require('child_process').exec('npm restart'); @@ -78,9 +81,9 @@ if (!argv.noupdate) { } if (argv.noupdate) { var j = schedule.scheduleJob('* 2 * * *', function(){ - console.log('Daily Restart!'); - bot.ircEndCustom('Daily Restart! Coming back in a few Senconds!'); + console.log('Daily restart!'); + bot.ircEndCustom('Daily restart! Coming back in a few Seconds!'); require('child_process').exec('npm restart'); }); } -setTimeout(function() { MakePush(); }, 20000); -\ No newline at end of file +setTimeout(function() { MakePush(); }, 20000);