Browse files

continued work on booth enforcement. song and idle time limit functio…

…nality should be in place, although functionality to prevent reentering the booth immediately after being removed is not yet there.
  • Loading branch information...
1 parent 36cb9a9 commit 40f18da9ae2ac2feff8ed439197f7173761375f3 @anamorphism committed Dec 15, 2011
Showing with 61 additions and 5 deletions.
  1. +48 −5 bot.js
  2. +13 −0 config.js
View
53 bot.js
@@ -14,14 +14,18 @@ ttfm.on('add_dj', function(data) {
// update our active DJs list
if (activeDJs && activeDJs.hasOwnProperty(data.user.userid)) {
AFKDJUpdate(data.user.userid);
- //$ checks for play limit and queue bypassing attempts will go here
+ //$ checks for rate limit, play limit and queue bypassing attempts will go here
} else {
AddActiveDJ(data.user.userid);
}
}
AutoDJCheck();
});
-
+
+ttfm.on('endsong', function() {
+ if (Config.BoothEnforce) EnforceBooth();
+});
+
ttfm.on('newsong', function(data) {
currentPlayId = null;
AutoDJCheck();
@@ -53,7 +57,10 @@ ttfm.on('ready', function() {
AutoDJCheck();
});
-ttfm.on('rem_dj', function(data) {
+ttfm.on('rem_dj', function(data) {
+ if (data.success) {
+ RemoveActiveDJ(data.user.userid);
+ }
AutoDJCheck();
});
@@ -87,7 +94,12 @@ ttfm.on('speak', function(data) {
Config.AutoBop = !Config.AutoBop;
ttfm.speak('Auto-Bop set to ' + Config.AutoBop + '.');
break;
-
+
+ case 'enforce':
+ Config.BoothEnforce = !Config.BoothEnforce;
+ ttfm.speak('Booth enforcement set to ' + Config.BoothEnforce + '.');
+ break;
+
// djing
case 'autodj':
Config.AutoDJ = !Config.AutoDJ;
@@ -112,7 +124,8 @@ ttfm.on('speak', function(data) {
break;
// queue
- case 'snag':
+ case 'snag
+ //$ need to change this to add songs to end of queue instead of beginning
ttfm.roomInfo(function(data) {
if (data.room.metadata.current_song._id) {
ttfm.playlistAdd(data.room.metadata.current_song._id, function(data) {
@@ -178,6 +191,12 @@ function AddActiveDJ(userid) {
}
}
+function RemoveActiveDJ(userid) {
+ if (activeDJs && userid && activeDJs.hasOwnProperty(userid)) {
+ activeDJs[userid].removed = new Date();
+ }
+}
+
function AFKDJUpdate(userid) {
if (activeDJs && userid && activeDJs.hasOwnProperty(userid)) {
activeDJs[userid].lastActive = new Date();
@@ -210,6 +229,30 @@ function AutoDJCheck() {
});
}
+function EnforceBooth() {
+ if (Config.BoothIdleLimit > 0) {
+ // convert idle time to milliseconds
+ var limit = Config.BoothIdleLimit * 60000;
+ var now = new Date();
+ for (var i in activeDJs) {
+ if ((now - activeDJs[i].lastActive) > limit) {
+ activeDJs[i].removed = now;
+ ttfm.remDj(i);
+ if (Config.BoothIdleLimitMessage) ttfm.speak(Config.BoothIdleLimitMessage);
+ }
+ }
+ }
+ if (Config.BoothSongLimit > 0) {
+ for (var i in activeDJs) {
+ if (activeDJs[i].plays >= Config.BoothSongLimit) {
+ activeDJs[i].removed = now;
+ ttfm.remDj(i);
+ if (Config.BoothSongLimitMessage) ttfm.speak(Config.BoothSongLimitMessage);
+ }
+ }
+ }
+}
+
function PopulateCurrent(data) {
ttfm.getProfile(data.room.metadata.current_dj, function(profile) {
if (profile) {
View
13 config.js
@@ -18,6 +18,19 @@ exports.AutoDJMin = 2;
// this number should be at least 2 greater than the min
exports.AutoDJMax = 4;
+// perform booth enforcement, bot needs to be a room moderator for this to work
+exports.BoothEnforce = false;
+// maximum time a dj can be idle, < 1 for none
+exports.BoothIdleLimit = 30;
+// message to say when removing djs for being idle, null for no message
+exports.BoothIdleLimitMessage = 'You have been removed from the booth for being inactive for too long. Please wait 5 minutes before attempting to reenter the booth.';
+// minimum amount of time in minutes before someone can get back into the booth, < 1 for none
+exports.BoothRateLimit = 5;
+// song limit, < 1 for none
+exports.BoothSongLimit = 10;
+// message to say when removing djs for hitting the song limit, null for no message
+exports.BoothSongLimitMessage = 'You have played the maximum number of songs. Please wait 5 minutes before attempting to reenter the booth.';
+
// auth code for the bot to use, should be 'auth+live+xxxxxxxx'
exports.BotAuth = process.env.TTFMBOT_USER_AUTH;
// turntable user id of the bot

0 comments on commit 40f18da

Please sign in to comment.