From 2fab1e3f1ec2e0833409fbecb5221179c8d4a449 Mon Sep 17 00:00:00 2001 From: henne Date: Wed, 2 Nov 2016 23:23:20 +0100 Subject: [PATCH] support mutiple channels --- src/ctdo.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/ctdo.js b/src/ctdo.js index a466dfb..fd2a95f 100644 --- a/src/ctdo.js +++ b/src/ctdo.js @@ -45,10 +45,10 @@ module.exports = function(robot) { // topic robot.adapter.bot.addListener('topic', function(channel, topic) { robot.brain.data.topics[channel] = topic - setTopic(topic); + setTopic(channel, topic); }); - function setTopic(currentTopic) { + function setTopic(channel, currentTopic) { robot.http("https://status.ctdo.de/api/simple/v2") .header('Accept', 'application/json') .get()(function(err, res, body) { @@ -76,14 +76,18 @@ module.exports = function(robot) { } } if(newTopic !== currentTopic) { - robot.brain.data.topics[process.env['HUBOT_IRC_ROOMS']] = newTopic; - robot.adapter.topic({room: process.env['HUBOT_IRC_ROOMS']}, newTopic); + robot.brain.data.topics[channel] = newTopic; + robot.adapter.topic({room: channel}, newTopic); } }) } // topic interval setInterval(function() { - setTopic(robot.brain.data.topics[process.env['HUBOT_IRC_ROOMS']]); + var channels = process.env['HUBOT_IRC_ROOMS']; + channels = channels.split(','); + channels.forEach(function(c) { + setTopic(robot.brain.data.topics[c]); + } }, 5000); // gem var gem = false; @@ -113,4 +117,21 @@ module.exports = function(robot) { r.reply("Ich erkenne niemanden im Treff."); }) }); + // disco + var discoInterval; + function disco() { + setLampel(Math.random() >= 0.5, Math.random() >= 0.5, Math.random() >= 0.5); + } + robot.respond(/(disco|disco ([0-9]{1,3}))$/i, function(r) { + if(typeof(discoInterval) !== 'undefined') { + clearInterval(discoInterval); // hebt den interval auf. + return discoInterval = undefined; + } + if(r.match.length === 2) { + console.log(parseInt(r.match[1])); + setInterval(disco, r.match[1]); + } else { + setInterval(disco, 500); // 120bpm! + } + }); }