Bots Home
|
Create an App
pokerSirena
Author:
david692
Description
Source Code
Launch Bot
Current Users
Created by:
David692
/* jshint strict:false */ /* global cb */ var word = [], init = true, answerUsers = [], wrong = 0, finished = false, userKing = '', setWord = '', currentWord = '', crown = ':crown2', letters = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' ], cmds = ['word', 'setking', 'guess', 'answer', 'solve'], lastWinner = '', choices = [], winner = '', lastWords = [], wordbank = [], initWord,runCommand, tryLetter, rmKing, getWord = null; cb.settings_choices = [ {name:'goal', label:'What the winner gets (Goal)', type:'str', minLength: 2, maxLength: 25, required: true}, {name:'guessTokens', label:'Letter guess tokens', type:'int', minValue:1, maxValue:99999, default:25}, {name:'answerTokens', label:'Answer guess tokens', type:'int', minValue:1, maxValue:99999, default:50}, {name:'word', type:'str', minLength: 0, maxLength: 25, required: false}, {name:'randWord', label: 'Choose words for you?', type:'choice', choice1:'Yes', choice2:'No', default:'Yes'}, {name:'endWhen', label: 'Auto reset the game when the hangman dies?', type:'choice', choice1:'Yes', choice2:'No', default:'Yes'}, {name:'noticeTime', label:'Time between notices', type:'int', minValue: 30, maxValue: 300, required: true, default:30}, {name:'waitTime', label:'How long before choosing a new word after a round has finished in seconds?', type:'int', minValue:1, maxValue:60, default:5}, {name:'winnerIsKing', label: 'Allow the user who wins to choose the next word?', type:'choice', choice1:'Yes', choice2:'No', default:'No'}, {name:'modAsKing', label: 'Allow mods to choose the word?', type:'choice', choice1:'Yes', choice2:'No', default:'No'}, {name:'rmUsed', label: 'Remove used letters from selection?', type:'choice', choice1:'Yes', choice2:'No', default:'Yes'} ]; cb.tipOptions( function() { var options = [{label: 'Normal Tip'}]; if (!finished) { options.push({label: 'Solve Hangman (tip at least '+cb.settings.answerTokens+')'}); for (var i=0; i < choices.length; i++) { options.push({label:choices[i]}); } return {options:options, label:'Hangman Options (To guess a letter tip at least '+cb.settings.guessTokens+'):'}; } return {options:[{label: 'Normal Tip'}], label:'Game finished. New word will be choosen soon.'}; } ); cb.onTip( function(tip) { var fromUser = tip.from_user || ''; var tipAmount = tip.amount || -1; var answerTokens = cb.settings.answerTokens || 0; var guessTokens = cb.settings.guessTokens || 0; if (tip.message === 'Solve Hangman (tip at least '+answerTokens+')'){ var message = 'Incorect tip amount for answering so sent as just a normal tip.'; if (tipAmount >= answerTokens) { for (var i = 0; i < tipAmount/answerTokens; i++) { answerUsers[answerUsers.length] = fromUser; } message = fromUser+' you can now '; if (tipAmount === answerTokens) { message += 'try to answer by typing !solve a space then the word.'; } else { var guesses = tipAmount/answerTokens; message += 'guess the word '+guesses+' time(s) by typing'; message += ' !solve a space then the word.'; } } cb.chatNotice(message, fromUser); } else if (tip.message.length === 1 && tipAmount >= guessTokens) { if (setWord !== fromUser) { tryLetter(fromUser, tip.message); } else { cb.chatNotice('You can\'t guess for a word you set.', fromUser); } } else { cb.chatNotice('Incorect tip amount so sent as a normal tip.', fromUser); } } ); cb.onMessage( function (msg) { if (msg.m.trim().indexOf('!') === 0){ msg.m = msg.m.trim().toLowerCase(); var m = msg.m; var slug = cb.room_slug || ''; var modAsKing = cb.settings.modAsKing || 'No'; msg['X-Spam'] = true; if (msg.user === slug && m === '!rmking') { rmKing(); } else if (msg.user === slug && m.indexOf('!') === 0) { runCommand(m, msg.user); } else if (msg.user === userKing && m.indexOf('!word') === 0) { runCommand(m, msg.user); } else if (answerUsers.indexOf(msg.user) > -1 && m.indexOf('!solve') === 0 && setWord !== msg.user) { runCommand(m, msg.user); } else if (msg.is_mod === true && modAsKing === 'Yes' && m.indexOf('!word') === 0) { runCommand(m, msg.user); } else if (setWord === msg.user) { cb.chatNotice('You can\'t guess for a word you set.', msg.user); } else { cb.chatNotice('You need to tip to guess.', msg.user); } } return msg; } ); cb.onDrawPanel( function (user) { var wordDisplay = ''; wordDisplay = word.join().replace(/,+/g, ' '); if (!finished) { if (user === cb.room_slug) { return { 'template':'3_rows_11_21_31', 'row1_value':'Welcome to Hangman!', 'row2_value':'Word: '+wordDisplay+' ('+currentWord.replace(/\s+/g, ' ')+')', 'row3_value':'Last Winner: '+lastWinner }; } return { 'template':'3_rows_11_21_31', 'row1_value':'Welcome to Hangman!', 'row2_value':'Word: '+wordDisplay, 'row3_value':'Last Winner: '+lastWinner }; } return { 'template':'3_rows_11_21_31', 'row1_value':'Welcome to Hangman!', 'row2_value':'Word: '+wordDisplay, 'row3_value':'The winner is '+winner+'!' }; } ); var flashNotice = function() { var time = cb.settings.noticeTime || 30; cb.chatNotice('Hangman App is active! Tip to guess letters or the word!'); cb.setTimeout(flashNotice, time*1000); }; getWord = function() { var rnumber = Math.floor(Math.random()*1000); if (lastWords[0] === null || lastWords.indexOf(rnumber) === -1){ lastWords.push(rnumber); word = []; choices = letters; currentWord = wordbank[rnumber]; cb.log('New word:: '+currentWord); } else { return getWord(); } initWord(); }; var hangmanTag = function(stage) { switch (stage) { case 0: return ':hmapp0'; case 1: return ':hmapp1'; case 2: return ':hmapp2'; case 3: return ':hmapp3'; case 4: return ':hmapp4'; case 5: return ':hmapp5'; case 6: var endWhen = cb.settings.endWhen || 'Yes'; var waitTime = cb.settings.waitTime || 5; var randWord = cb.settings.randWord || 'Yes'; if (endWhen === 'Yes'){ finished = true; cb.chatNotice('Round Over'); if (randWord === 'Yes') { cb.setTimeout(getWord, waitTime*1000); } else { cb.chatNotice('The game was lost set a new word with !word and then the word.', cb.room_slug); } } return 'He\'s dead! :hmapp6'; default: return 'He\'s more dead! :hmapp6'; } }; initWord = function() { if (init) { var goal = cb.settings.goal || ''; var startWord = cb.settings.word || ''; cb.changeRoomSubject('Hangman App! Tip to guess letters or the word! Winner gets: ['+goal+']'); cb.chatNotice('Hangman App is active! Tip to guess letters or the word!'); currentWord = startWord.trim().toLowerCase(); var time = cb.settings.noticeTime || 30; cb.setTimeout(flashNotice, time*1000); init = false; } var randWord = cb.settings.randWord || 'Yes'; if (currentWord !== null && currentWord !== '') { for (var i=0; i < currentWord.length; i++) { if (currentWord[i] === ',' || currentWord[i] === ' ') { word[i] = ' | '; } else if (letters.indexOf(currentWord[i]) > -1) { word[i] = '_'; } else { word[i] = currentWord[i]; } } wrong = 0; finished = false; choices = JSON.parse(JSON.stringify(letters)); cb.drawPanel(); cb.chatNotice('A new word has been chosen! '+hangmanTag(wrong++)); } else if (randWord === 'Yes'){ getWord(); } else { cb.chatNotice('No word choosen word choosen for you.', cb.room_slug); getWord(); } }; var isCmd = function(cmd) { return (cmds.indexOf(cmd.replace('!','')) >-1); }; var getCmd = function(str) { var end = str.trim().indexOf(' '); cb.log('Found space at: ' + end); if (end > -1){ var cmd = str.substring(1, end).toLowerCase(); if (!isCmd(cmd)) { return 'noleadspaces'; } cb.log('cmd::' + cmd); return cmd; } return 'noleadspaces'; }; var getParam = function(str, cmd) { var params = str.trim().replace('!'+cmd+' ', ''); params = params.replace(/\s+/g, ',').replace(/,+/g, ','); cb.log('param::' + params); return params; }; var updateWord = function(letter) { for (var i=0; i < currentWord.length; i++){ if (currentWord.charAt(i) === letter) { word[i] = letter; } } if (word.indexOf('_') === -1) { finished = true; } cb.drawPanel(); }; tryLetter = function(user, letter) { var adj = 'incorrectly'; var rmUsed = cb.settings.rmUsed || 'Yes'; var m = ''; if (currentWord.indexOf(letter) > -1 && word.indexOf(letter) === -1){ updateWord(letter); adj = 'correctly'; } else { m = hangmanTag(wrong++); } if (rmUsed === 'Yes') { choices.splice(choices.indexOf(letter), 1); } cb.chatNotice(user+' has guessed the letter '+letter.toLowerCase().charAt(0)+' '+adj+'! ' + m); }; var setKing = function(user) { userKing = user; cb.chatNotice(user+' is now the Hangman king.'); var message = 'Hey, '+userKing+' '+cb.room_slug; message += ' has chosen you as the next hangman king.\n'; message += 'Type !word a space and then the word to choose the next word.'; cb.chatNotice(message, userKing); }; var checkAnswer = function(user, aword) { var adj = 'incorrectly'; var winnerIsKing = cb.settings.winnerIsKing || 'No'; var waitTime = cb.settings.waitTime || 5; var randWord = cb.settings.randWord || 'Yes'; var m = ''; if (!finished){ aword = aword.trim().toLowerCase().replace(/\s+/g, ',').replace(/,+/g, ' '); if (currentWord === aword) { word = currentWord.split(''); winner = user; finished = true; cb.drawPanel(); adj = 'correctly'; if (winnerIsKing === 'Yes') { setKing(user); } lastWinner = user; if (randWord === 'Yes') { cb.setTimeout(getWord, waitTime*1000); } else { var message = 'Hey '+user+' has guessed the word '+adj+'!\n'; message += 'You can change the word by typeing !word a space then the word.'; cb.chatNotice(message, cb.room_slug); } } else { m = hangmanTag(wrong++); } if (user !== cb.room_slug) { answerUsers.splice(answerUsers.indexOf(user), 1); } cb.chatNotice(user+' has guessed the word '+aword+' '+adj+'! '+m); } else { cb.chatNotice('The game is finished wait for a new word.', user); } }; var newWord = function(nword) { word = []; currentWord = nword; initWord(); }; runCommand = function(msg, user) { var cmd = getCmd(msg); if (cmd !== 'noleadspaces'){ var param = getParam(msg, cmd); if (cmd === 'word') { setWord = user; newWord(param); } else if (cmd === 'setking') { setKing(param); } else if (cmd === 'guess') { tryLetter(user, param); } else if (cmd === 'answer' || cmd === 'solve') { checkAnswer(user, param); } } else { cb.chatNotice('Place a space between the command and the word.', user); } }; rmKing = function() { cb.chatNotice('Hey, '+userKing+' you are no longer the hangman king.', userKing); userKing = null; }; wordbank = ['italy','tear','pottery','swing','trade','stamp','ego','guilt', 'fight','waterfall','tortoise','vinegar','herald','tshirt','mosquito','knife', 'cabbage','concert','flamenco','knitting','salt','draw','cancer','chips', 'reading','bar','coat','van','wagon','rumour','thief','hammer','manners', 'bacteria','graduate','rhinoceros','button','parent','well','juice','judo', 'pirate','bellows','university','laxative','rose','saint','lodger','croissant', 'trapeze','conductor','spring','parity','ball','sunburn','tourist','orange', 'creation','test','tragedy','toy','cashier','taxi','turf','entrance','forest', 'insult','night','seasick','reindeer','aquarium','chandelier','ears','anchor', 'college','wood','scarf','wheelbarrow','father','xray','waiter','pencil', 'spanner','lead','fare','general','lighthouse','calculator','wisdom','tower', 'aerial','bath','asylum','spoon','loom','jug','remedy','letterbox','puppy', 'bible','whale','news','bullet','whiteboard','cheat','ashes','soldier','neck', 'rash','amplifier','piano','training','comet','empire','prank','ant','needle', 'dove','pyjamas','kid','album','storm','snake','escape','aid','address','soccer', 'sponge','cellar','hygiene','novel','spire','typewriter','creeper','scar', 'bench','badge','fireman','limit','planning','cousin','giraffe','pudding', 'screen','scales','concierge','force','brakes','sausage','donkey','task', 'radar','artillery','switch','sugar','sex','lord','service','signature', 'creature','bin','coronet','mushroom','jump','buoy','carnival','shrimps', 'noise','note','tiger','vice','shoehorn','passion','flea','book','belt','formula','planet','genius','egg','bikini','ipad','shout','fleet','song','evil','loan','joke','minute','prison','estate','kite','toothpick','wallet','thermometer','poster','breath','lap','parrot','garden','artist','grade','spaghetti','zoo','emerald','fuck','accountant','bingle','boxing','travel','necklace','salmon','kangaroo','coffin','sparrow','shorts','ink','butterfly','bargain','queen','radiator','handbag','pyramid','crutch','stain','opera','parasite','end','surgeon','mermaid','crumbs','arrow','dice','ring','definition','family','wine','library','pocket','danger','catastrophe','plate','snow','invention','barber','flywheel','chimney','divorce','ransom','rebel','prize','pussy','ladder','sail','blonde','lunch','cord','horsepower','heretic','cupboard','slide','sofa','fridge','hope','commander','wolf','quarry','cereal','sandals','aluminium','beer','duty','flowerpot','hosepipe','stream','principal','bus','muscle','tissue','bed','offer','leaf','staple','snail','texas','nursery','courage','ladybird','bishop','bush','corporation','war','captain','choir','scream','nappy','kennel','chapel','fad','stool','comedy','toffee','crab','printer','voting','antique','map','pub','pharmacy','drug','inn','playground','brass','hand','concrete','funeral','fin','weather','leather','chair','grease','carriage','lodge','chisel','bandage','tape','bulb','dragon','carpet','school','factory','contract','hour','day','crown','egypt','flight','generator','binder','ice','tongue','robot','skin','waltz','leech','custard','warship','farm','pillow','help','hinge','chimp','hair','angel','torrent','locust','prince','monster','research','statue','morals','ballroom','beach','practice','loaf','pincer','market','spaceship','china','messenger','dance','velcro','picture','calm','aroma','thermostat','brooch','string','rollercoaster','software','ridge','singer','panther','denim','lane','shark','icon','cherry','wig','pimple','spider','indian','pain','bib','stardom','pear','fuse','razor','election','bacon','fork','orchestra','photograph','ambiguous','toast','verb','comic','napkin','seagull','milkshake','lipstick','tornado','sunrise','cave','navel','vase','lighter','blame','fire','octopus','ferry','paradise','bowl','staff','salon','computer','satellite','decorator','gloves','silo','bill','bubble','fax','music','swimming','perch','sunset','iceberg','fairy','marble','headache','barrier','fatigue','promotion','mind','shop','climbing','injury','chart','wave','galaxy','mirror','plastic','snore','dish','bridge','dusk','guitar','vowel','brick','tapestry','loop','mite','scallop','toes','dynamo','friar','riot','volcano','baby','dodgem','pastry','microbe','sermon','sole','telescope','pie','morning','nile','ravioli','parade','essay','party','gears','cap','summer','pin','migraine','mouse','grasshopper','epidemic','eyebrow','peace','lift','spinach','referee','hardware','elastic','space','store','pasta','gondola','wind','report','tablet','station','fungus','law','lunatic','press','compass','balcony','fact','noun','scandal','oyster','sentry','ham','cowboy','parachute','section','cucumber','hostpital','florist','figure','toothbrush','shoes','horseshoe','alphabet','observation','mattress','mole','race','mill','gossip','carpenter','jet','mound','ginger','tap','blister','flag','frown','lobster','decoy','India','basket','trap','cider','lemon','ketchup','doctrine','mask','turtle','pension','curtain','envelope','politician','tax','tomb','skyscraper','skirt','star','straw','grass','pride','architect','colony','fish','ceiling','clay','board','ostrich','pumpkin','moustache','religion','cuff','berry','parliament','attack','summit','spade','vote','hooligan','fair','prairie','gown','arm','video','basin','satan','park','sneeze','dentist','oar','jacket','laser','magician','nanny','dolphin','flood','cape','chameleon','frock','rain','curlers','pankake','joy','mint','cloak','tray','scarecrow','stampede','skateboard','herb','crowd','cube','hymn','key','chess','graffiti','square','radio','scorpion','saxophone','mat','barrel','hook','cry','union','miser','corn','stars','bullfight','silence','word','crisis','birthday','shooting','butter','rib','motorcycle','duck','paranoia','schedule','Russia','chain','log','island','moth','target','comb','flirt','bully','pigeon','president','powder','poker','nail','crisps','winner','glasses','revenge','cloud','synthetic','plaster','faint','gamble','lentil','hamburger','tank','screwdriver','bow','kidney','novice','pepper','cheese','stew','galvanise','crust','reason','sunglasses','search','plane','composer','title','profit','spy','paw','vitamins','socks','licence','scissors','finger','colour','chime','jealousy','newspaper','policeman','pilot','altar','cult','advertising','hospital','shoelace','legs','saddle','file','refugee','conference','rank','pail','letter','arithmetic','ski','junk','interlude','dictionary','midwife','trailer','frog','reciept','finance','flashbulb','drum','tusk','consonant','justice','package','price','zip','luggage','carrot','cafe','nun','film','cook','encyclopedia','soap','second','bead','tour','gym','fever','snack','rhythm','massage','earth','value','certificate','whisky','aplause','pebble','souvenir','pen','model','gnome','stone','poverty','cactus','harp','feast','hobby','gutter','diary','diver','magazine','beggar','beans','spacestation','muslim','bridle','salad','wardrobe','honey','mellon','power','garlic','potato','satire','saucer','crystal','roulette','work','bingo','tie','fan','cup','cripple','hanger','porridge','gang','coal','mime','ticket','flesh','bee','sow','slut','seat','smile','lollipop','spine','runway','nose','digging','judge','blood','sheet','peacock','bandit','drinking','manure','rudder','cot','bundle','exam','manhole','slipper','alarm','motel','caterpillar','prejudice','prophet','gallery','cocktail','suicide','parlour','binge','game','eagle','widow','desert','pliers','crane','internet','seal','saviour','referendum','kiosk','beard','teacher','bank','threat','mustard','cow','goal','stage','baton','shampoo','tv','surface','foam','cabin','survey','olympics','holiday','telephone','shopping','code','dinner','puppet','bomb','lamp','result','skylight','increments','roses','consumer','tonic','cat','church','kidnap','trellis','reject','cream','net','kitchen','elephant','lemonade','granny','cough','shirt','corner','engineer','sea','error','shelf','legend','termite','reward','stiletto','pillar','sword','tears','seed','jury','caper','leg','rubbish','padlock','sardine','foundation','pants','tennis','holly','tail','escalator','miner','iron','golf','tart','fertiliser','seesaw','dock','bell','mile','capital','sack','turkey','algae','haystack','violin','perfume','graph','boots','sailor','microphone','chocolate','label','cartridge','chimpanzee','menu','shape','tartan','myth','tattoo','worm','applause','nuts','memory','plug','psychiatrist','door','tram','cliff','loft','spar','headline','witch','bait','energy','guide','sale','parish','doughnut','daisy','moon','sky','cannon','sanity','cork','crash','fall','stomach','hazard','king','fountain','oil','monkey','band','nib','arch','lump','angle','mutton','leisure','copier','guillotine','sedative','safe','republic','hostage','cemetery','accident','exile','arthritis','paddock','cottage','giant','blanket','rescue','verse','coffee','midget','river','passport','stadium','tractor','chicken']; initWord();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.