Skip to content

Instantly share code, notes, and snippets.

@NuckChorris
Last active December 11, 2015 11:18
Show Gist options
  • Select an option

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

Select an option

Save NuckChorris/4592653 to your computer and use it in GitHub Desktop.
var singer = require('./singer.js');
var ponDeFloor = singer.compileSong(require('./ponDeFloor.js'));
bot.on('newsong', function (data) {
var song = data.room.metadata.current_song;
// I forget how I detected songs, but once you've determined the song is Pon De Floor...
singer.sing(bot, ponDeFloor);
});
module.exports = [
{
"time": 38,
"text": "MAJOR LAZER"
},
{
"time": 45,
"text": "PON DE FLOOR"
},
{
"time": 46,
"duration": 29,
"frequency": 7,
"func": function (time) {
// oooOOOOoooooOOOOoooo
var out = '';
for (var i = 0, l = 3 + Math.round(Math.random() * 5); i < l; i++) {
out += Array(2 + Math.floor(Math.random() * 6)).join('O');
out += Array(2 + Math.floor(Math.random() * 6)).join('o');
}
return out;
}
},
{
"time": 77,
"duration": 10,
"frequency": 5,
"text": "BABY GET IN LINE, LET ME SEE YOUR BESTEST WINES"
},
{
"time": 90,
"duration": 10,
"frequency": 5,
"text": "PON DE FLOOR, ANYWAY"
},
{
"time": 106,
"duration": 44,
"frequency": 7,
"func": function (time) {
// oooOOOOoooooOOOOoooo
var out = '';
for (var i = 0, l = 3 + Math.round(Math.random() * 5); i < l; i++) {
out += Array(2 + Math.floor(Math.random() * 6)).join('O');
out += Array(2 + Math.floor(Math.random() * 6)).join('o');
}
return out;
}
},
{
"time": 159,
"text": "MAJOR LAZER"
},
{
"time": 160,
"duration": 10,
"frequency": 5,
"text": "BABY GET IN LINE, LET ME SEE YOUR BESTEST WINES"
},
{
"time": 175,
"duration": 47,
"frequency": 7,
"func": function (time) {
// oooOOOOoooooOOOOoooo
var out = '';
for (var i = 0, l = 3 + Math.round(Math.random() * 5); i < l; i++) {
out += Array(2 + Math.floor(Math.random() * 6)).join('O');
out += Array(2 + Math.floor(Math.random() * 6)).join('o');
}
return out;
}
},
{
"time": 199,
"text": "BEEP BEEP BEEP BEEP"
}
];
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 (bot, 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