Bots Home
|
Create an App
Tip Bomb by: Mx2k6
Author:
daeva_reed
Description
Source Code
Launch Bot
Current Users
Created by:
Daeva_Reed
/* Name: Tip Bomb Author: mx2k6 Version History ============================================ v1.0 23/05/2014: First release v1.1 24/05/2014: Option to disable announcement when prize degrades Credits and Props ============================================ Suggestion credit: ashley93bad */ if (cb == null) { var cb = { changeRoomSubject: function(new_subject) {}, drawPanel: function() {}, log: function(message) {}, onDrawPanel: function(func) {}, onEnter: function(func) {}, onLeave: function(func) {}, onMessage: function(func) {}, onTip: function(func) {}, room_slug: '', sendNotice: function(message, to_user, background, foreground, weight, to_group) {}, setTimeout: function(func, msec) {}, settings_choices: [], settings: {}, tipOptions: function(func) {}, limitCam_start: function(message, allowed_users) {}, limitCam_stop: function() {}, limitCam_addUsers: function(allowed_users) {}, limitCam_removeUsers: function(removed_users) {}, limitCam_removeAllUsers: function() {}, limitCam_userHasAccess: function(user) {}, limitCam_allUsersWithAccess: function() {}, limitCam_isRunning: function() {}, }; } var TOTAL_PRIZES = 6; var prizeSettings = []; for (var gSetting = 1; gSetting <= TOTAL_PRIZES; gSetting++) { prizeSettings.push({ name: 'prize_' + gSetting + '_description', label: 'Prize ' + gSetting + ' Description', type: 'str', minLength: (gSetting === 1 ? 1 : 0), maxLength: 255, required: (gSetting === 1) }); prizeSettings.push({ name: 'prize_' + gSetting + '_expiry', label: 'Prize ' + gSetting + ' Expiry (minutes)', type: 'int', minValue: 1, defaultValue: 30, required: (gSetting === 1) }); } cb.settings_choices = [ { name: 'prize_tip_amount', label: 'Tip Required to win prize', type: 'int', minValue: 1, defaultValue: 1000 }, { name: 'require_exact_amount', label: 'Require Exact Amount to win', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No' }, { name: 'announce_prize_expiry', label: 'Announce prize expiration', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, ]; cb.settings_choices = prizeSettings.concat(cb.settings_choices); var Colours = { AliceBlue: "#F0F8FF", AntiqueWhite: "#FAEBD7", Aqua: "#00FFFF", Aquamarine: "#7FFFD4", Azure: "#F0FFFF", Beige: "#F5F5DC", Bisque: "#FFE4C4", Black: "#000000", BlanchedAlmond: "#FFEBCD", Blue: "#0000FF", BlueViolet: "#8A2BE2", Brown: "#A52A2A", BurlyWood: "#DEB887", CadetBlue: "#5F9EA0", Chartreuse: "#7FFF00", Chocolate: "#D2691E", Coral: "#FF7F50", CornflowerBlue: "#6495ED", Cornsilk: "#FFF8DC", Crimson: "#DC143C", Cyan: "#00FFFF", DarkBlue: "#00008B", DarkCyan: "#008B8B", DarkGoldenRod: "#B8860B", DarkGrey: "#A9A9A9", DarkGreen: "#006400", DarkKhaki: "#BDB76B", DarkMagenta: "#8B008B", DarkOliveGreen: "#556B2F", DarkOrange: "#FF8C00", DarkOrchid: "#9932CC", DarkRed: "#8B0000", DarkSalmon: "#E9967A", DarkSeaGreen: "#8FBC8F", DarkSlateBlue: "#483D8B", DarkSlateGrey: "#2F4F4F", DarkTurquoise: "#00CED1", DarkViolet: "#9400D3", DeepPink: "#FF1493", DeepSkyBlue: "#00BFFF", DimGrey: "#696969", DodgerBlue: "#1E90FF", FireBrick: "#B22222", FloralWhite: "#FFFAF0", ForestGreen: "#228B22", Fuschia: "#FF00FF", Gainsboro: "#DCDCDC", GhostWhite: "#F8F8FF", Gold: "#FFD700", GoldenRod: "#DAA520", Grey: "#808080", Green: "#008000", GreenYellow: "#ADFF2F", HoneyDew: "#F0FFF0", HotPink: "#FF69B4", IndianRed: "#CD5C5C", Indigo: "#4B0082", Ivory: "#FFFFF0", Khaki: "#F0E68C", Lavender: "#E6E6FA", LavenderBlush: "#FFF0F5", LawnGreen: "#7CFC00", LemonChiffon: "#FFFACD", LightBlue: "#ADD8E6", LightCoral: "#F08080", LightCyan: "#E0FFFF", LightGoldenRodYellow: "#FAFAD2", LightGrey: "#D3D3D3", LightGreen: "#90EE90", LightPink: "#FFB6C1", LightSalmon: "#FFA07A", LightSeaGreen: "#20B2AA", LightSkyBlue: "#87CEFA", LightSlateGrey: "#778899", LightSteelBlue: "#B0C4DE", LightYellow: "#FFFFE0", Lime: "#00FF00", LimeGreen: "#32CD32", Linen: "#FAF0E6", Magenta: "#FF00FF", Maroon: "#800000", MediumAquaMarine: "#66CDAA", MediumBlue: "#0000CD", MediumOrchid: "#BA55D3", MediumPurple: "#9370DB", MediumSeaGreen: "#3CB371", MediumSlateBlue: "#7B68EE", MediumSpringGreen: "#00FA9A", MediumTurquoise: "#48D1CC", MediumVioletRed: "#C71585", MidnightBlue: "#191970", MintCream: "#F5FFFA", MistyRose: "#FFE4E1", Moccasin: "#FFE4B5", NavajoWhite: "#FFDEAD", Navy: "#000080", OldLace: "#FDF5E6", Olive: "#808000", OliveDrab: "#6B8E23", Orange: "#FFA500", OrangeRed: "#FF4500", Orchid: "#DA70D6", PaleGoldenRod: "#EEE8AA", PaleGreen: "#98FB98", PaleTurquoise: "#AFEEEE", PaleVioletRed: "#DB7093", PapayaWhip: "#FFEFD5", PeachPuff: "#FFDAB9", Peru: "#CD853F", Pink: "#FFC0CB", Plum: "#DDA0DD", PowderBlue: "#B0E0E6", Purple: "#800080", Red: "#FF0000", RosyBrown: "#BC8F8F", RoyalBlue: "#4169E1", SaddleBrown: "#8B4513", Salmon: "#FA8072", SandyBrown: "#F4A460", SeaGreen: "#2E8B57", SeaShell: "#FFF5EE", Sienna: "#A0522D", Silver: "#C0C0C0", SkyBlue: "#87CEEB", SlateBlue: "#6A5ACD", SlateGrey: "#708090", Snow: "#FFFAFA", SpringGreen: "#00FF7F", SteelBlue: "#4682B4", Tan: "#D2B48C", Teal: "#008080", Thistle: "#D8BFD8", Tomato: "#FF6347", Turquoise: "#40E0D0", Violet: "#EE82EE", Wheat: "#F5DEB3", White: "#FFFFFF", WhiteSmoke: "#F5F5F5", Yellow: "#FFFF00", YellowGreen: "#9ACD32" }; var Groups = { TokenHolders: 'cyan', Tippers: 'blue', Fans: 'green', Moderators: 'red' }; var NotificationType = { Error: 'e', Warning: 'w', Success: 's', Information: 'i' }; var Messenger = { sendModeratorNotice: function(str) { this.sendGenericMessage(str, Colours.Blue, null, null, Groups.Moderators); }, sendErrorMessage: function(str, recipient, group) { this.sendGenericMessage(str, Colours.Red, null, recipient, group); }, sendWarningMessage: function(str, recipient, group) { this.sendGenericMessage(str, Colours.Orange, null, recipient, group); }, sendSuccessMessage: function(str, recipient, group) { this.sendGenericMessage(str, Colours.DarkGreen, null, recipient, group); }, sendInfoMessage: function(str, recipient, group) { this.sendGenericMessage(str, Colours.Black, null, recipient, group); }, sendGenericMessage: function(str, colour, background, recipient, group) { if (recipient != null && group != null) cb.sendNotice(str, recipient, '', colour, 'bold', ''); cb.sendNotice(str, recipient, background, colour, 'bold', group); }, }; String.prototype.format = function() { var newString = String(this); for (var idx = 0; idx < arguments.length; idx++) { newString = newString.replace('{' + idx + '}', arguments[idx]); } return String(newString); }; var Prize = function() { this.index = 0; this.description = ''; this.expiry = 0; this.won = false; this.onTimerExpired = function() { Application.Debugger.debugMessage("Timer for prize {0} finished".format(this.index)); if (this.won) { this.won = false; Messenger.sendSuccessMessage("Let's play again! Tip quickly to win this or an even better prize!", null, null); Application.Goal.setPrize(0); } else { if (Application.Goal.hasNextPrize()) { if (Application.Settings.announcePrizeExpiry) { Messenger.sendErrorMessage("Oh no! Prize {0} has been lost! Tip quickly to avoid missing out on the next prize!".format(this.description), null, null); } } else { Messenger.sendErrorMessage("Oh no! Prize {0} has been lost! Tip any amount to start the game over!".format(this.description), null, null); } Application.Goal.nextPrize(); } }; this.startTimer = function() { Application.Debugger.debugMessage("Timer for prize {0} started".format(this.index)); cb.setTimeout(function () { Application.Goal.getCurrentPrize().onTimerExpired(); }, this.expiry * 1000 * 60); }; }; var Application = { title: 'Tip Bomb', version: 1.1, Settings: { announcePrizeExpiry: true, interpret: function() { this.announcePrizeExpiry = (cb.settings.announce_prize_expiry == 'Yes'); Application.Goal.setRequireExactTip(cb.settings.require_exact_amount == 'Yes'); Application.Goal.setRequiredTipAmount(parseInt(cb.settings.prize_tip_amount)); for (var gIdx = 1; gIdx <= TOTAL_PRIZES; gIdx++) { if (cb.settings['prize_' + gIdx + '_description'] !== "" && parseInt(cb.settings['prize_' + gIdx + '_expiry']) !== 0) { Application.Goal.addPrize(cb.settings['prize_' + gIdx + '_description'], parseInt(cb.settings['prize_' + gIdx + '_expiry'])); } } Application.Goal.getCurrentPrize().startTimer(); } }, Debugger: { internal: { enabled: false, }, setDebugMode: function(enabled) { this.internal.enabled = enabled; }, getDebugMode: function() { return this.internal.enabled; }, debugMessage: function(msg) { if (!this.internal.enabled) return; cb.log("[{0}] {1}".format(new Date().toString(), msg)); }, }, Room: { internal: { subject: '', }, setSubject: function(subject) { subject = "Tip Bomb! {0}".format(subject); Application.Debugger.debugMessage("Room subject changing to: {0}".format(subject)); this.internal.subject = subject; cb.changeRoomSubject(this.internal.subject); }, getSubject: function() { return this.internal.subject; }, }, Goal: { internal: { highTipper: undefined, highTotal: 0, leaderboard: [], currentPrize: 0, prizes: [], requireExactTip: false, requiredTipAmount: 0, }, setRequiredTipAmount: function(tokens) { this.internal.requiredTipAmount = tokens; }, setRequireExactTip: function(required) { this.internal.requireExactTip = required; }, getRequiredTipAmount: function() { return this.internal.requiredTipAmount; }, getRequireExactTip: function() { return this.internal.requireExactTip; }, addPrize: function(description, expiry) { var prize = new Prize(); prize.index = Application.Goal.internal.prizes.length; prize.description = description; prize.expiry = expiry; Application.Debugger.debugMessage("New prize '{0}' with expiry '{1} minutes' created".format(prize.description, prize.expiry)); this.internal.prizes.push(prize); }, hasNextPrize: function() { return (this.internal.prizes[this.internal.currentPrize + 1] != null); }, getCurrentPrize: function() { return this.internal.prizes[this.internal.currentPrize]; }, validateTip: function(tokens) { if (this.internal.requireExactTip && tokens == this.internal.requiredTipAmount) return true; if (!this.internal.requireExactTip && tokens >= this.internal.requiredTipAmount) return true; return false; }, nextPrize: function() { this.setPrize(this.getPrize() + 1); }, getPrize: function() { return this.internal.currentPrize; }, setPrize: function(index) { this.internal.currentPrize = index; if (this.getCurrentPrize() != null) this.getCurrentPrize().startTimer(); }, addTip: function(username, tokens) { Application.Debugger.debugMessage("Tip of {0} received from {1}".format(tokens, username)); var isFound = false; for (var idx = 0; idx < this.internal.leaderboard.length; idx++) { if (this.internal.leaderboard[idx].name == username) { isFound = true; this.internal.leaderboard[idx].tokens += tokens; break; } } if (!isFound) { this.internal.leaderboard.push({ name: username, tokens: tokens }); } this.internal.leaderboard.sort(function(a, b) { return b.tokens - a.tokens; }); if (tokens > this.internal.highTotal) { this.internal.highTotal = tokens; this.internal.highTipper = username; } if (this.getCurrentPrize() != null) { if (this.validateTip(tokens)) { Messenger.sendSuccessMessage("Congratulations! {0} has tipped the correct amount to win {1}!".format(username, this.getCurrentPrize().description), null, null); this.getCurrentPrize().won = true; } else { if (this.internal.requireExactTip) { Messenger.sendErrorMessage("Sorry, but that wasn't the right amount to win the prize. Try {0}!".format(this.getRequiredTipAmount() > tokens ? "higher" : "lower"), username, null); } else { Messenger.sendErrorMessage("Sorry, but the magic number is higher than that. Keep trying!", username, null); } } } else { this.setPrize(0); Messenger.sendSuccessMessage("The game is now ON! Tip quickly to win prizes, the quicker the better!", null, null); } this.cachePanel(); }, getHighTipper: function() { return this.internal.highTipper; }, getHighTotalTipper: function() { return (this.internal.leaderboard.length > 0 ? this.internal.leaderboard[0].name : undefined); }, drawPanel: function() { return this.internal.panel; }, cachePanel: function() { Application.Debugger.debugMessage("Caching new panel"); this.internal.panel = { template: '3_rows_of_labels', row1_label: '', row1_value: '', row2_label: 'Highest Tip:', row2_value: '{0} ({1})'.format(formatUsername(this.getHighTipper()), (this.internal.highTotal == undefined ? '--' : this.internal.highTotal)), row3_label: '', row3_value: '' }; cb.drawPanel(); }, }, onStart: function() { return true; }, onTip: function(tip) { this.Goal.addTip(tip.from_user, tip.amount); return false; }, onMessage: function(message) { if (message.user == this.Goal.getHighTipper()) { message.background = Colours.PowderBlue; } if (message.user == this.Goal.getHighTotalTipper()) { message.background = Colours.SkyBlue; } return message; }, onEnter: function(username) { Messenger.sendInfoMessage("Welcome! This room is running Tip Bomb! Tip quickly for the best prizes - prizes get less valuable as time goes on!", username); return false; }, onLeave: function(username) { return false; }, onDrawPanel: function() { return this.Goal.drawPanel(); } }; function formatUsername(username) { if (username == undefined) { return "--"; } else { return username.substring(0, 12); } }; cb.onTip(function(tip) { if (!Application.onTip(tip)) return; }); cb.onMessage(function(message) { return Application.onMessage(message); }); cb.onEnter(function(username) { if (!Application.onEnter(username)) return; }); cb.onLeave(function(username) { if (!Application.onLeave(username)) return; }); cb.onDrawPanel(function() { return Application.onDrawPanel(); }); if (cb !== null && cb.settings !== null) { if (Application.onStart()) { if (cb.room_slug == 'mx2k6') Application.Debugger.setDebugMode(true); Application.Settings.interpret(); Application.Room.setSubject("Tip quickly to win the best prizes! The slower you go, the more you lose!"); Application.Goal.cachePanel(); Messenger.sendSuccessMessage("{0} v{1} has started. Tip quickly for the best prizes - prizes get less valuable as time goes on!".format(Application.title, Application.version)); } }
© Copyright Chaturbate 2011- 2026. All Rights Reserved.