Bots Home
|
Create an App
joker tip to view
Author:
joker_luciano
Description
Source Code
Launch Bot
Current Users
Created by:
Joker_Luciano
// Keep It Up limitCam Bot // Author: mark54321 // Version: 1.0 // // This bot only allows viewers that tip regularly to access to the broadcaster's camera. // Viewers are allowed to view the cam for a configurable length of time. Within // that time they must have tipped a configurable minimum amount or they can no // longer view the camera. They can view the camera again by tipping the minimum amount. // In short, viewers must continue to tip in order to continue viewing the camera. // // Basically, there are two ways to configure and use the app: // // 1. A single entry fee and no tipping required afterwords (kind of like a password show without having to set a password) // 2. Require regular tipping with an optional entry fee // // Broadcasters may set: // * The time limit before non-tipping viewers are cut off from the camera // * The minimum tip amount required within each time limit block // * An optional minimum "entry" tip to view the camera. Without it users get a "free view" for a limited amount of time. // * Whether or not mods are automatically exempt from the time/tipping limits // * Whether or not fan club members are automatically exempt from the time/tipping limits // * The broadcaster may make specific viewers exempt from the time/tipping limits at any time (and remove that exemption) // * The broadcaster and mods may remove specific users at any time. This removes them from the camera feed without having to ban them. // * "Removed" users can be "unremoved" by the broadcaster or mods var KeepItUpApp = function () { var appName = "Keep It Up", self, users = {}, timerSet = false, timerInterval = 60000, minStartTokens, tipTimeInterval, minTip, allowList, modsExempt, fansExempt; // Fore- and background colors for different chot notices var msgColors = { info:{background: "#ffffff", color: "#000090", weight:"normal"}, notice:{background: "#00cccc", color: "#000000", weight:"normal"}, warn:{background: "#cc6600", color: "#ffffff", weight:"normal"}, important:{background: "#aa0303", color: "#ffffff", weight:"bold"}, entered: {background: "#03aa03", color: "#ffffff", weight:"normal"} }; var lineDelimiter = "################################################################################"; return { // Initializes the app // This should be called after the broadcaster settting have been made init: function () { // Get some settings minStartTokens = cb.settings.minStartTokens; tipTimeInterval = cb.settings.tipTimeInterval * 60; minTip = cb.settings.minTip; allowList = cb.settings.allowList && cb.settings.allowList.length ? cb.settings.allowList.split(" ") : []; modsExempt = cb.settings.modsPay === "No" ? true : false; fansExempt = cb.settings.fansPay === "No" ? true : false; self.sendInfo(cb.room_slug + "'s " + appName + " started"); }, // Helper function to initialize the timer and auction time keeping initTimer: function () { // Start the timer if needed if (!timerSet) { cb.setTimeout(self.onTimer, timerInterval); timerSet = true; } }, // Sets up and returns the broadcaster bot settings template getSettingChoices: function () { self = this; return [ { name: 'minStartTokens', label: "Cost to join the show. Set to 0 to allow users a 'free view' for the time interval set below.", type: 'int', minValue: 0, maxValue: 10000, defaultValue: 100 }, { name: 'hiddenCamMessage', label: 'Message displayed in the camera when the show is in progress', type: 'str', minLength: 1, maxLength: 256, defaultValue: appName + ' show in progress! Type /rules to see how to join in on the fun!' }, { name: "tipTimeInterval", label: "The time interval in minutes. Users must tip the minimum amount within each interval or be cut off from the camera.", type: "choice", choice1: 1, choice2: 10, choice3: 15, choice4: 20, choice5: 25, choice6: 30, defaultValue: 10 }, { name: "minTip", label: "The minimum tip users must tip each time interval or be cut off from the camera.", type: "int", minValue: 0, defaultValue: 5 }, { name: 'allowList', label: 'Guest List. Enter the usernames, separated by a SPACE, of the users that are automatically allowed in. You can add others at any time with the /allow comand', type: 'str', minLength: 0, maxLength: 512, required: false }, { name: "modsPay", label: "Do the time/tip limits apply to Mods?", type: "choice", choice1: "Yes", choice2: "No", defaultValue: "No" }, { name: "fansPay", label: "Do the time/tip limits apply to Fan Club members?", type: "choice", choice1: "Yes", choice2: "No", defaultValue: "No" } ]; }, // Called when a tip has been sent. // If the user is already in the show, we update their tip total for the interval. // If the user is not in the show and there is no entry fee, or the tip // (or cumulative tips) covers the entry fee, add them. onTip: function (tip) { var user = null, msg = "", tipAmount = parseInt(tip.amount, 10); //Check if the user is already in the show if (self.isInShow(tip.from_user)) { // Update the time interval tip total users[tip.from_user].tips += tipAmount; } else if (typeof users[tip.from_user] !== "undefined" && users[tip.from_user].isRemoved) { // User was explicitly removed. Let them know msg = tip.from_user + ": Thank you for the tip but you have been explicitly removed by " + cb.room_slug; msg += ". Only " + cb.room_slug + " can allow you back in again."; self.sendNotice(msg, tip.from_user); } else if (minStartTokens > 0) { // There is a min entry fee. See if the user is exempt, already paid it or the tip covers the fee if (typeof users[tip.from_user] !== "undefined") { user = users[tip.from_user]; } else { user = self.createUser(tip.from_user, tip.from_user_is_mod, tip.from_user_in_fanclub, false); } if (self.isUserExempt(user.username, user.isMod, user.isFan) || user.entryPaid || tipAmount >= minStartTokens || (user.tips + tipAmount) >= minStartTokens) { // Add the user user = self.addUser(user.username, user.isMod, user.isFan, user.allowed); user.tips += tipAmount; user.entryPaid = true; } else if ((user.tips + tipAmount) < minStartTokens) { // Tell the user about the entry fee msg = tip.from_user + ": You must tip " + (minStartTokens - (user.tips + tipAmount)) + " more tokens to join the show."; self.sendNotice(msg, tip.from_user); } else { // Tell the user about the entry fee msg = tip.from_user + ": You must tip " + minStartTokens + " tokens to join the show."; self.sendNotice(msg, tip.from_user); } } else { // No entry fee. Check if the user has already used // their free period or is tipping to enter (again). if (typeof users[tip.from_user] !== "undefined") { var tipTotal = tipAmount + users[tip.from_user].tips; if (tipTotal < minTip) { msg = tip.from_user + ": You must tip " + (minTip - tipTotal) + " more tokens to re-join the show."; self.sendNotice(msg, tip.from_user); return; } } // New user so we can just add them user = self.addUser(tip.from_user, tip.from_user_is_mod, tip.from_user_in_fanclub, false); user.tips += tipAmount; user.entryPaid = true; } }, // Called when a message has been sent onMessage: function (msg) { // Is this a command? var parts = msg.m.split(" "); var hideMessage = true; if (parts[0] === "/start") { self.handleStart(msg); } else if (parts[0] === "/stop") { self.handleStop(msg); } else if (parts[0] === "/enter") { self.handleEnter(msg); } else if (parts[0] === "/allow") { self.handleAllow(msg); } else if (parts[0] === "/unallow") { self.handleUnallow(msg); } else if (parts[0] === "/remove") { self.handleRemove(msg); } else if (parts[0] === "/unremove") { self.handleUnremove(msg); } else if (parts[0] === "/list") { self.handleList(msg); } else if (parts[0] === "/stats") { self.handleStats(msg); } else if (parts[0] === "/reset") { hideMessage = true; } else if (parts[0] === "/check") { hideMessage = true; } else if (parts[0] === "/rules") { self.showRules(msg); } else if (parts[0] === "/help") { // Output the help self.showHelp(msg); } else { // Update mod/fan club member status in case somthing has // changed along the way if (typeof users[msg.user] !== "undefined") { users[msg.user].isMod = msg.is_mod; users[msg.user].isFan = msg.in_fanclub; } hideMessage = false; } if (hideMessage) { // Prevent the command from being output to chat msg['X-Spam'] = true; } return msg; }, // Try to shut things down when the broadcaster leaves onLeave: function (user) { if (user.user === cb.room_slug) { // The user and msg objects have the same properties so this is ok self.handleStop(user); } }, // For cases when the the show is restarted we want to reset the info for // all of the users currently in the cam list resetUsers: function () { var now = new Date().getTime(); var camUsers = cb.limitCam_allUsersWithAccess(); var camUser; for (var i = 0; i < camUsers.length; i++) { camUser = camUsers[i]; if (typeof users[camUser] !== "undefined") { users[camUser].startTime = now; } } }, // Handles the /start command. msg is the message object // passed in to onMessage. handleStart: function (msg) { if (msg.user === cb.room_slug && !cb.limitCam_isRunning()) { // Reset the user info if we're restarting // or people are already in the list if (cb.limitCam_allUsersWithAccess().length) { self.resetUsers(); } // Add the pre-configured "allow" list for (var i = 0; i < allowList.length; i++) { var username = allowList[i]; if (username.length) { self.addUser(username, false, false, true); var text = "Pre-configured VIP " + username + " added to the guest list"; self.sendInfo(text, cb.room_slug); } } // Start the hidden camera cb.limitCam_start(cb.settings.hiddenCamMessage); // Start the timer self.initTimer(); // Output the rules self.showRules(msg); } }, // Stops the hidden cam and cleans up as best we can handleStop: function (msg) { if (msg.user === cb.room_slug) { // Stop the hidden cam cb.limitCam_stop(); // Clear out the list var camUsers = cb.limitCam_allUsersWithAccess(); if (camUsers.length) { cb.limitCam_removeUsers(camUsers); } self.sendInfo(cb.room_slug + " has stopped the " + appName); } }, // Handles the "enter" command // Users are allowed to enter if: // 1. The user is exempt from limits (Mod, fan or specifically allowed by the broadcaster) OR // 2. There is no "minStartTokens" set AND // 3. They have not been in the show or there is still time remaining of their "free view" handleEnter: function (msg) { var text = ""; // If this is the broadcaster just ignore if (msg.user === cb.room_slug) { text = cb.room_slug + ": The /enter command is for viewers to enter. You should already be there ;)"; self.sendInfo(text, msg.user); return false; } // Has the user been explicitly removed? if (typeof users[msg.user] !== "undefined") { if (users[msg.user].isRemoved) { return false; } } // Is the user exempt from the limitations var isAllowed = false; if (self.isUserExempt(msg.user, msg.is_mod, msg.in_fanclub)) { if (typeof users[msg.user] !== "undefined") { isAllowed = users[msg.user].allowed; } self.addUser(msg.user, msg.is_mod, msg.in_fanclub, isAllowed); return true; } // Is this user already within limits (typed /enter several times)? if (typeof users[msg.user] !== "undefined") { if (self.isUserWithinLimits(users[msg.user])) { isAllowed = users[msg.user].allowed; cb.log("handleEnter: User " + msg.user + " exists and within limits. user.freePeriodOver: " + users[msg.user].freePeriodOver); self.addUser(msg.user, msg.is_mod, msg.in_fanclub, isAllowed); return true; } else if (minStartTokens > 0) { text = msg.user + ": You must tip " + minStartTokens + " tokens to join the show."; self.sendImportant(text, msg.user); return false; } else { text = msg.user + ": You must tip " + minTip + " tokens to join the show."; self.sendImportant(text, msg.user); return false; } } // Is there an entry fee? if (minStartTokens > 0) { text = msg.user + ": You must tip " + minStartTokens + " tokens to join the show."; self.sendImportant(text, msg.user); return false; } // Add the user if (typeof users[msg.user] !== "undefined") { isAllowed = users[msg.user].allowed; } self.addUser(msg.user, msg.is_mod, msg.in_fanclub, isAllowed); return true; }, // Handles the /allow command. This may only be issued by the broadcaster. handleAllow: function (msg) { if (msg.user === cb.room_slug) { var parts = msg.m.split(" "); // Should be a command followed by one or more usernames if (parts.length < 2) { var text = "The /allow command requires that you specify one or more usernames. For example:\n\n"; text += " /allow user1\n"; text += "OR\n"; text += " /allow user1 user2 user3\n"; self.sendInfo(text, cb.room_slug); return; } // Add the user as explicitly allowed var i; for (i = 1; i < parts.length; i++) { if (parts[i].length) { self.addUser(parts[i], false, false, true); self.sendNotice("User " + parts[i] + " explicitly allowed", cb.room_slug); self.sendNotice(parts[i] + ": You have been explicitly allowed by " + cb.room_slug, parts[i]); } } } }, // Handles the /allow command. This may only be issued by the broadcaster. handleUnallow: function (msg) { if (msg.user === cb.room_slug) { var parts = msg.m.split(" "); // Should be a command followed by one or more usernames if (parts.length < 2) { var text = "The /unallow command requires that you specify one or more usernames. For example:\n\n"; text += " /unallow user1\n"; text += "OR\n"; text += " /unallow user1 user2 user3\n"; self.sendInfo(text, cb.room_slug); return; } // Add the user as explicitly allowed var i; for (i = 1; i < parts.length; i++) { if (parts[i].length) { var username = parts[i]; if (typeof users[username] !== "undefined") { users[username].isAllowed = false; // Reset the time users[username].startTime = new Date().getTime(); self.sendNotice("User " + username + "'s 'allowed' exemption removed.", cb.room_slug); self.sendNotice(username + ": Your 'allowed' exemption has been removed by " + cb.room_slug); } } } } }, // Handles the /remove command. This may only be issued by the broadcaster. handleRemove: function (msg) { if (msg.user === cb.room_slug || msg.is_mod) { var parts = msg.m.split(" "); // Should be a command followed by one or more usernames if (parts.length < 2) { var text = "The /remove command requires that you specify one or more usernames. For example:\n\n"; text += " /remove user1\n"; text += "OR\n"; text += " /remove user1 user2 user3\n"; self.sendInfo(text, cb.room_slug); return; } // Remove the user(s) var i; for (i = 1; i < parts.length; i++) { if (parts[i].length) { self.removeUser(parts[i]); var msg = parts[i] + ": You have been explicitly removed from the show by " + msg.user; self.sendImportant(msg, parts[i]); self.sendImportant("User " + parts[i] + " explicitly removed"); } } } }, // Handles the /unremove command. This may only be issued by the broadcaster. handleUnremove: function (msg) { if (msg.user === cb.room_slug || msg.is_mod) { var parts = msg.m.split(" "); // Should be a command followed by one or more usernames if (parts.length < 2) { var text = "The /unremove command requires that you specify one or more usernames. For example:\n\n"; text += " /unremove user1\n"; text += "OR\n"; text += " /unremove user1 user2 user3\n"; self.sendInfo(text, cb.room_slug); return; } // Remove the user(s) var i; for (i = 1; i < parts.length; i++) { if (parts[i].length) { var username = parts[i]; if (typeof users[username] !== "undefined") { users[username].isRemoved = false; var msg = username + ": You have been explicitly \"unremoved\" and may now enter the show normally."; self.sendImportant(msg, username); self.sendImportant("User " + username + " explicitly unremoved"); } } } } }, // Lists users currently in the show handleList: function (msg) { if (msg.user === cb.room_slug) { if (cb.limitCam_isRunning()) { var text = "\nCurrent User List:\n\n"; var camUsers = cb.limitCam_allUsersWithAccess(); if (camUsers.length) { for (var i = 0; i < camUsers.length; i++) { text += camUsers[i] + "\n"; } self.sendInfo(text, msg.user); } else { self.sendInfo("No users currently in the show.", msg.user); } } else { self.sendInfo("The camera is not currently hidden.", msg.user); } } }, // Outputs information about users that are or have been in the show handleStats: function (msg) { if (msg.user === cb.room_slug) { var camUsers = cb.limitCam_allUsersWithAccess(); var line = ""; var text = lineDelimiter + "\n"; text += "User Stats:\n"; text += lineDelimiter + "\n"; //text += "User - Total Tokens - Mod - Fan - Allowed - Removed\n"; //text += lineDelimiter + "\n"; var userCol = 20, tokensCol = 12, i, tokens; for (user in users) { // if (cbjs.arrayContains(camUsers, username)) { var currentUser = users[user]; line = currentUser.username + ": "; /*for (i = currentUser.username.length; i < userCol; i++) { line += " "; }*/ tokens = (currentUser.totalTips + currentUser.tips); /*for (i = tokens.length; i < tokensCol; i++) { line += " "; }*/ line += tokens + " tokens"; line += (currentUser.isMod ? " Mod " : " "); line += (currentUser.isFan ? " Fan " : " "); line += (currentUser.isAllowed ? " Allowed " : " "); line += (currentUser.isRemoved ? " Removed " : " "); text += line + "\n"; } text += lineDelimiter; self.sendInfo(text, cb.room_slug); } }, // Adds a user to the internal structure and camera as needed. addUser: function (username, isMod, isFan, isAllowed) { if (typeof users[username] !== "undefined") { cb.log("addUser: User " + username + " exists"); // Update an existing user users[username].isMod = isMod; users[username].isFan = isFan; users[username].isAllowed = isAllowed; if (isAllowed) { // Explicitly allowed so remove any "removed" flag users[username].isRemoved = false; cb.log("addUser: User " + username + " is allowed"); } } else { // New user. Add to our internal data structure users[username] = self.createUser(username, isMod, isFan, isAllowed); cb.log("addUser: Creating user " + username); } // Check if we need to add them to the cam list if (!cb.limitCam_userHasAccess(username)) { // Add the user cb.limitCam_addUsers([username]); var msg = "User " + username + " entered the show"; self.sendEntered(msg); } return users[username]; }, // Removes a user removeUser: function (username) { // Update the internal structure if (typeof users[username] === "undefined") { // Not in the list but we want to put them there // so they can't get back in again var newUser = self.createUser(username, false, false, false); newUser.isRemoved = true; users[username] = newUser; } else { users[username].isAllowed = false; users[username].isRemoved = true; } // Check if we need to remove them to the cam list if (cb.limitCam_userHasAccess(username)) { // Remove the user cb.limitCam_removeUsers([username]); } }, // Creates and returns an internal user object createUser: function(username, isMod, isFan, isAllowed) { var now = new Date().getTime(); var newUser = { startTime: now, tips: 0, totalTips: 0, username: username, isMod: isMod, isFan: isFan, isAllowed: isAllowed, isRemoved: false, entryPaid: minStartTokens > 0 ? false : true, freePeriodOver: false }; return newUser; }, // Returns true if the user is exempt from the limitations isUserExempt: function (username, isMod, isFan) { // Check for explicit allow or remove if (typeof users[username] !== "undefined") { if (users[username].isRemoved) { return false; } if (users[username].isAllowed) { return true; } } else if (cbjs.arrayContains(allowList, username)) { // User doesn't yet exist but is in the guest list return true; } // Check for mod if (isMod && modsExempt) { return true; } // Check for fan if (isFan && fansExempt) { return true; } // Default to false return false; }, // Determines if the time interval has expired for this user hasTimeExpired: function (user) { // Get the current time var now = new Date().getTime(); // Calculate the elapsed time (in seconds) var elapsed = Math.round((now - user.startTime) / 1000); // And the interval in seconds if (elapsed > tipTimeInterval) { return true; } return false; }, // Checks if the user is within time limits and/or has tipped the // minimum amount. // user is our internal user object isUserWithinLimits: function (user) { if (typeof user !== "undefined") { if (!self.hasTimeExpired(user)) { // Time not yet expired so all good cb.log("isUserWithinLimits: " + user.username + ": Time not expired."); return true; } // Time has expired. Check the tip level if (user.tips >= minTip) { cb.log("isUserWithinLimits: " + user.username + ": User tipped at least the minimum."); return true; } // Is the user under "free view"? if (minStartTokens === 0) { if (user.freePeriodOver) { cb.log("isUserWithinLimits: " + user.username + ": No entry fee and free period over."); return false; } else { cb.log("isUserWithinLimits: " + user.username + ": No entry fee and free period NOT over."); return true; } } // Time not expired. Is there and and entry paid if (minStartTokens > 0) { if (user.entryPaid) { cb.log("isUserWithinLimits: " + user.username + ": Entry fee paid."); return true; } else { cb.log("isUserWithinLimits: " + user.username + ": Entry NOT fee paid."); return false; } } } // This should not be called with a non-existent user // so return false return false; }, // Returns true if the user is currently in the show. // A user is in the show if they are in the cam list and // there is an existing internal structure object for the user isInShow: function (username) { if (typeof users[username] === "undefined") { return false; } return cb.limitCam_userHasAccess(username); }, // Determines if the user is allowed to stay or not based on the time // and the amount of tips. user is our internal user object processUser: function(user) { // Check if user is exempt or the time has expired var now = new Date().getTime(); var msg; if (self.isUserExempt(user.username, user.isMod, user.isFan)) { // Just reset to keep track of totals, or if reason for exemption changes user.totalTips += user.tips; user.tips = 0; user.startTime = now; cb.log("processUser: " + user.username + ": User is exempt."); } else if (self.hasTimeExpired(user)) { cb.log("processUser: " + user.username + ": Time expired."); // Check if the user has tipped enough if (user.tips >= minTip) { // Yes so reset user.totalTips += user.tips; user.tips = 0; user.startTime = now; cb.log("processUser: " + user.username + ": Has tipped enough."); } else { cb.log("processUser: " + user.username + ": Not tipped enough. Removing from cam."); // Clear the latest tip, if any, so they can't just re-enter (when no entry fee) user.tips = 0; // Cut the user off if (cb.limitCam_userHasAccess(user.username)) { // Remove the user cb.limitCam_removeUsers([user.username]); } // Let them know what happened msg = user.username + ": You have been removed from the show for not tipping enough within the time limit."; msg += " You must tip " + minTip + " tokens to re-enter the show."; self.sendImportant(msg, user.username); // Tell the broadcaster msg = "User " + user.username + " removed for not making the minimum tip."; self.sendImportant(msg, cb.room_slug); } // Once time has expired the free period is over for good user.freePeriodOver = true; } else { // See if we need to remind the user to tip // We'll do this every 5 minutes, and every minute the last 5, but only if they haven't tipped enough yet // Calculate the remaining time (in seconds) var minutesRemaining = (Math.round(tipTimeInterval / 60) - Math.round((now - user.startTime) / 60000)); cb.log("processUser: " + user.username + ": Minutes remaining: " + minutesRemaining); var warnUser = false; var hardWarning = false; if (user.tips < minTip) { if ((tipTimeInterval / 60) === 5) { // 5 minute interval if (minutesRemaining < 5) { // Less than 5 minutes left warnUser = true; } } else if ((minutesRemaining % 5) === 0) { // Multiple of 5 minutes left warnUser = true; } else if (minutesRemaining < 5) { // Less than 5 minutes left warnUser = true; } cb.log("processUser: " + user.username + ": tipTimeInterval: " + tipTimeInterval + " minutesRemaining: " + minutesRemaining + " warnUser: " + warnUser); } else { cb.log("processUser: " + user.username + ": user.tips >= minTip: user.tips: " + user.tips + " minTip: " + minTip); } if (warnUser) { msg = user.username + ": You have "; if (minutesRemaining === 0) { msg += "less than 1 minute "; hardWarning = true; } else if (minutesRemaining === 1) { msg += "1 minute "; hardWarning = true; } else { msg += minutesRemaining + " minutes "; } msg += "to tip the remaining " + (minTip - user.tips) + " tokens."; var background = msgColors.notice.background, color = msgColors.notice.color, weight = msgColors.notice.weight; if (hardWarning) { msg += "\n Not tipping a minimum of " + minTip + " tokens "; msg += "within each " + (tipTimeInterval / 60) + " minute block will lead to you being removed from the show."; background = msgColors.warn.background; color = msgColors.warn.color; weight = msgColors.warn.weight; } cb.sendNotice(msg, user.username, background, color, weight); } } }, // Helper function to output the rules showRules: function (msg) { var intervalInMinutes = (tipTimeInterval / 60), output = lineDelimiter + "\n", showInProgress = cb.limitCam_isRunning(), outputToUser, internalOutput; output += cb.room_slug + "'s " + appName + " rules\n"; output += lineDelimiter + "\n\n"; if (showInProgress) { output += "The show is currently in progress :woohoo \n\n"; } if (minStartTokens !== 0) { if (showInProgress) { output += "To enter the show you must tip " + minStartTokens + " tokens\n"; } else { output += "Once the show has started you must tip " + minStartTokens + " tokens to enter the show.\n"; } } else { output += "Entry to the show is free.\n"; if (showInProgress) { output += "Type /enter to enter the show\n"; } else { output += "Once the show has started Type /enter to enter the show.\n"; } } if (minTip) { output += "To stay in the show, you must tip at least " + minTip + " tokens within each " + intervalInMinutes + " minute block.\n"; output += "If you do not tip the minimum amount within the time limit you will be removed from the show.\n"; output += "If removed, you may re-enter the show by tipping the minimum amount.\n"; if (minStartTokens !== 0) { output += "Your entry tip counts towards the first minimum tip.\n"; } } output += "\nType /help to see which commands are available to you\n"; if (typeof msg !== "undefined") { if (msg.user == cb.room_slug || msg.isMod) { // Explicitly asked for by the broadcaster or mod // so it should go to everyone. // But we want to output the setting in case they forgot :) internalOutput = self.getSettingsText(msg) + "\n"; } else { // Explicitly asked for by the user so send only to that user outputToUser = msg.user; } } // Output the rules output += lineDelimiter; self.sendInfo(output, outputToUser); // And special info if set if (typeof internalOutput !== "undefined") { self.sendInfo(internalOutput, msg.user); } }, // Helper function to output the help message // msg is the msg object received by onMessage showHelp: function (msg) { var isBroadcaster = msg.user == cb.room_slug ? true : false, intervalInMinutes = (tipTimeInterval / 60), text; text = lineDelimiter + "\n"; text += appName + " Help:\n"; text += lineDelimiter + "\n\n"; if (isBroadcaster || msg.is_mod) { text += "The " + appName + " bot allows you to charge an optional 'entry fee' to enter the show\n"; text += "and require users in the show to tip a minimum amount during regular time intervals\n"; text += "to stay in the show. And because this is a bot, you can run your favorite app during the show!\n\n"; text += self.getSettingsText(msg); text += "\n"; } else { if (minStartTokens) { text += "Tip " + minStartTokens + " tokens to enter the show.\n"; } else { text += "Enter the show by typing /enter.\n"; } text += "To stay in the show, you must tip at least " + minTip + " tokens within each " + intervalInMinutes + " minute block.\n"; text += "If you do not tip the minimum amount within the time limit you will be removed from the show.\n"; text += "If removed, you may re-enter the show by tipping the minimum amount.\n"; if (minStartTokens) { text += "Your entry tip counts towards the first minimum tip.\n"; } } text += "\n"; text += "Commands:\n"; text += "/rules Outputs the show rules\n"; text += "/help Outputs this message\n"; if (isBroadcaster) { text += "\nBroadcaster-only commands:\n\n"; text += "/start Starts the hidden camera show. Only users who pay the entry fee (if set)\n"; text += " and tip at least the minimum within every time block can view your camera.\n"; text += " ***IMPORTANT*** You MUST run the /start command to make the camera hidden.\n" text += "/stop Stops the hidden camera show. The room returns to normal, i.e. everybody in\n"; text += " the room can see your camera.\n"; text += " ***IMPORTANT*** You MUST run the /stop command to make your camera public again. This is a limitation of the CB limitCam api.\n"; text += "/allow <username> Allows a specific user to enter the show without the normal limitations\n"; text += " (entry tip, min tip.). Allow multiple users at once by typing their usernames\n"; text += " separated by a SPACE\n"; text += "/unallow <username> Removes the user from the 'allow list' and the normal limitations\n"; text += " (entry tip, min tip) will apply. Unallow multiple users at once by typing their usernames\n"; text += " separated by a SPACE\n"; text += "/list Lists all of the users currently in the show. This is only seen by the broadcaster.\n"; text += "/stats Outputs information about users who have been in the show. This is only seen by the broadcaster.\n"; } if (isBroadcaster || msg.is_mod) { text += "\nModerator commands:\n\n"; text += "/remove <username> Removes a specific user from the show. Removed users cannot enter again until you 'unremove' them\n"; text += " Removed users are only removed from the hidden cam show, and only as long as the bot is running.\n"; text += "/unremove <username> Removes the user from the 'removed list' and the normal limitations\n"; text += " (entry tip, min tip) will apply. Unremove multiple users at once by typing their usernames\n"; text += " separated by a SPACE\n"; } text += lineDelimiter; // Output the help self.sendInfo(text, msg.user); }, // Helper function to send a chat notice with specific colors sendInfo: function (text, username) { cb.sendNotice(text, username, msgColors.info.background, msgColors.info.color, msgColors.info.weight); }, // Helper function to send a chat notice with specific colors sendNotice: function (text, username) { cb.sendNotice(text, username, msgColors.notice.background, msgColors.notice.color, msgColors.notice.weight); }, // Helper function to send a chat notice with specific colors sendWarning: function (text, username) { cb.sendNotice(text, username, msgColors.warn.background, msgColors.warn.color, msgColors.warn.weight); }, // Helper function to send a chat notice with specific colors sendImportant: function (text, username) { cb.sendNotice(text, username, msgColors.important.background, msgColors.important.color, msgColors.important.weight); }, // Helper function to send a chat notice with specific colors sendEntered: function (text, username) { cb.sendNotice(text, username, msgColors.entered.background, msgColors.entered.color, msgColors.entered.weight); }, // Returns text describing the current bot settings getSettingsText: function (msg) { if (msg.user == cb.room_slug || msg.isMod) { // Explicitly asked for by the broadcaster or mod // so it should go to everyone. // But we want to output the setting in case they forgot :) var intervalInMinutes = (tipTimeInterval / 60); var text = "Current " + appName + " settings:\n\n"; text += "Min. Entry Tip: " + minStartTokens + " tokens\n"; text += "Tip Time Interval: " + intervalInMinutes + " minutes\n"; text += "Min. Tip per Interval: " + minTip + " tokens\n"; return text; } return ""; }, // Our "on timer" callback onTimer: function () { // If the cam is limited process the users if (cb.limitCam_isRunning()) { var camUsers = cb.limitCam_allUsersWithAccess(); for (var i = 0; i < camUsers.length; i++) { var camUser = camUsers[i]; cb.log("onTimer: Processing user " + camUser); if (typeof users[camUser] !== "undefined") { self.processUser(users[camUser]); } else { // Somebody in the cam list but not // in the internal data. Nothing much we can do but add them self.addUser(camUser, false, false, false); // Log it cb.log("onTimer: User " + camUser + " in camera list but not internal data. Adding."); } } } else { cb.log("onTimer: onTimer called when limitCam not running"); } // Reset the timer cb.setTimeout(self.onTimer, timerInterval); } }; }; // Create the app var theApp = new KeepItUpApp(); // Setup the broadcaster settings cb.settings_choices = theApp.getSettingChoices(); // Jack into the cb API // onLeave event cb.onLeave(function(user) { theApp.onLeave(user); }); // onTip event cb.onTip(function(tip) { theApp.onTip(tip); }); // onMessage event cb.onMessage(function(msg) { theApp.onMessage(msg); }); // Initialize the app theApp.init();
© Copyright Freesexcam 2011- 2024. All Rights Reserved.