Bots Home
|
Create an App
RoboEric
Author:
testguy1234
Description
Source Code
Launch Bot
Current Users
Created by:
Testguy1234
// settings cb.settings_choices = [{ name: 'intro_message', type: 'str', minLength: 1, maxLength: 255, defaultValue: 'Tipguess game! Tip $minimum - $maximum to win a pink cocktail umbrella!', label: "Intro message ( /intro x )" },{ name: 'format', type: 'choice', choice1: 'Show available numbers', choice2: 'Show NOT numbers', choice3: 'Show whichever is shorter', defaultValue: 'Show NOT numbers', label: "Format" },{ name: 'format_ranges', type: 'choice', choice1: 'Yes', choice2: 'No', choice3: 'For NOT numbers only', choice4: 'No and also show opposite numbers as x', defaultValue: 'Yes', label: "Combine numbers into ranges" },{ name: 'minimum', type: 'int', minValue: 1, defaultValue: 1, label: "Minimum number ( /minimum x )" },{ name: 'maximum', type: 'int', minValue: 1, defaultValue: 23, label: "Maximum number ( /maximum x )" },{ name: 'win_message', type: 'str', minLength: 1, maxLength: 255, defaultValue: 'Congratulations $user! $lucky_number was the lucky number!', label: "Win message (empty to disable)" },{ name: 'chat_interval', type: 'int', minValue: 0, defaultValue: 40, label: "Automatically remind every X number of lines in chat (0 to disable)" }]; // hooks cb.onTip(function (tip) { check_lucky_number(tip); check_chat_interval(); }); cb.onMessage(function (msg) { if (msg.m.charAt(0) == '/') { msg['X-Spam'] = true; var components = msg.m.split(' '); switch (components[0]) { case '/minimum': if (msg['user'] != cb.room_slug) break; if (components.length < 2) break; var amount = components[1].replace(/\D/g,''); if (amount.length < 1) break; cb.settings.minimum = Number(amount); broadcaster_notice("Minimum changed (will take effect on next rollover)."); break; case '/maximum': if (msg['user'] != cb.room_slug) break; if (components.length < 2) break; var amount = components[1].replace(/\D/g,''); if (amount.length < 1) break; cb.settings.maximum = Number(amount); broadcaster_notice("Maximum changed (will take effect on next rollover)."); break; case '/rollover': if (msg['user'] != cb.room_slug) break; var lucky_number = Math.round(Math.random() * (cb.settings.maximum - cb.settings.minimum)) + cb.settings.minimum; if (components.length > 1) { var lucky_maybe = components[1].replace(/\D/g,''); if (lucky_maybe.length > 0) lucky_number = Number(lucky_maybe); } rollover(lucky_number); broadcaster_notice("Game started, lucky number is " + lucky_number); break; case '/intro': if (msg['user'] != cb.room_slug) break; if (components.length < 2) break; cb.settings.intro_message = components[1]; broadcaster_notice("Intro message changed."); break; case '/lucky_number': if (msg['user'] != cb.room_slug) break; broadcaster_notice("The lucky number is " + game.lucky_number); break; case '/numbers': notify_game_status(); break; } } else { check_chat_interval(); } return msg; }); // stuff function default_notice(msg, user) { if (user == undefined) user = ""; cb.chatNotice(msg, user, '#ffffff', '#FF1493'); } function broadcaster_notice(msg) { cb.chatNotice(msg, cb.room_slug, '#ffffff', '#CD5C5C'); } var chat_interval = 0; function check_chat_interval() { if (cb.settings.chat_interval == 0) return; chat_interval++; if (chat_interval > cb.settings.chat_interval) { chat_interval = 0; notify_game_status(); } } // game var game = { 'running' : false, 'minimum' : 0, 'maximum' : 0, 'lucky_number' : 0, 'guessed' : [] } function check_lucky_number(tip) { if (tip.amount > game.maximum) return; if (tip.amount < game.minimum) return; if (game.guessed.indexOf(tip.amount) == -1) game.guessed.push(tip.amount); if (tip.amount != game.lucky_number) return; game.running = false; if (cb.settings.win_message.length == 0) return; var msg = cb.settings.win_message.replace("$user", tip.from_user).replace("$lucky_number", game.lucky_number); default_notice(msg); } function rollover(lucky_number) { game.running = true; game.minimum = cb.settings.minimum; game.maximum = cb.settings.maximum; game.lucky_number = lucky_number; game.guessed = []; notify_game_status(); } function make_ranges(numbers) { numbers.sort( function(a,b) { return a-b; } ); var run = 0; for (var i = numbers.length - 1; i > 0; i--) { if (i > 1 && numbers[i] == numbers[i - 2] + 2 + run) { numbers[i - 1] = numbers[i]; numbers.splice(i, 1); run++; } else { if (run == 0) continue; numbers[i - 1] = numbers[i - 1] + " - " + numbers[i] numbers.splice(i, 1); i--; run = 0; } } return numbers; } function notify_game_status() { if (!game.running) return; // settings var show_available = cb.settings.format == 'Show available numbers'; if (cb.settings.format == 'Show whichever is shorter' && game.guessed.length > ((cb.settings.maximum - cb.settings.minimum) / 2)) show_available = true; var format_ranges = cb.settings.format_ranges == "Yes" || (cb.settings.format_ranges == "For NOT numbers only" && !show_available) // numbers var numbers = game.guessed; if (show_available) { numbers = []; for (var i = cb.settings.minimum; i <= cb.settings.maximum; i++) { if (game.guessed.indexOf(i) == -1) numbers.push(i); } } // construct string var numbers_str = show_available ? " Available: " : " NOT: "; if (cb.settings.format_ranges == 'No and also show opposite numbers as x') { for (var i = cb.settings.minimum; i <= cb.settings.maximum; i++) { if (numbers.indexOf(i) != -1) numbers_str += i + ", "; else numbers_str += "x, "; } numbers_str = numbers_str.substring(0, numbers_str.length - 2); } else if (numbers.length > 0) { if (format_ranges) numbers = make_ranges(numbers); numbers_str += numbers[0]; for (var i = 1; i < numbers.length; i++) { numbers_str += ", " + numbers[i]; } } else numbers_str = ""; // post var msg = cb.settings.intro_message.replace('$minimum', cb.settings.minimum).replace('$maximum', cb.settings.maximum) + numbers_str; default_notice(msg); chat_interval = 0; } // chat commands: /* /rollover x broadcaster only, x is the lucky number, if no x, a random lucky number will be selected /numbers shows the current game status /lucky_number broadcaster only, shows the current lucky number to broadcaster /minimum x broadcaster only, x is the minimum tip of the game /maximum x broadcaster only, x is the maximum tip of the game /intro x broadcaster only, x is the games introductory text */
© Copyright Chaturbate 2011- 2024. All Rights Reserved.