commit f0f05cf4dedc9ae18aa9d1e0f067ae7a107b653b
parent 8c9dc97fae5d38ae945e7d1c7b55620e2b19b2c7
Author: MTRNord <mtrnord1@gmail.com>
Date: Sun, 11 Sep 2016 11:09:39 +0200
Manual merging
Diffstat:
| M | README.md | | | 37 | ++----------------------------------- |
| M | configs/commands.json | | | 102 | ++----------------------------------------------------------------------------- |
| M | handlers/irc.js | | | 244 | +------------------------------------------------------------------------------ |
| M | main.js | | | 94 | ++----------------------------------------------------------------------------- |
4 files changed, 8 insertions(+), 469 deletions(-)
diff --git a/README.md b/README.md
@@ -1,4 +1,3 @@
-<<<<<<< HEAD
[](https://codeclimate.com/github/MTRNord/nordlab-hackerspace-door)
Nordlab Bot
===========
@@ -30,37 +29,4 @@ Commands
Updates
=======
-The Bot pulls the repo every day at 2am (if not deativated) and restarts the bot. So it is always UpTo-Date :)<br>
-=======
-Nordlab Bot
-===========
-Modular parser for the hackerspace door status with handlers for multiple services and IRC Bot for the Nordlab e.V.
-
-How to install
-==============
-1. npm install
-2. npm start
-
-Commandline options
-===================
-When using commandline arguments use ```node main.js``` to start.<br>
-```--noupdate``` - stops bot from getting updates <br>
-
-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>
-```!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>
-```!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>
-
-Updates
-=======
-The Bot pulls the repo every day at 2am (if not deativated) and restarts the bot. So it is always UpTo-Date :)<br>
->>>>>>> master
+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
diff --git a/configs/commands.json b/configs/commands.json
@@ -1,4 +1,3 @@
-<<<<<<< HEAD
{
"commands": [
{
@@ -88,102 +87,4 @@
"target": "from"
}
]
-}
-=======
-{
- "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 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 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",
- "argument": "0",
- "target": "from"
- },
- {
- "keyword": "who",
- "message": "Everybody can come to the Nordlab e.V.",
- "argument": "0",
- "target": "from"
- },
- {
- "keyword": "when",
- "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",
- "argument": "0",
- "target": "from"
- },
- {
- "keyword": "license",
- "message": "You can find the license of this bot at https://github.com/MTRNord/nordlab-hackerspace-door/blob/master/LICENSE.md",
- "argument": "0",
- "target": "from"
- },
- {
- "keyword": "bug",
- "message": "You have found an bug? :O Send it right now to https://github.com/MTRNord/nordlab-hackerspace-door/issues",
- "argument": "0",
- "target": "from"
- },
- {
- "keyword": "klassiker",
- "message": "Für mehr oder weniger hilfreiche Kommentare den klassiker fragen und wenn er mal nicht reagiert ist er damit beschäftigt dem MTRNord damit zu queälen seinen realnamen nicht zu sagen. :( <-- sad MTRNord face.",
- "argument": "0",
- "target": "to"
- },
- {
- "keyword": "stina",
- "message": "Stina liebt unzielgerichteten Unsinn *lach*",
- "argument": "0",
- "target": "to"
- },
- {
- "keyword": "afk",
- "before": "from",
- "message": " is now afk.",
- "argument": "0",
- "target": "to"
- },
- {
- "keyword": "alone",
- "before": "from",
- "message": " is now alone.",
- "argument": "0",
- "target": "to"
- },
- {
- "keyword": "freifunk",
- "message": "http://memegen.link/buzz/freifunk/everywhere.-the-dream.jpg",
- "argument": "0",
- "target": "to"
- },
- {
- "keyword": "todo",
- "message": "- Add ability to do multiple server connections\n- Add SSH Admin Control Server for editing the bot easily",
- "argument": "0",
- "target": "from"
- },
- {
- "keyword": "xmas",
- "message": "Der NordlabBot wünscht euch allen eine frohe und besinliche Weihnachtszeit :)",
- "argument": "0",
- "target": "to"
- }
- ]
-}
->>>>>>> master
+}
+\ No newline at end of file
diff --git a/handlers/irc.js b/handlers/irc.js
@@ -1,4 +1,3 @@
-<<<<<<< HEAD
/**
* IRC-ChatBot Module
*
@@ -450,244 +449,4 @@ module.exports = {
ircNick: function() {
send('nick', botname);
}
-};
-=======
-var irc = require('irc');
-var request = require('request');
-var command_config = require("../configs/commands.json");
-var params_config = require("../configs/params.json");
-
-//Set Params
-var botname = params_config["botname"];
-var autoupdate = params_config["autoupdate"];
-var disconnect_meassage = params_config["disconnect_meassage"];
-/* // TEMPLATE //
-for (var key in params_config["servers"]) {
- if (params_config["servers"].hasOwnProperty(key)) {
- var servername = params_config["servers"][key]["servername"];
- var serveraddress = params_config["servers"][key]["serveraddress"];
- var main_channel = params_config["servers"][key]["main_channel"];
- var nickserv_pass = params_config["servers"][key]["nickserv_pass"];
- var active = params_config["servers"][key]["active"];
- var debug = params_config["servers"][key]["debug"];
- if (debug == 1) {
- var debug = true;
- }else{
- var debug = false;
- }
- }
-}
-*/
-
-
-for (var key in params_config["servers"]) {
- if (params_config["servers"].hasOwnProperty(key)) {
- var serveraddress = params_config["servers"][key]["serveraddress"];
- var main_channel = params_config["servers"][key]["main_channel"];
- var active = params_config["servers"][key]["active"];
- var debug = params_config["servers"][key]["debug"];
- if (debug == 1) {
- var debug = true;
- }else{
- var debug = false;
- }
- if (debug == false) {
- console = console || {};
- console.log = function(){};
- }
- if (active == 1) {
- var bot = new irc.Client(serveraddress, botname, {
- debug: debug,
- channels: [main_channel, "#freifunk-flensburg"],
- autoRejoin: true,
- autoConnect: false,
- messageSplit: 1000000
- });
- }
- }
-}
-
-module.exports = {
- ircEndCustom: function (meassage) {
- bot.disconnect(meassage);
- },
- ircPreload: function () {
- bot.addListener('error', function(message) {
- setTimeout(function() {
- console.log("wait 7sek");
- }, 7000);
-
- bot.send('nick', botname);
- for (var key in params_config["servers"]) {
- if (params_config["servers"].hasOwnProperty(key)) {
- var nickserv_pass = params_config["servers"][key]["nickserv_pass"];
- bot.say('NickServ', 'identify ' + nickserv_pass);
- }
- }
- });
- setTimeout(function() {
- console.log("wait 7sek");
- }, 7000);
- bot.connect(10, function() {
- bot.send('nick', botname);
- for (var key in params_config["servers"]) {
- if (params_config["servers"].hasOwnProperty(key)) {
- var nickserv_pass = params_config["servers"][key]["nickserv_pass"];
- var main_channel = params_config["servers"][key]["main_channel"];
- bot.say('NickServ', 'identify ' + nickserv_pass);
- bot.join(main_channel);
- }
- }
- bot.say('#hackerspace', 'Door Bot is starting to watch on the Door Status');
- })
- },
- ircSend: function (door_status) {
- for (var key in params_config["servers"]) {
- if (params_config["servers"].hasOwnProperty(key)) {
- var main_channel = params_config["servers"][key]["main_channel"];
- bot.say(main_channel, 'Door Status changed to: ' + door_status);
- bot.say("#freifunk-flensburg", '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(disconnect_meassage);
- },
- ircBotCommands: function() {
- // Will remove all false values: undefined, null, 0, false, NaN and "" (empty string)
- function cleanArray(actual) {
- var newArray = new Array();
- for (var i = 0; i < actual.length; i++) {
- if (actual[i]) {
- newArray.push(actual[i]);
- }
- }
- return newArray;
- }
-
- 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(" ");
- channel = cleanArray(channel);
- if (channel[0] + " " + channel[1] == "!source this") {
- console.log("!source " + channel[1]);
- if (channel[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 (!error && response.statusCode == 200) {
- if (door_status == "geschlossen") {
- door_status = "closed";
- } else {
- door_status = "open";
- }
- console.log(from + ' => ' + to + ': ' + message);
- bot.say(from, "DoorStatus is: " + door_status);
- }else{
- bot.say(from, "DoorStatus is not availible at this time");
- }
- }).setMaxListeners(0);
- }
- if (channel[0] + " " + channel[1] == "!doorstatus this") {
- 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 (!error && response.statusCode == 200) {
- 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[1] !== "this") {
- if (channel[1] !== " ") {
- bot.addListener('channellist', function (channel_list) {
- for (var key in channel_list) {
- if (channel_list.hasOwnProperty(key)) {
- if (channel_list[key]["name"] == channel[1]) {
- bot.join(channel[1]);
- bot.say(channel[1], "DoorStatus is: " + door_status);
- }
- }
- }
- });
- } else {
- bot.say(from, "DoorStatus is: " + door_status);
- }
- } else {
- bot.join(to);
- bot.say(to, "DoorStatus is: " + door_status);
- }
- }else{
- bot.say(from, "DoorStatus is not availible at this time");
- }
- }).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(disconnect_meassage);
- process.exit();
- }
- }
- }
- })
- },
- ircNick: function() {
- bot.send('nick', botname);
- }
-};
->>>>>>> master
+};
+\ No newline at end of file
diff --git a/main.js b/main.js
@@ -1,4 +1,3 @@
-<<<<<<< HEAD
/**
* Main-functionality for handling the Modules :)
*
@@ -181,94 +180,4 @@ async.auto({
console.log(err)
}
}
-);
-=======
-var request = require('request');
-var git = require('simple-git');
-var schedule = require('node-schedule');
-var argv = require('yargs').argv;
-var fs = require('fs');
-var params_config = require("./configs/params.json");
-var autoupdate = params_config["autoupdate"];
-
-//LOAD MODULES DOWN HERE
-var pushbullet = require('./handlers/pushbullet.js');
-var irc = require('./handlers/irc.js');
-
-//Constants
-var SIGINT = "SIGINT";
-
-console.log("Starting up...");
-var door_status2 = "1";
-irc.ircPreload();
-function MakePush(){
-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 (!error && response.statusCode == 200) {
- // console.log("Current Real State:" + door_status + "\n");
- // console.log("Current Last State:" + door_status2 + "\n");
- // console.log("Next Check!");
- if (door_status2 !== door_status){
- if (door_status2 !== "1") {
- door_status2 = door_status;
- if (door_status == "geschlossen"){
- door_status = "closed";
- }else{
- door_status = "open";
- }
- //ADD MODULE RUNTIMES DOWN HERE
- pushbullet.pushbulletSend(door_status);
- irc.ircSend(door_status);
- }else{
- door_status2 = door_status;
- }
- }
- }
- // console.log("WAIT!");
- if (process.platform === "win32") {
- var rl = require("readline").createInterface({
- input: process.stdin,
- output: process.stdout
- }).setMaxListeners(0);
-
- rl.on(SIGINT, function () {
- process.emit(SIGINT);
- }).setMaxListeners(0);
- }
-
- process.on(SIGINT, function () {
- irc.ircStopp();
- process.exit();
- }).setMaxListeners(0);
- setTimeout(function() { MakePush(); }, 10000);
-}).setMaxListeners(0);
-}
-irc.ircBotCommands();
-if (!argv.noupdate && autoupdate == 1) {
- var j = schedule.scheduleJob('59 3 * * *', function(){
- git.pull("origin", "master", function(err, update) {
- if(update && update.summary.changes) {
- console.log('Start Update!');
-
- console.log('Daily restart!');
- irc.ircEndCustom('Start update! Coming back in a few Seconds!');
- require('child_process').exec('npm restart');
- }
- });
- });
-}
-if ((argv.noupdate) || (autoupdate == 0)) {
- var k = schedule.scheduleJob('59 3 * * *', function(){
- console.log('Daily restart!');
- irc.ircEndCustom('Daily restart! Coming back in a few Seconds!');
- require('child_process').exec('npm restart');
- });
-}
-setTimeout(function() { MakePush(); }, 20000);
->>>>>>> master
+);
+\ No newline at end of file