commit 1636d124677c4537068c3237b17fb59bf224afd6
parent a5d02a601487b19a7041db41ef85af918761d017
Author: Marcel Radzio <marcel@radzio-sh.de>
Date: Sat, 12 Dec 2015 23:26:26 +0100
Add 'this' argument to source command
Diffstat:
2 files changed, 111 insertions(+), 105 deletions(-)
diff --git a/README.md b/README.md
@@ -20,7 +20,7 @@ Commands
```!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<br>
+```!source``` - Send an PM with the Link of this Repo. If you add this 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>
diff --git a/handlers/irc.js b/handlers/irc.js
@@ -1,11 +1,11 @@
var irc = require('irc');
var bot = new irc.Client('irc.lugfl.de', 'NordlabBot', {
- debug: false,
- channels: ['#hackerspace'],
- autoRejoin: false,
- autoConnect: false,
- messageSplit: 1000000
- });
+ debug: false,
+ channels: ['#hackerspace'],
+ autoRejoin: false,
+ autoConnect: false,
+ messageSplit: 1000000
+});
var request = require('request');
var command_config = require("../commands.json");
module.exports = {
@@ -14,94 +14,100 @@ module.exports = {
},
ircPreload: function (){
bot.addListener('error', function(message) {
- setTimeout(function() {
+ setTimeout(function() {
// console.log("wait 7sek");
}, 7000);
- bot.send('nick', 'NordlabBot');
- bot.say('NickServ', 'identify NordlabBotPass');
+ bot.send('nick', 'NordlabBot');
+ bot.say('NickServ', 'identify NordlabBotPass');
});
setTimeout(function() {
// console.log("wait 7sek");
}, 7000);
bot.connect(10, function() {
bot.send('nick', 'NordlabBot');
- bot.say('NickServ', 'identify NordlabBotPass');
+ bot.say('NickServ', 'identify NordlabBotPass');
bot.join('#hackerspace');
//bot.say('#hackerspace', 'Door Bot is starting to watch on the Door Status');
})
},
ircSend: function (door_status){
- bot.say('#hackerspace', 'Door Status changed to: ' + 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();
+ },
+ 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"]);
- }
- }
- }
- }
+ 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"]);
+ }
+ }
+ }
}
- }
- 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);
- }
- var channel = message.split(" ");
- 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;
+ }
+ }
+ 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{
+ }else{
door_status = error;
//console.log(error);
- }
- if (door_status == "geschlossen"){
- door_status = "closed";
- }else{
- door_status = "open";
- }
+ }
+ 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]);
@@ -110,40 +116,40 @@ module.exports = {
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);
+ 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.say(from, "DoorStatus is: " + door_status);
+ }
}else{
bot.join(to);
- bot.say(to, "DoorStatus is: " + door_status);
+ bot.say(to, "DoorStatus is: " + door_status);
}
- }).setMaxListeners(0);
- }
- if (message == "!kill"){
- if ((from == "DasNordlicht") || (from == "MTRNord")) {
+ }).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();
- }
- }
+ 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');
- }
+ })
+},
+ircNick: function() {
+ bot.send('nick', 'NordlabBot');
+}
};
\ No newline at end of file