2016-04-24 20:05:56 +00:00
|
|
|
const net = require('net');
|
|
|
|
|
2016-04-28 21:32:29 +00:00
|
|
|
const myName = process.env['HUBOT_IRC_NICK'];
|
2016-04-24 20:05:56 +00:00
|
|
|
module.exports = function(robot) {
|
|
|
|
// old stuff
|
|
|
|
// lampel
|
|
|
|
function setLampel(r,ge,gr) {
|
|
|
|
var x = 0;
|
|
|
|
if(r)
|
|
|
|
x+=4;
|
|
|
|
if(ge)
|
|
|
|
x+=2;
|
|
|
|
if(gr)
|
|
|
|
x+=1;
|
|
|
|
var command = "io set port 2 0"+x+"\n";
|
|
|
|
var client = net.createConnection({port: 2701, host: 'lampel.raum.ctdo.de'}, function() {
|
|
|
|
client.end(command);
|
|
|
|
});
|
|
|
|
}
|
2016-04-30 12:43:44 +00:00
|
|
|
robot.respond(/rot$/i, function(r) {
|
2016-04-24 20:05:56 +00:00
|
|
|
setLampel(1,0,0);
|
|
|
|
});
|
2016-04-30 12:58:14 +00:00
|
|
|
robot.respond(/gruen$/i, function(r) {
|
2016-04-24 20:05:56 +00:00
|
|
|
setLampel(0,0,1);
|
|
|
|
});
|
2016-04-30 12:43:44 +00:00
|
|
|
robot.respond(/gelb$/i, function(r) {
|
2016-04-24 20:05:56 +00:00
|
|
|
setLampel(0,1,0);
|
|
|
|
});
|
2016-04-30 12:43:44 +00:00
|
|
|
robot.respond(/(all|alle|rotgelbgruen|gelbrotgruen|rotgruengelb|gelbgruenrot|gruenrotgelb|gruengelbrot)$/i, function(r) {
|
2016-04-24 20:05:56 +00:00
|
|
|
setLampel(1,1,1);
|
|
|
|
});
|
2016-04-30 12:43:44 +00:00
|
|
|
robot.respond(/(rotgelb|gelbrot)$/i, function(r) {
|
2016-04-24 20:05:56 +00:00
|
|
|
setLampel(1,1,0);
|
|
|
|
});
|
2016-04-30 12:43:44 +00:00
|
|
|
robot.respond(/(gruengelb|gelbgruen)$/i, function(r) {
|
2016-04-24 20:05:56 +00:00
|
|
|
setLampel(0,1,1);
|
|
|
|
});
|
2016-04-30 12:43:44 +00:00
|
|
|
robot.respond(/(rotgruen|gruenrot)$/i, function(r) {
|
2016-04-24 20:05:56 +00:00
|
|
|
setLampel(1,0,1);
|
|
|
|
});
|
2016-04-30 12:43:44 +00:00
|
|
|
robot.respond(/(aus|off)$/i, function(r) {
|
2016-04-30 09:43:35 +00:00
|
|
|
setLampel(0,0,0);
|
2016-04-30 09:45:08 +00:00
|
|
|
});
|
2016-04-24 20:05:56 +00:00
|
|
|
// topic
|
|
|
|
robot.adapter.bot.addListener('topic', function(channel, topic) {
|
|
|
|
if(typeof(robot.brain.data.topics) !== 'Object') {
|
|
|
|
robot.brain.data.topics = {}
|
|
|
|
}
|
|
|
|
robot.brain.data.topics[channel] = topic
|
|
|
|
setTopic(topic);
|
|
|
|
});
|
|
|
|
|
|
|
|
function setTopic(currentTopic) {
|
|
|
|
robot.http("http://status.ctdo.de/api/simple/v2")
|
|
|
|
.header('Accept', 'application/json')
|
|
|
|
.get()(function(err, res, body) {
|
|
|
|
var data = JSON.parse(body);
|
|
|
|
var raum_offen = /(raum: |r: )(auf|offen|open)/ig;
|
|
|
|
var raum_zu = /(raum: |r: )(zu|geschlossen|closed)/ig
|
|
|
|
var currentState = data.state;
|
|
|
|
var newTopic = currentTopic;
|
|
|
|
if(currentTopic.match(raum_offen)) {
|
|
|
|
// wenn raum auf drinsteht
|
|
|
|
if(!data.state) {
|
|
|
|
newTopic = currentTopic.replace(raum_offen, 'Raum: zu');
|
|
|
|
}
|
|
|
|
} else if(currentTopic.match(raum_zu)) {
|
|
|
|
// wenn raum zu drinsteht
|
|
|
|
if(data.state) {
|
|
|
|
newTopic = currentTopic.replace(raum_zu, 'Raum: auf');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// wenn nix drinsteht
|
|
|
|
if(data.state) {
|
|
|
|
newTopic = "Raum: auf | " + currentTopic;
|
|
|
|
} else {
|
|
|
|
newTopic = "Raum: zu | " + currentTopic;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(newTopic !== currentTopic) {
|
|
|
|
robot.brain.data.topics[process.env['HUBOT_IRC_ROOMS']] = newTopic;
|
|
|
|
robot.adapter.topic({room: process.env['HUBOT_IRC_ROOMS']}, newTopic);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// topic interval
|
|
|
|
setInterval(function() {
|
|
|
|
setTopic(robot.brain.data.topics[process.env['HUBOT_IRC_ROOMS']]);
|
|
|
|
}, 5000);
|
|
|
|
// gem
|
|
|
|
var gem = false;
|
|
|
|
robot.respond(/gem$/i, function(r) {
|
|
|
|
if(gem) {
|
|
|
|
gem = false;
|
|
|
|
r.reply("Gem Deactivated");
|
|
|
|
} else {
|
|
|
|
gem = true;
|
|
|
|
var c = Math.floor(Math.random() * 100) + 1;
|
|
|
|
if(c>99) {
|
|
|
|
r.reply('Mooooooooooooo!');
|
|
|
|
} else {
|
|
|
|
r.reply("Gem Activated");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// new stuff
|
2016-04-30 10:03:49 +00:00
|
|
|
robot.respond(/status$/i, function(r) {
|
2016-04-30 09:43:35 +00:00
|
|
|
console.log("status");
|
2016-04-24 20:05:56 +00:00
|
|
|
robot.http("http://status.ctdo.de/api/simple/v2")
|
|
|
|
.header('Accept', 'application/json')
|
|
|
|
.get()(function(err, res, body) {
|
|
|
|
var data = JSON.parse(body);
|
2016-04-30 09:43:35 +00:00
|
|
|
console.log(body);
|
2016-04-24 20:05:56 +00:00
|
|
|
r.reply("Derzeit im Treff: " + data.names.join(', '));
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|