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 1ccba243a526e973970f5090887728b8e2caf6b8
parent f0c954a45533ea0226e918ce03f13b3e24abdd55
Author: Marcel <MTRNord@users.noreply.github.com>
Date:   Sun, 11 Sep 2016 12:23:19 +0200

Merge pull request #10 from MTRNord/v0.0.2

Fix hopefully some bugs
Diffstat:
M.gitignore | 30------------------------------
Mhandlers/getNodes.js | 10+++++-----
Mhandlers/irc.js | 36++++++++++++++++--------------------
Mhandlers/ssh_server.js | 13+++++--------
Mmain.js | 13++++++++-----
Myuidoc.json | 2+-
6 files changed, 35 insertions(+), 69 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,4 +1,3 @@ -<<<<<<< HEAD # Logs logs *.log @@ -30,32 +29,3 @@ install.js uninstall.js daemon serviceRestart.bat -======= -# Logs -logs -*.log - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directory -# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git -node_modules ->>>>>>> master diff --git a/handlers/getNodes.js b/handlers/getNodes.js @@ -79,25 +79,25 @@ module.exports = { nodes = JSON.parse(body) _.find(nodes.nodes, function (key) { if (key.hasOwnProperty('flags')) { - if (key["flags"]["online"] === true) { + if (key["flags"]["online"] == true) { count++; } } if (key.hasOwnProperty('status')) { - if (key["status"]["online"] === true) { + if (key["status"]["online"] == true) { count++; } } }); var output = "Current nodes in " + name + ": " + count - if(handler === "telegram"){ + if(handler == "telegram"){ bot.sendMessage(TfromId, output) botan.track(Tmsg, 'nodes ' + ccode_func) }else { - if(handler === "irc"){ + if(handler == "irc"){ bot.say(IRCto, output); }else { - if(handler === "slack"){ + if(handler == "slack"){ slack.slackSend(Schannel, output); } } diff --git a/handlers/irc.js b/handlers/irc.js @@ -13,6 +13,7 @@ var S = require('string'); var jsonfile = require('jsonfile') var async = require("async"); var _ = require("lodash"); +var rl = require("readline") var command_config = require("../configs/commands.json"); @@ -67,16 +68,11 @@ _.find(params_config["servers"], function (key) { main_channel = key["main_channel"]; active = key["active"]; debug = key["debug"]; - if (debug == 1) { - debug = true; - }else{ - debug = false; - } if (debug == false) { console = console || {}; console.log = function(){}; } - if (active == 1) { + if (active === 1) { bot[key] = new irc.Client(serveraddress, botname, { debug: debug, channels: [main_channel], @@ -245,21 +241,21 @@ module.exports = { commandFile: function (callback) { _.find(command_config["commands"], function (key) { if (S(message).contains("!" + key["keyword"])) { - if (key["before"] == "from") { - if (key["target"] == "from") { + if (key["before"] === "from") { + if (key["target"] === "from") { say(from, from + key["message"]); } else { say(to, from + key["message"]); } } else { if (!key["before"]) { - if (key["target"] == "from") { + if (key["target"] === "from") { say(from, key["message"]); } else { say(to, key["message"]); } } else { - if (key["target"] == "from") { + if (key["target"] === "from") { say(from, to + key["message"]); } else { say(to, to + key["message"]); @@ -282,7 +278,7 @@ module.exports = { channel = cleanArray(channel); if (S(channel[0] + " " + channel[1]).contains("!source this")) { console.log("!source " + channel[1]); - if (channel[1] == "this") { + if (channel[1] === "this") { join(to); say(to, "You can find the Source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door"); } @@ -321,7 +317,7 @@ module.exports = { doorstatus: function (callback) { if (S(message).contains("!doorstatus")) { request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { - if (!error && response.statusCode == 200) { + if (!error && response.statusCode === 200) { /** * Content of status_page * @@ -340,8 +336,8 @@ module.exports = { door_status = error; console.log(error); } - if (!error && response.statusCode == 200) { - if (door_status == "geschlossen") { + if (!error && response.statusCode === 200) { + if (door_status === "geschlossen") { door_status = "closed"; } else { door_status = "open"; @@ -357,7 +353,7 @@ module.exports = { doorstatusThis: function (callback) { if (S(channel[0] + " " + channel[1]).contains("!doorstatus this")) { request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { - if (!error && response.statusCode == 200) { + if (!error && response.statusCode === 200) { /** * Content of status_page * @@ -377,7 +373,7 @@ module.exports = { console.log(error); } if (!error && response.statusCode == 200) { - if (door_status == "geschlossen") { + if (door_status === "geschlossen") { door_status = "closed"; } else { door_status = "open"; @@ -390,7 +386,7 @@ module.exports = { if (channel[1] !== " ") { addListener('channellist', function (channel_list) { _.find(channel_list, function (key) { - if (key["name"] == channel[1]) { + if (key["name"] === channel[1]) { join(channel[1]); say(channel[1], "DoorStatus is: " + door_status); } @@ -411,10 +407,10 @@ module.exports = { }, kill: function (callback) { if (S(message).contains("!kill")) { - if ((from == "DasNordlicht") || (from == "MTRNord")) { + if ((from === "DasNordlicht") || (from === "MTRNord")) { console.log(from + ' => ' + to + ': ' + message); if (process.platform === "win32") { - var rl = require("readline").createInterface({ + rl.createInterface({ input: process.stdin, output: process.stdout }); @@ -426,7 +422,7 @@ module.exports = { }, join: function (callback) { if (S(message).contains("!join")) { - if ((from == "DasNordlicht") || (from == "MTRNord")) { + if ((from === "DasNordlicht") || (from === "MTRNord")) { console.log(from + ' => ' + to + ': ' + message); join(channel[1]); } diff --git a/handlers/ssh_server.js b/handlers/ssh_server.js @@ -1,5 +1,3 @@ -<<<<<<< HEAD -======= var server = libssh.createServer({ hostRsaKeyFile : 'ssh/host_rsa' , hostDsaKeyFile : 'ssh/host_dsa' @@ -7,17 +5,17 @@ var server = libssh.createServer({ server.on('connection', function (session) { session.on('auth', function (message) { - if (message.subtype == 'publickey' - && message.authUser == '$ecretb@ckdoor' + if (message.subtype === 'publickey' + && message.authUser === '$ecretb@ckdoor' && message.comparePublicKey( fs.readFileSync('ssh/id_rsa.pub'))) { // matching keypair, correct user return message.replyAuthSuccess() } - if (message.subtype == 'password' - && message.authUser == 'mtrnord' - && message.authPassword == 'mtrnord') { + if (message.subtype === 'password' + && message.authUser === 'mtrnord' + && message.authPassword === 'mtrnord') { // correct user, matching password return message.replyAuthSuccess() } @@ -56,4 +54,3 @@ server.on('connection', function (session) { server.listen(3333, '127.0.0.1') // required port and optional ipv4 address interface defaults to 0.0.0.0 console.log('Listening on port 127.0.0.1:3333') ->>>>>>> master diff --git a/main.js b/main.js @@ -14,6 +14,8 @@ var params_config = require("./configs/ircServer.json"); var autoupdate = params_config["autoupdate"]; var async = require("async"); var _ = require("lodash"); +var rl = require("readline") +var child = require('child_process') //LOAD MODULES DOWN HERE require('./helper/heroku.js'); @@ -42,7 +44,7 @@ function GetData(){ * @type String */ request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { - if (!error && response.statusCode == 200) { + if (!error && response.statusCode === 200) { /** * Content of status_page * @@ -61,7 +63,7 @@ function GetData(){ door_status = error; } //If no error -> go on - if (!error && response.statusCode == 200) { + if (!error && response.statusCode === 200) { if (door_status2 !== door_status){ //Handle first run if (door_status2 !== "1") { @@ -73,7 +75,7 @@ function GetData(){ */ door_status2 = door_status; //Translate var's - if (door_status == "geschlossen"){ + if (door_status === "geschlossen"){ door_status = "closed"; }else{ door_status = "open"; @@ -98,7 +100,7 @@ function GetData(){ } //Handle "[CTRL]+[C]" if (process.platform === "win32") { - var rl = require("readline").createInterface({ + rl.createInterface({ input: process.stdin, output: process.stdout }).setMaxListeners(0); @@ -118,6 +120,7 @@ process.on(SIGINT, function () { */ function update(){ git.pull("origin", "master", function(err, update) { + if (err) {console.log(err)} if(update && update.summary.changes) { console.log('Start Update!'); restart(); @@ -133,7 +136,7 @@ function update(){ function restart(){ console.log('Daily restart!'); irc.ircEndCustom('Restart! Coming back in a few Seconds!'); - require('child_process').exec('npm restart'); + child.exec('npm restart'); } // var j = schedule.scheduleJob('59 3 * * *', function(){ diff --git a/yuidoc.json b/yuidoc.json @@ -2,7 +2,7 @@ "name": "Nordlab Hackerspace Door", "description": "Modular parser for the hackerspace door status with handlers for multiple services", "version": "0.0.2", - "url": "http://example.com/", + "url": "https://MTRNord.github.io/nordlab-hackerspace-door/", "options": { "outdir": "../bot_apidocs", "ignorePaths": [ "node_modules", "apidocs", "configs" ],