Bots Home
|
Create an App
lucky number
Author:
everlast_69
Description
Source Code
Launch Bot
Current Users
Created by:
Everlast_69
// vars /*jshint esversion: 6 */ var VERSION = '1.0.9.1'; var guessedNumbers = []; var winner = false; var amount; var strdash = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; var nl = '\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501'; var slugtimer = 2.5; var msg_prize; var guessNumber = 0; var minNumber = cb.settings.minNumber; var maxNumber = cb.settings.maxNumber; var prize = cb.settings.prize; var showNumber = true; var roomSubject = cb.settings.roomSubject; var tmguessboard = cb.settings.tmguessboard; var board = ''; cb.onTip(function (tip) { let found = false; if(winner != true){ if (tip.amount == guessNumber) { cb.chatNotice("\n" + strdash + "\n :woohoo \n You have guessed the Lucky number !!!\n " + tip.from_user + " wins " + prize); cb.chatNotice("Lucky Number: " + tip.amount + "\n" + strdash); let new_subject="Lucky Number FOUND: " + prize + roomSubject; cb.changeRoomSubject(new_subject); winner = true; } else { if (guessedNumbers.indexOf(tip.amount) < 0 && tip.amount <= maxNumber && tip.amount >= minNumber){ cb.chatNotice(strdash + "\nNot the lucky number - keep guessing\n" + strdash); guessedNumbers.push(tip.amount); guessedNumbers.sort(function(a,b){ return a-b; }); updateBoard(); } } } else { return; } } ); function update_subject(minNumber, maxNumber, prize, roomSubject) { let new_subject = roomSubject + "\n Lucky Guess Prize: " + prize; cb.changeRoomSubject(new_subject); } function msg_gamesubject(minNumber, maxNumber, prize) { let new_gs = "Lucky Guess from " + minNumber + " to " + maxNumber + " - Winning Prize: " + prize; msg_prize = new_gs; msg_send(null); } function msg_send(user){ if (user) { cb.sendNotice(msg_prize, user); } else { cb.sendNotice(msg_prize); } } function drawBoard(user) { if (user) { cb.sendNotice(board, user,'#16d9d2','#000000','bold'); } else { cb.sendNotice(board, '','#16d9d2','#000000','bold'); } } function pad(number, length) { let str = '' + number; while (str.length < length) { str = '0' + str; } return str; } function updateBoard() { let out = "Lucky Guess Board - Winning Prize: " + prize + "\n"; out += nl + '\n'; let mod = 10; let col = 1; if (maxNumber - minNumber > 100) mod = 15; for (let i = minNumber; i <= maxNumber; i++) { out += ' '; if (guessedNumbers.indexOf(i) < 0 ) { out += pad(i,2); } else { out += 'xx'; } out += ' '; if (col == mod) { out += '\n'; col = 1; } else { col++; } } if (out.substring(out.length - 1) != '\n') out += '\n'; out += nl; board = out; } /* function notify(message, u, bg, c, w) { if (bg == null) { bg = '#FFF'; } if (c == null) { c = '#000'; } if (w == null) { w = 'bold'; // leave at '' for normal } if (u == 'onlyMods') { cb.sendNotice(message,'',bg,c,w,'red'); } else if (u == 'roomHost') { cb.sendNotice(message,roomHost,bg,c,w); } else if (u == 'modsAndHost') { cb.sendNotice(message,'',bg,c,w,'red'); cb.sendNotice(message,roomHost,bg,c,w); } else if (u == null) { cb.sendNotice(message,'',bg,c,w); } else { cb.sendNotice(message,u,bg,c,w); } } */ cb.onMessage(function (msg) { var msgString = msg.m.trim(); var isCommand = msgString.charAt(0).match(/(\/|!)/gi); if (isCommand) { // Lucky Number Board if (msg.m.match(/(^|\s)(!|\/)b\b/i)) { if (msg.user == cb.room_slug || msg.is_mod) { cb.sendNotice('To send the board to the entire room, use //b or !!b', msg.user, '#FFCCCC', '#BB2222', 'bold'); } if (msg.user == cb.room_slug || msg.is_mod || msg.has_tokens) { msg.m += " (lucky number: board sent to " + msg.user + ")"; drawBoard(msg.user); } else { msg.m += " (lucky number: please buy tokens to play!)"; msg['X-Spam'] = true; } } if (msg.m.match(/(^|\s)(!!|\/\/)b\b/i)) { if (msg.user == cb.room_slug || msg.is_mod) { msg.m += " (lucky number: board sent to all)"; drawBoard(null); } } // Send lucky name title and Prize if (msg.m.match(/(^|\s)(!|\/)p\b/i)) { if (msg.user == cb.room_slug || msg.is_mod) { cb.sendNotice('To send the prize list to the entire room, use //p or !!p', msg.user, '#FFCCCC', '#BB2222', 'bold'); } if (msg.user == cb.room_slug || msg.is_mod || msg.has_tokens) { msg.m += " (lucky number: prize list sent to " + msg.user + ")"; msg_send(msg.user); } else { msg.m += " (lucky number: please buy tokens to play!)"; msg['X-Spam'] = true; } } if (msg.user == cb.room_slug || msg.is_mod) { msg.m += " (lucky number: prize list sent to all)"; msg_send(null); } } // Send Version if (msg.m.match(/(^|\s)(!|\/)version\b/i)) { cb.sendNotice(VERSION, msg.user); } return msg; } ); function setSettings(){ cb.settings_choices = [ { name:'minNumber', type:'int', minValue: 1, default: 10, label: "Lowest number to guess" }, { name:'maxNumber', type:'int', minValue: 16, default: 111, label: "Highest number to guess" }, { name:'guessNumber', type:'int', minValue: 0, default: 55, maxValue: 150, label: "Lucky Number to guess. 0 = generate random lucky number" }, { name: 'showNumber', type: 'choice', choice1: 'yes', choice2: 'no', default: 'yes', label: 'show broadcaster the random number?' }, { name:'prize', type:'str', label: "Prize to win" }, { name:'roomSubject', type:'str', label: "Add your Room Subject" }, { name:'tmguessboard', type:'int', minValue: 1, maxValue: 15, default: 5, label: "When to show number board (in minutes)" } ]; } function advert_game() { msg_gamesubject(minNumber, maxNumber, prize); cb.setTimeout(advert_game, (slugtimer * 60000)); } function advert_board() { updateBoard(); drawBoard(null); cb.setTimeout(advert_board, (tmguessboard * 50000)); } function getRandomIntInclusive(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; } function init() { setSettings(); if (cb.settings.guessNumber == 0) { guessNumber = getRandomIntInclusive(minNumber, maxNumber); if (showNumber) { cb.sendNotice ("ramdom Lucky Number is " + guessNumber, cb.room_slug,'#d91616','#ffffff','bold'); } } else { guessNumber = cb.settings.guessNumber; } if (minNumber <= maxNumber && guessNumber >= minNumber && guessNumber <= maxNumber) { update_subject(minNumber, maxNumber, prize, roomSubject); msg_gamesubject(minNumber, maxNumber, prize); updateBoard(); drawBoard(null); cb.setTimeout(advert_board, (tmguessboard * 50000)); cb.setTimeout(advert_game, (slugtimer * 60000)); } else { cb.sendNotice('ERROR: \nLowest number can\'t be bigger than Highest number,\nLucky Number must be between Lowest and Highest number,\nrestart the app and change the settings', cb.room_slug,'#ffffff','#d91616,'); } } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.