2.diff (17953B)
1 diff --git a/README.md b/README.md 2 index a43d4e6..d931b2f 100644 3 --- a/README.md 4 +++ b/README.md 5 @@ -1,6 +1,6 @@ 6 Nordlab Bot 7 =========== 8 -Modular parser for the hackerspace door status with handlers for multiple services and IRC Bot for the Nordlab e.V. 9 +Modular parser for the hackerspace door status with handlers for multiple services and IRC Bot for the Nordlab e.V. 10 11 How to install 12 ============== 13 @@ -16,16 +16,16 @@ Commands 14 ======== 15 ```!help | !hilfe``` - Lists all commands in a PM<br> 16 ```!doorstatus``` - Send an PM with the actual Door Status<br> 17 -```!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> 18 +```!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> 19 ```!where``` - Send an PM with the address of the Hackerspace<br> 20 ```!who``` - Send an PM with information about who can go to the Hackerspace<br> 21 ```!when``` - Send an PM with information about when the Hackerspace usually is open<br> 22 -```!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> 23 -```!license``` - Send an PM with the link of the Bot license<br> 24 +```!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> 25 +```!license``` - Send an PM with the link of the bot license<br> 26 ```!afk``` - Send in the actual channel that you are A(way) F(rom) K(eyboard)<br> 27 -```!alone``` - Send in the actual channel that you are Alone in the channel<br> 28 -```!freifunk``` - Send in the actual channel a link with an Meme about Freifunk<br> 29 +```!alone``` - Send in the actual channel that you are alone in the channel<br> 30 +```!freifunk``` - Send in the actual channel a link with an meme about Freifunk<br> 31 32 Updates 33 ======= 34 -The Bot pulls the repo every day at 2am (if not deativated) and restarts the bot. So it is always UpTo-Date :)<br> 35 \ No newline at end of file 36 +The Bot pulls the repo every day at 2am (if not deativated) and restarts the bot. So it is always UpTo-Date :)<br> 37 diff --git a/commands.json b/commands.json 38 index c160d3a..2b60da4 100644 39 --- a/commands.json 40 +++ b/commands.json 41 @@ -2,37 +2,37 @@ 42 "commands": [ 43 { 44 "keyword": "help", 45 - "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?????????", 46 + "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?????????", 47 "argument": "1", 48 "target": "from" 49 }, 50 { 51 "keyword": "hilfe", 52 - "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?????????", 53 + "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?????????", 54 "argument": "1", 55 "target": "from" 56 }, 57 { 58 "keyword": "where", 59 - "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", 60 + "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", 61 "argument": "0", 62 "target": "from" 63 }, 64 { 65 "keyword": "who", 66 - "message": "Everybody can come to the Norlab e.V.", 67 + "message": "Everybody can come to the Nordlab e.V.", 68 "argument": "0", 69 "target": "from" 70 }, 71 { 72 "keyword": "when", 73 - "message": "The Hackerpace of Norlab e.V. is usually opened every Monday at 6pm o'clock.", 74 + "message": "The Hackerpace of Nordlab e.V. is usually opened every Monday at 6pm o'clock.", 75 "argument": "0", 76 "target": "from" 77 }, 78 { 79 "keyword": "source", 80 - "message": "You can find the Source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door", 81 + "message": "You can find the source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door", 82 "argument": "0", 83 "target": "from" 84 }, 85 diff --git a/handlers/irc.js b/handlers/irc.js 86 index 7f354f2..59702a7 100644 87 --- a/handlers/irc.js 88 +++ b/handlers/irc.js 89 @@ -8,11 +8,12 @@ var bot = new irc.Client('irc.lugfl.de', 'NordlabBot', { 90 }); 91 var request = require('request'); 92 var command_config = require("../commands.json"); 93 + 94 module.exports = { 95 - ircEndCustom: function (meassage){ 96 + ircEndCustom: function (meassage) { 97 bot.disconnect(meassage); 98 }, 99 - ircPreload: function (){ 100 + ircPreload: function () { 101 bot.addListener('error', function(message) { 102 setTimeout(function() { 103 // console.log("wait 7sek"); 104 @@ -30,126 +31,126 @@ module.exports = { 105 //bot.say('#hackerspace', 'Door Bot is starting to watch on the Door Status'); 106 }) 107 }, 108 - ircSend: function (door_status){ 109 + ircSend: function (door_status) { 110 bot.say('#hackerspace', 'Door Status changed to: ' + door_status); 111 - // bot.send('topic','#hackerspace "Hackerspace Flensburg - Treffen jeden Montag 18:00 Uhr im Offenen Kanal Flensburg! - Tür Status"' + door_status); 112 - // console.log("IRC Door Status Chnaged"); 113 - }, 114 - ircStopp: function() { 115 - bot.disconnect('Bot was stopped!'); 116 - }, 117 - ircBotCommands: function(){ 118 - bot.addListener('message', function (from, to, message) { 119 - message = message.toLowerCase(); 120 - for (var key in command_config["commands"]) { 121 - if (command_config["commands"].hasOwnProperty(key)) { 122 - // console.log("!" + JSON.stringify(command_config["commands"][key]["keyword"])); 123 - if (message == ("!" + command_config["commands"][key]["keyword"])) { 124 - if (command_config["commands"][key]["before"] == "from") { 125 - if (command_config["commands"][key]["target"] == "from") { 126 - bot.say(from, from + command_config["commands"][key]["message"]); 127 - }else{ 128 - bot.say(to, from + command_config["commands"][key]["message"]); 129 - } 130 - }else{ 131 - if (!command_config["commands"][key]["before"]) { 132 - if (command_config["commands"][key]["target"] == "from") { 133 - bot.say(from, command_config["commands"][key]["message"]); 134 - }else{ 135 - bot.say(to, command_config["commands"][key]["message"]); 136 - } 137 - }else{ 138 - if (command_config["commands"][key]["target"] == "from") { 139 - bot.say(from, to + command_config["commands"][key]["message"]); 140 - }else{ 141 - bot.say(to, to + command_config["commands"][key]["message"]); 142 - } 143 - } 144 - } 145 - } 146 - } 147 - } 148 - var channel = message.split(" "); 149 - if (message == "!source " + channel[channel.length-1]){ 150 - if (channel[channel.length-1] == "this"){ 151 - bot.join(to); 152 - bot.say(to, "You can find the Source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door"); 153 - } 154 - } 155 - if (message == "!doorstatus"){ 156 - request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { 157 - if (!error && response.statusCode == 200) { 158 - door_status = body; 159 - //console.log(body); 160 - }else{ 161 - door_status = error; 162 - //console.log(error); 163 - } 164 - if (door_status == "geschlossen"){ 165 - door_status = "closed"; 166 - }else{ 167 - door_status = "open"; 168 - } 169 - // console.log(from + ' => ' + to + ': ' + message); 170 - bot.say(from, "DoorStatus is: " + door_status); 171 - }).setMaxListeners(0); 172 - } 173 - if (message == "!doorstatus " + channel[channel.length-1]){ 174 - request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { 175 - if (!error && response.statusCode == 200) { 176 - door_status = body; 177 - //console.log(body); 178 - }else{ 179 - door_status = error; 180 - //console.log(error); 181 - } 182 - if (door_status == "geschlossen"){ 183 - door_status = "closed"; 184 - }else{ 185 - door_status = "open"; 186 - } 187 - // console.log(message); 188 - bot.list(); 189 - // console.log(channel[(channel.length-(channel.length-1))+1]); 190 - // console.log(channel.length); 191 - if (channel[channel.length-1] !== "this"){ 192 - if (channel[channel.length-1] !== " ") { 193 - bot.addListener('channellist', function (channel_list) { 194 - for (var key in channel_list) { 195 - if (channel_list.hasOwnProperty(key)) { 196 - if (channel_list[key]["name"] == channel[channel.length-1]) { 197 - // console.log("1"); 198 - bot.join(channel[channel.length-1]); 199 - bot.say(channel[channel.length-1], "DoorStatus is: " + door_status); 200 - } 201 - } 202 + // bot.send('topic','#hackerspace "Hackerspace Flensburg - Treffen jeden Montag 18:00 Uhr im Offenen Kanal Flensburg! - Tür Status"' + door_status); 203 + // console.log("IRC Door Status Chnaged"); 204 + }, 205 + ircStopp: function() { 206 + bot.disconnect('Bot was stopped!'); 207 + }, 208 + ircBotCommands: function() { 209 + bot.addListener('message', function (from, to, message) { 210 + message = message.toLowerCase(); 211 + for (var key in command_config["commands"]) { 212 + if (command_config["commands"].hasOwnProperty(key)) { 213 + // console.log("!" + JSON.stringify(command_config["commands"][key]["keyword"])); 214 + if (message == ("!" + command_config["commands"][key]["keyword"])) { 215 + if (command_config["commands"][key]["before"] == "from") { 216 + if (command_config["commands"][key]["target"] == "from") { 217 + bot.say(from, from + command_config["commands"][key]["message"]); 218 + } else { 219 + bot.say(to, from + command_config["commands"][key]["message"]); 220 + } 221 + } else { 222 + if (!command_config["commands"][key]["before"]) { 223 + if (command_config["commands"][key]["target"] == "from") { 224 + bot.say(from, command_config["commands"][key]["message"]); 225 + } else { 226 + bot.say(to, command_config["commands"][key]["message"]); 227 + } 228 + } else { 229 + if (command_config["commands"][key]["target"] == "from") { 230 + bot.say(from, to + command_config["commands"][key]["message"]); 231 + } else { 232 + bot.say(to, to + command_config["commands"][key]["message"]); 233 + } 234 + } 235 + } 236 + } 237 + } 238 + } 239 + var channel = message.split(" "); 240 + if (message == "!source " + channel[channel.length-1]) { 241 + if (channel[channel.length-1] == "this") { 242 + bot.join(to); 243 + bot.say(to, "You can find the Source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door"); 244 + } 245 + } 246 + if (message == "!doorstatus") { 247 + request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { 248 + if (!error && response.statusCode == 200) { 249 + door_status = body; 250 + //console.log(body); 251 + } else { 252 + door_status = error; 253 + //console.log(error); 254 + } 255 + if (door_status == "geschlossen") { 256 + door_status = "closed"; 257 + } else { 258 + door_status = "open"; 259 + } 260 + // console.log(from + ' => ' + to + ': ' + message); 261 + bot.say(from, "DoorStatus is: " + door_status); 262 + }).setMaxListeners(0); 263 + } 264 + if (message == "!doorstatus " + channel[channel.length-1]) { 265 + request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { 266 + if (!error && response.statusCode == 200) { 267 + door_status = body; 268 + //console.log(body); 269 + } else { 270 + door_status = error; 271 + //console.log(error); 272 + } 273 + if (door_status == "geschlossen") { 274 + door_status = "closed"; 275 + } else { 276 + door_status = "open"; 277 + } 278 + // console.log(message); 279 + bot.list(); 280 + // console.log(channel[(channel.length-(channel.length-1))+1]); 281 + // console.log(channel.length); 282 + if (channel[channel.length-1] !== "this") { 283 + if (channel[channel.length-1] !== " ") { 284 + bot.addListener('channellist', function (channel_list) { 285 + for (var key in channel_list) { 286 + if (channel_list.hasOwnProperty(key)) { 287 + if (channel_list[key]["name"] == channel[channel.length-1]) { 288 + // console.log("1"); 289 + bot.join(channel[channel.length-1]); 290 + bot.say(channel[channel.length-1], "DoorStatus is: " + door_status); 291 } 292 - }); 293 - }else{ 294 - bot.say(from, "DoorStatus is: " + door_status); 295 - } 296 - }else{ 297 - bot.join(to); 298 - bot.say(to, "DoorStatus is: " + door_status); 299 - } 300 - }).setMaxListeners(0); 301 -} 302 -if (message == "!kill"){ 303 - if ((from == "DasNordlicht") || (from == "MTRNord")) { 304 - // console.log(from + ' => ' + to + ': ' + message); 305 - if (process.platform === "win32") { 306 - var rl = require("readline").createInterface({ 307 - input: process.stdin, 308 - output: process.stdout 309 - }); 310 - bot.disconnect('Bot was stopped!'); 311 - process.exit(); 312 + } 313 + } 314 + }); 315 + } else { 316 + bot.say(from, "DoorStatus is: " + door_status); 317 + } 318 + } else { 319 + bot.join(to); 320 + bot.say(to, "DoorStatus is: " + door_status); 321 + } 322 + }).setMaxListeners(0); 323 + } 324 + if (message == "!kill") { 325 + if ((from == "DasNordlicht") || (from == "MTRNord")) { 326 + // console.log(from + ' => ' + to + ': ' + message); 327 + if (process.platform === "win32") { 328 + var rl = require("readline").createInterface({ 329 + input: process.stdin, 330 + output: process.stdout 331 + }); 332 + bot.disconnect('Bot was stopped!'); 333 + process.exit(); 334 + } 335 } 336 } 337 - } 338 - }) 339 -}, 340 -ircNick: function() { 341 - bot.send('nick', 'NordlabBot'); 342 -} 343 -}; 344 \ No newline at end of file 345 + }) 346 + }, 347 + ircNick: function() { 348 + bot.send('nick', 'NordlabBot'); 349 + } 350 +}; 351 diff --git a/main.js b/main.js 352 index a1140ff..5a58386 100644 353 --- a/main.js 354 +++ b/main.js 355 @@ -6,6 +6,9 @@ var argv = require('yargs').argv; 356 var pushbullet = require('./handlers/pushbullet.js'); 357 var irc = require('./handlers/irc.js'); 358 359 +//Constants 360 +var SIGINT = "SIGINT"; 361 + 362 363 function sleep(milliseconds) { 364 var start = new Date().getTime(); 365 @@ -52,12 +55,12 @@ request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, re 366 output: process.stdout 367 }).setMaxListeners(0); 368 369 - rl.on("SIGINT", function () { 370 - process.emit("SIGINT"); 371 + rl.on(SIGINT, function () { 372 + process.emit(SIGINT); 373 }).setMaxListeners(0); 374 } 375 376 - process.on("SIGINT", function () { 377 + process.on(SIGINT, function () { 378 irc.ircStopp(); 379 process.exit(); 380 }).setMaxListeners(0); 381 @@ -68,7 +71,7 @@ irc.ircBotCommands(); 382 if (!argv.noupdate) { 383 var j = schedule.scheduleJob('* 2 * * *', function(){ 384 console.log('Start Update!'); 385 - bot.ircEndCustom('Start Update! Coming back in a few Senconds!'); 386 + bot.ircEndCustom('Start update! Coming back in a few Seconds!'); 387 git.pull(function(err, update) { 388 if(update && update.summary.changes) { 389 require('child_process').exec('npm restart'); 390 @@ -78,9 +81,9 @@ if (!argv.noupdate) { 391 } 392 if (argv.noupdate) { 393 var j = schedule.scheduleJob('* 2 * * *', function(){ 394 - console.log('Daily Restart!'); 395 - bot.ircEndCustom('Daily Restart! Coming back in a few Senconds!'); 396 + console.log('Daily restart!'); 397 + bot.ircEndCustom('Daily restart! Coming back in a few Seconds!'); 398 require('child_process').exec('npm restart'); 399 }); 400 } 401 -setTimeout(function() { MakePush(); }, 20000); 402 \ No newline at end of file 403 +setTimeout(function() { MakePush(); }, 20000);