Skip to content

Instantly share code, notes, and snippets.

@NuckChorris
Created January 22, 2013 06:46
Show Gist options
  • Select an option

  • Save NuckChorris/4592640 to your computer and use it in GitHub Desktop.

Select an option

Save NuckChorris/4592640 to your computer and use it in GitHub Desktop.
var bot = require('./bot');
var compileSong = function (lines) {
var trigs = {};
var addTrig = function (time, line) {
if (!line.func && line.text) {
line.func = function () {
return line.text;
};
}
trigs[time] = line.func;
};
for (var i = 0, l = lines.length; i < l; i++) {
var line = lines[i];
if (line.duration && line.frequency) {
addTrig(line.time, line);
var t = line.time + line.frequency;
var end = line.time + line.duration;
while (t <= end) {
addTrig(t, line);
t += line.frequency;
}
} else {
addTrig(line.time, line);
}
}
return trigs;
};
var sing = function sing (song) {
var i = 0;
setInterval(function () {
i++;
if (song[i]) {
bot.speak(song[i]());
}
}, 1000);
};
module.exports.compileSong = compileSong;
module.exports.sing = sing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment