support mutiple channels

This commit is contained in:
henne 2016-11-02 23:23:20 +01:00
parent 1003fa0f4f
commit 2fab1e3f1e
1 changed files with 26 additions and 5 deletions

View File

@ -45,10 +45,10 @@ module.exports = function(robot) {
// topic // topic
robot.adapter.bot.addListener('topic', function(channel, topic) { robot.adapter.bot.addListener('topic', function(channel, topic) {
robot.brain.data.topics[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") robot.http("https://status.ctdo.de/api/simple/v2")
.header('Accept', 'application/json') .header('Accept', 'application/json')
.get()(function(err, res, body) { .get()(function(err, res, body) {
@ -76,14 +76,18 @@ module.exports = function(robot) {
} }
} }
if(newTopic !== currentTopic) { if(newTopic !== currentTopic) {
robot.brain.data.topics[process.env['HUBOT_IRC_ROOMS']] = newTopic; robot.brain.data.topics[channel] = newTopic;
robot.adapter.topic({room: process.env['HUBOT_IRC_ROOMS']}, newTopic); robot.adapter.topic({room: channel}, newTopic);
} }
}) })
} }
// topic interval // topic interval
setInterval(function() { 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); }, 5000);
// gem // gem
var gem = false; var gem = false;
@ -113,4 +117,21 @@ module.exports = function(robot) {
r.reply("Ich erkenne niemanden im Treff."); 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!
}
});
} }