Bots Home
|
Create an App
Prepaid Secret Show
Author:
paintthegirlwithlove
Description
Source Code
Launch Bot
Current Users
Created by:
Paintthegirlwithlove
cb.settings_choices = [ {name: 'tokens_per_minute', type: 'int', minValue: 1, maxValue: 1000, defaultValue: 6, label: "Tokens per minute"} ]; var oneMinute = 60000; var userMinutesArr = {}; var tokensPerMinute = 0; cb.onTip(function(tip) { var user = tip['from_user']; var minutesBought = parseInt(parseInt(tip['amount']) / tokensPerMinute); if(minutesBought > 0) { addMinutes(user, minutesBought); cb.sendNotice(user + " bought " + minutesBought + " minutes in the secret show!", "", "#FFFF00", "#01DF01"); cb.sendNotice("You now have " + (userMinutesArr[user].MinutesLeft - 1) + " minutes of secret show viewing.", user); } else { cb.sendNotice("You did not tip enough tokens to purchase secret show minutes. Tip at least " + tokensPerMinute + " to gain access", user); } }); cb.onMessage(function (msg) { var message = msg['m']; var user = msg['user']; var username = ""; if (cb.room_slug === user && message == '/start' && !cb.limitCam_isRunning()) { startShow(); } if (cb.room_slug === user && message == '/stop' && cb.limitCam_isRunning()) { stopShow(); } if (cb.room_slug === user && message.substring(0, 7) == '/remove' && cb.limitCam_allUsersWithAccess().length > 0 && cb.limitCam_isRunning()) { username = message.substring(8, message.length); removeUser(username); cb.sendNotice(cb.room_slug + ' has removed ' + user + ' from the show.'); } if (cb.room_slug === user && message.substring(0, 6) == '/check') { username = message.substring(7, message.length); checkIfUserInShow(username); } if (cb.room_slug === user && message.substring(0, 19) == '/changeTokensPerMin') { tokens = message.substring(20, message.length); changeTokensPerMinute(tokens); } if (cb.room_slug === user && message === '/list') { listUsers(); } if (message[0] == '/') { msg['X-Spam'] = true; } return msg; }); function removeUser(user) { if (cbjs.arrayContains(cb.limitCam_allUsersWithAccess(), user)) { cb.limitCam_removeUsers([user]); delete userMinutesArr[user]; } } function refresh() { if(cb.limitCam_isRunning()) { for(var user in userMinutesArr) { userMinutesArr[user].MinutesLeft--; userMinutesArr[user].DecrementedSinceLastTip = true; if(userMinutesArr[user].MinutesLeft <= 0) { removeUser(user); cb.chatNotice("You have run out of minutes and been removed from the secret show.", user); cb.chatNotice(user + " ran out of minutes and has been removed", cb.room_slug); } else { if(userMinutesArr[user].MinutesLeft == 1) { cb.chatNotice("You only have one minute left! Tip a multiple of " + tokensPerMinute + " to continue viewing.", user); } else { cb.chatNotice("You have " + userMinutesArr[user].MinutesLeft + " minutes left to view the show.", user); } } } } cb.setTimeout(refresh, oneMinute); } function getHideMessage(_tokensPerMinute) { return "Secret show" + (cb.limitCam_isRunning()? " in progress" : "") + ". " + _tokensPerMinute + " tokens per minute. " + "Tip a multiple of " + _tokensPerMinute + " to gain access for tip/" + _tokensPerMinute + " minutes."; } function startShow() { cb.limitCam_start(getHideMessage(tokensPerMinute)); cb.sendNotice(getHideMessage(tokensPerMinute)); cb.sendNotice(cb.room_slug + ' has started the show!', "", "#FFFF00", "#FF4000"); } function stopShow() { cb.limitCam_stop(); cb.sendNotice(cb.room_slug + ' has stopped the show!', "", "#FFFF00", "#FF4000"); } function addMinutes(user, minutes) { if (!cbjs.arrayContains(cb.limitCam_allUsersWithAccess(), user)) { userMinutesArr[user] = { MinutesLeft: minutes + 1, DecrementedSinceLastTip: false }; cb.limitCam_addUsers([user]); cb.sendNotice('Added '+ user + ' to secret show!'); } else { if(userMinutesArr[user].DecrementedSinceLastTip) { userMinutesArr[user].MinutesLeft += minutes + 1; userMinutesArr[user].DecrementedSinceLastTip = false; } else { userMinutesArr[user].MinutesLeft += minutes; } } } function changeTokensPerMinute(tokens) { tokensPerMinute = parseInt(tokens); cb.sendNotice(cb.room_slug + " changed the tokens per minute rate to " + tokens + ".", "", "#FFFF00", "#FF4000"); cb.sendNotice(getHideMessage(tokensPerMinute)); cb.limitCam_stop(); cb.limitCam_start(getHideMessage(tokensPerMinute)); cb.sendNotice("Note that previously purchased minutes are still valid for this session.", cb.room_slug); } function checkIfUserInShow(username) { if (cb.limitCam_userHasAccess(username)) { cb.sendNotice(username + " is in the show."); } else { cb.sendNotice(username + " is not in the show."); } } function listUsers() { var userlist = cb.limitCam_allUsersWithAccess(); if (userlist.length > 0) { var userMinuteStr = "" + userlist.length + (userlist.length > 1 ? " users" : " user") + " in show: \n"; for(i in userlist) { var user = userlist[i]; var minutes = userMinutesArr[user].MinutesLeft - 1; if(minutes == 0) { userMinuteStr += user + ", less than 1 minute left."; } else { userMinuteStr += user + ", " + minutes + (minutes > 1 ? " minutes" : " minute") + " left\n"; } } cb.sendNotice(userMinuteStr, cb.room_slug); } else { cb.sendNotice("No users in show."); } } function init() { tokensPerMinute = parseInt(cb.settings.tokens_per_minute); cb.sendNotice(getHideMessage(tokensPerMinute)); cb.setTimeout(refresh, oneMinute); } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.