-
Notifications
You must be signed in to change notification settings - Fork 97
Stuck Song Detection and Correction
Who knows exactly why, but a song usually gets stuck at the end of the song. When this happens, the title bar just turns blank and everyone sits there wondering what happened because no one was really paying attention to who was just playing a song. I've heard of songs being stuck in popular rooms for hours, effectively shutting down the room.
This script fixes that problem, in a nice way. If a song doesn't end, the newsong event won't be called, so if we set a watchdog timer when the song starts for the "length" of the song plus 10 seconds. If it expires, it will give us a place to "fix" the problem. Currently, it warns the user with the stuck song, giving them 10 seconds to skip, then removes the stuck DJ if they don't respond. If the newsong event comes at the right time, we'll have a chance to clear the timer and nobody will be the wiser that there was a little watchdog timer running in background.
As an added bonus, there are two lines of code that make the bot PM the admin with what happened, the user's name and id just for good measure. config.admin.userid is your userid, which can be entered anyway you see fit, even hard coded.
global.curSongWatchdog = null;
global.takedownTimer = null;
global.lastdj = null;
bot.on('newsong', function (data){
var length = data.room.metadata.current_song.metadata.length;
// If watch dog has been previously set,
// clear since we've made it to the next song
if(curSongWatchdog != null) {
clearTimeout(curSongWatchdog);
curSongWatchdog = null;
}
// If takedown Timer has been set,
// clear since we've made it to the next song
if(takedownTimer != null) {
clearTimeout(takedownTimer);
takedownTimer = null;
bot.speak("@"+theUsersList[lastdj].name+", Thanks buddy ;-)");
bot.pm(theUsersList[lastdj].name+" "+lastdj+" SONG WAS STUCK and they SKIPPED :-) ",config.admin.userid);
}
// Set this after processing things from previously set watchdog timer
lastdj = data.room.metadata.current_dj;
// Set a new watchdog timer for the current song.
curSongWatchdog = setTimeout( function() {
curSongWatchdog = null;
bot.speak("@"+theUsersList[lastdj].name+", you have 10 seconds to skip your stuck song before you are removed");
//START THE 10 SEC TIMER
takedownTimer = setTimeout( function() {
takedownTimer = null;
bot.remDj(lastdj); // Remove Saved DJ from last newsong call
bot.pm(theUsersList[lastdj].name+" "+lastdj+" SONG WAS STUCK and they got REMOVED :-(",config.admin.userid);
}, 10 * 1000); // Current DJ has 10 seconds to skip before they are removed
}, (length + 10) * 1000); // Timer expires 10 seconds after the end of the song, if not cleared by a newsong
});
The only thing not shown is how the theUsersList[lastdj].name is implemented... this can be done numerous ways in the registered and roomChanged events.
by B^Dub (aka DubbyTT) 10-28-2012 "DubbyTT"+"@"+"gmail"+"."+"com"