10.diff (11746B)
1 diff --git a/.gitignore b/.gitignore 2 index bdb90aa..fe9abd2 100644 3 --- a/.gitignore 4 +++ b/.gitignore 5 @@ -1,4 +1,3 @@ 6 -<<<<<<< HEAD 7 # Logs 8 logs 9 *.log 10 @@ -30,32 +29,3 @@ install.js 11 uninstall.js 12 daemon 13 serviceRestart.bat 14 -======= 15 -# Logs 16 -logs 17 -*.log 18 - 19 -# Runtime data 20 -pids 21 -*.pid 22 -*.seed 23 - 24 -# Directory for instrumented libs generated by jscoverage/JSCover 25 -lib-cov 26 - 27 -# Coverage directory used by tools like istanbul 28 -coverage 29 - 30 -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 31 -.grunt 32 - 33 -# node-waf configuration 34 -.lock-wscript 35 - 36 -# Compiled binary addons (http://nodejs.org/api/addons.html) 37 -build/Release 38 - 39 -# Dependency directory 40 -# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 41 -node_modules 42 ->>>>>>> master 43 diff --git a/handlers/getNodes.js b/handlers/getNodes.js 44 index cf1ee5d..d10664d 100644 45 --- a/handlers/getNodes.js 46 +++ b/handlers/getNodes.js 47 @@ -79,25 +79,25 @@ module.exports = { 48 nodes = JSON.parse(body) 49 _.find(nodes.nodes, function (key) { 50 if (key.hasOwnProperty('flags')) { 51 - if (key["flags"]["online"] === true) { 52 + if (key["flags"]["online"] == true) { 53 count++; 54 } 55 } 56 if (key.hasOwnProperty('status')) { 57 - if (key["status"]["online"] === true) { 58 + if (key["status"]["online"] == true) { 59 count++; 60 } 61 } 62 }); 63 var output = "Current nodes in " + name + ": " + count 64 - if(handler === "telegram"){ 65 + if(handler == "telegram"){ 66 bot.sendMessage(TfromId, output) 67 botan.track(Tmsg, 'nodes ' + ccode_func) 68 }else { 69 - if(handler === "irc"){ 70 + if(handler == "irc"){ 71 bot.say(IRCto, output); 72 }else { 73 - if(handler === "slack"){ 74 + if(handler == "slack"){ 75 slack.slackSend(Schannel, output); 76 } 77 } 78 diff --git a/handlers/irc.js b/handlers/irc.js 79 index d3b6e58..7112909 100644 80 --- a/handlers/irc.js 81 +++ b/handlers/irc.js 82 @@ -13,6 +13,7 @@ var S = require('string'); 83 var jsonfile = require('jsonfile') 84 var async = require("async"); 85 var _ = require("lodash"); 86 +var rl = require("readline") 87 88 89 var command_config = require("../configs/commands.json"); 90 @@ -67,16 +68,11 @@ _.find(params_config["servers"], function (key) { 91 main_channel = key["main_channel"]; 92 active = key["active"]; 93 debug = key["debug"]; 94 - if (debug == 1) { 95 - debug = true; 96 - }else{ 97 - debug = false; 98 - } 99 if (debug == false) { 100 console = console || {}; 101 console.log = function(){}; 102 } 103 - if (active == 1) { 104 + if (active === 1) { 105 bot[key] = new irc.Client(serveraddress, botname, { 106 debug: debug, 107 channels: [main_channel], 108 @@ -245,21 +241,21 @@ module.exports = { 109 commandFile: function (callback) { 110 _.find(command_config["commands"], function (key) { 111 if (S(message).contains("!" + key["keyword"])) { 112 - if (key["before"] == "from") { 113 - if (key["target"] == "from") { 114 + if (key["before"] === "from") { 115 + if (key["target"] === "from") { 116 say(from, from + key["message"]); 117 } else { 118 say(to, from + key["message"]); 119 } 120 } else { 121 if (!key["before"]) { 122 - if (key["target"] == "from") { 123 + if (key["target"] === "from") { 124 say(from, key["message"]); 125 } else { 126 say(to, key["message"]); 127 } 128 } else { 129 - if (key["target"] == "from") { 130 + if (key["target"] === "from") { 131 say(from, to + key["message"]); 132 } else { 133 say(to, to + key["message"]); 134 @@ -282,7 +278,7 @@ module.exports = { 135 channel = cleanArray(channel); 136 if (S(channel[0] + " " + channel[1]).contains("!source this")) { 137 console.log("!source " + channel[1]); 138 - if (channel[1] == "this") { 139 + if (channel[1] === "this") { 140 join(to); 141 say(to, "You can find the Source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door"); 142 } 143 @@ -321,7 +317,7 @@ module.exports = { 144 doorstatus: function (callback) { 145 if (S(message).contains("!doorstatus")) { 146 request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { 147 - if (!error && response.statusCode == 200) { 148 + if (!error && response.statusCode === 200) { 149 /** 150 * Content of status_page 151 * 152 @@ -340,8 +336,8 @@ module.exports = { 153 door_status = error; 154 console.log(error); 155 } 156 - if (!error && response.statusCode == 200) { 157 - if (door_status == "geschlossen") { 158 + if (!error && response.statusCode === 200) { 159 + if (door_status === "geschlossen") { 160 door_status = "closed"; 161 } else { 162 door_status = "open"; 163 @@ -357,7 +353,7 @@ module.exports = { 164 doorstatusThis: function (callback) { 165 if (S(channel[0] + " " + channel[1]).contains("!doorstatus this")) { 166 request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { 167 - if (!error && response.statusCode == 200) { 168 + if (!error && response.statusCode === 200) { 169 /** 170 * Content of status_page 171 * 172 @@ -377,7 +373,7 @@ module.exports = { 173 console.log(error); 174 } 175 if (!error && response.statusCode == 200) { 176 - if (door_status == "geschlossen") { 177 + if (door_status === "geschlossen") { 178 door_status = "closed"; 179 } else { 180 door_status = "open"; 181 @@ -390,7 +386,7 @@ module.exports = { 182 if (channel[1] !== " ") { 183 addListener('channellist', function (channel_list) { 184 _.find(channel_list, function (key) { 185 - if (key["name"] == channel[1]) { 186 + if (key["name"] === channel[1]) { 187 join(channel[1]); 188 say(channel[1], "DoorStatus is: " + door_status); 189 } 190 @@ -411,10 +407,10 @@ module.exports = { 191 }, 192 kill: function (callback) { 193 if (S(message).contains("!kill")) { 194 - if ((from == "DasNordlicht") || (from == "MTRNord")) { 195 + if ((from === "DasNordlicht") || (from === "MTRNord")) { 196 console.log(from + ' => ' + to + ': ' + message); 197 if (process.platform === "win32") { 198 - var rl = require("readline").createInterface({ 199 + rl.createInterface({ 200 input: process.stdin, 201 output: process.stdout 202 }); 203 @@ -426,7 +422,7 @@ module.exports = { 204 }, 205 join: function (callback) { 206 if (S(message).contains("!join")) { 207 - if ((from == "DasNordlicht") || (from == "MTRNord")) { 208 + if ((from === "DasNordlicht") || (from === "MTRNord")) { 209 console.log(from + ' => ' + to + ': ' + message); 210 join(channel[1]); 211 } 212 diff --git a/handlers/ssh_server.js b/handlers/ssh_server.js 213 index 7aa57de..d788e17 100644 214 --- a/handlers/ssh_server.js 215 +++ b/handlers/ssh_server.js 216 @@ -1,5 +1,3 @@ 217 -<<<<<<< HEAD 218 -======= 219 var server = libssh.createServer({ 220 hostRsaKeyFile : 'ssh/host_rsa' 221 , hostDsaKeyFile : 'ssh/host_dsa' 222 @@ -7,17 +5,17 @@ var server = libssh.createServer({ 223 224 server.on('connection', function (session) { 225 session.on('auth', function (message) { 226 - if (message.subtype == 'publickey' 227 - && message.authUser == '$ecretb@ckdoor' 228 + if (message.subtype === 'publickey' 229 + && message.authUser === '$ecretb@ckdoor' 230 && message.comparePublicKey( 231 fs.readFileSync('ssh/id_rsa.pub'))) { 232 // matching keypair, correct user 233 return message.replyAuthSuccess() 234 } 235 236 - if (message.subtype == 'password' 237 - && message.authUser == 'mtrnord' 238 - && message.authPassword == 'mtrnord') { 239 + if (message.subtype === 'password' 240 + && message.authUser === 'mtrnord' 241 + && message.authPassword === 'mtrnord') { 242 // correct user, matching password 243 return message.replyAuthSuccess() 244 } 245 @@ -56,4 +54,3 @@ server.on('connection', function (session) { 246 247 server.listen(3333, '127.0.0.1') // required port and optional ipv4 address interface defaults to 0.0.0.0 248 console.log('Listening on port 127.0.0.1:3333') 249 ->>>>>>> master 250 diff --git a/main.js b/main.js 251 index bb6b164..de15175 100644 252 --- a/main.js 253 +++ b/main.js 254 @@ -14,6 +14,8 @@ var params_config = require("./configs/ircServer.json"); 255 var autoupdate = params_config["autoupdate"]; 256 var async = require("async"); 257 var _ = require("lodash"); 258 +var rl = require("readline") 259 +var child = require('child_process') 260 261 //LOAD MODULES DOWN HERE 262 require('./helper/heroku.js'); 263 @@ -42,7 +44,7 @@ function GetData(){ 264 * @type String 265 */ 266 request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { 267 - if (!error && response.statusCode == 200) { 268 + if (!error && response.statusCode === 200) { 269 /** 270 * Content of status_page 271 * 272 @@ -61,7 +63,7 @@ function GetData(){ 273 door_status = error; 274 } 275 //If no error -> go on 276 - if (!error && response.statusCode == 200) { 277 + if (!error && response.statusCode === 200) { 278 if (door_status2 !== door_status){ 279 //Handle first run 280 if (door_status2 !== "1") { 281 @@ -73,7 +75,7 @@ function GetData(){ 282 */ 283 door_status2 = door_status; 284 //Translate var's 285 - if (door_status == "geschlossen"){ 286 + if (door_status === "geschlossen"){ 287 door_status = "closed"; 288 }else{ 289 door_status = "open"; 290 @@ -98,7 +100,7 @@ function GetData(){ 291 } 292 //Handle "[CTRL]+[C]" 293 if (process.platform === "win32") { 294 - var rl = require("readline").createInterface({ 295 + rl.createInterface({ 296 input: process.stdin, 297 output: process.stdout 298 }).setMaxListeners(0); 299 @@ -118,6 +120,7 @@ process.on(SIGINT, function () { 300 */ 301 function update(){ 302 git.pull("origin", "master", function(err, update) { 303 + if (err) {console.log(err)} 304 if(update && update.summary.changes) { 305 console.log('Start Update!'); 306 restart(); 307 @@ -133,7 +136,7 @@ function update(){ 308 function restart(){ 309 console.log('Daily restart!'); 310 irc.ircEndCustom('Restart! Coming back in a few Seconds!'); 311 - require('child_process').exec('npm restart'); 312 + child.exec('npm restart'); 313 } 314 315 // var j = schedule.scheduleJob('59 3 * * *', function(){ 316 diff --git a/yuidoc.json b/yuidoc.json 317 index 0d22f67..c66f945 100644 318 --- a/yuidoc.json 319 +++ b/yuidoc.json 320 @@ -2,7 +2,7 @@ 321 "name": "Nordlab Hackerspace Door", 322 "description": "Modular parser for the hackerspace door status with handlers for multiple services", 323 "version": "0.0.2", 324 - "url": "http://example.com/", 325 + "url": "https://MTRNord.github.io/nordlab-hackerspace-door/", 326 "options": { 327 "outdir": "../bot_apidocs", 328 "ignorePaths": [ "node_modules", "apidocs", "configs" ],