const net = require('net'); 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); }); } robot.hear(/^rot$/i, function(r) { setLampel(1,0,0); }); robot.hear(/^gruen$/i, function(r) { setLampel(0,0,1); }); robot.hear(/^gelb$/i, function(r) { setLampel(0,1,0); }); robot.hear(/^(all|alle)$/i, function(r) { setLampel(1,1,1); }); robot.hear(/^(rotgelb|gelbrot)$/i, function(r) { setLampel(1,1,0); }); robot.hear(/^(gruengelb|gelbgruen)$/i, function(r) { setLampel(0,1,1); }); robot.hear(/^(rotgruen|gruenrot)$/i, function(r) { setLampel(1,0,1); }); // 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 robot.respond(/status$/i, function(r) { robot.http("http://status.ctdo.de/api/simple/v2") .header('Accept', 'application/json') .get()(function(err, res, body) { var data = JSON.parse(body); r.reply("Derzeit im Treff: " + data.names.join(', ')); }) }); }