Apps Home
|
Create an App
Goody Bot
Author:
goodwood
Description
Source Code
Launch App
Current Users
Created by:
Goodwood
var scores = {} //scores, with the player uernames as keys var answers = {} //answers, with their sources as keys var answerusers = [] //an array of who answered for the purposes of keeping score var scoringusers = [] //an array of who gets points var scoreboard = [] var goldmedals = [] var silvermedals = [] var bronzemedals = [] cb.settings_choices = [ {name:'timer_length', type:'int', minValue:1, maxValue:120, defaultValue:30, label: "Timer length (in seconds)"}, {name:'mods_priv', type:'choice', choice1:'only the broadcaser', choice2:'broadcaster and mods', defaultValue:'only the broadcaster', label:'Who may use commands'}, {name:'keep_score', type:'choice', choice1:'yes', choice2:'no', defaultValue:'yes', label:'Use scorekeeping'} ]; cb.onMessage(function(msg){ // collect an answer if (msg['m'].startsWith('/a') || msg['m'].startsWith('/A')){ msg['X-Spam'] = true; answers[msg['user']] = msg['m'].substring(2); cb.sendNotice("Thank you for your answer!", msg['user'], '#000000', '#00FFFF', 'bold'); msg["m"] = "[You Answered: " + msg['m'].substring(2) + "]" return msg; }; //this part can only be done if you have bot privileges if (msg['user'] == cb.room_slug || (msg['is_mod'] && cb.settings.mod_priv == 'broadcaster and mods')){ // start timer if (msg['m'] == '/t'){ cb.sendNotice('Timer started! Remember to start your answer with /a', '', '#000000', '#00FFFF', 'bold'); cb.setTimeout(post_answers, (cb.settings.timer_length * 1000)); msg['m'] = '[Timer Started]' msg['X-Spam'] = true; return msg; }; // publish q and start timer if (msg['m'].startsWith('/q ')){ cb.sendNotice('Question: ' + msg['m'].substring(3), '', '#000000', '#00FFFF', 'bold'); cb.sendNotice('Timer started! Remember to start your answer with /a', '', '#000000', '#00FFFF', 'bold'); cb.setTimeout(post_answers, (cb.settings.timer_length * 1000)); msg['m'] = '[Question Sent]' msg['X-Spam'] = true; return msg; }; // score answers if (msg['m'].startsWith('/s')){ msg['X-Spam'] = true; scoringusers.length = 0; scoringusers = msg['m'].substring(3).split(' '); msg['m'] = "[Scored Answers: " + msg['m'].substring(3) + "]" var i; for (i = 0; i < scoringusers.length; i++){ //if it's a name if (isNaN(scoringusers[i])){ if (scores[scoringusers[i]] == 0 || scores[scoringusers[i]] == '' || scores[scoringusers[i]] == null) { scores[scoringusers[i]] = 1; } else { scores[scoringusers[i]]++ }; //if it's a number } else { if (scores[answerusers[scoringusers[i]-1]] == 0 || scores[answerusers[scoringusers[i]-1]] == '' || scores[answerusers[scoringusers[i]-1]] == null) { scores[answerusers[scoringusers[i]-1]] = 1; } else { scores[answerusers[scoringusers[i]-1]]++ }; }; }; post_scores(); answers = {} return msg; }; //remove scorer if (msg['m'].startsWith('/r')){ delete scores[msg['m'].substring(3)]; msg['m'] = "[Removed " + msg['m'].substring(3) + "]" post_scores(); return msg; }; //nobody got it right if (msg['m'] == '/c'){ msg['m'] = "[Answers Cleared]" post_scores(); answers = {}; return msg; }; // end the admin-only commands }; // Mark current winners with their place if (goldmedals.indexOf(msg['user']) != -1){ msg['m'] = ':goldGem ' + msg['m']; }; // Mark current winners with their place if (silvermedals.indexOf(msg['user']) != -1){ msg['m'] = ':silverGem ' + msg['m']; }; // Mark current winners with their place if (bronzemedals.indexOf(msg['user']) != -1){ msg['m'] = ':bronzeGem ' + msg['m']; }; }) function post_answers() { cb.sendNotice("Time's Up!", '', '#000000', '#00FFFF', 'bold'); answerusers = Object.keys(answers); if (answerusers.length == 0){cb.sendNotice('No Answers Submitted', '', '#000000', '#00FFFF', 'bold'); }; var i; for (i = 0; i < answerusers.length; i++){ cb.sendNotice((i + 1) + ') ' + answerusers[i] + ' says: ' + answers[answerusers[i]], '', '#000000', '#00FFFF', 'bold'); }; if (cb.settings.keep_score == 'no'){answers = {};}; } function post_scores() { scoreboard = [] if (Object.keys(scores).length > 0){ var i; for (const i in scores){ scoreboard.push([i, scores[i]]) }; scoreboard.sort(function(a, b){return b[1] - a[1]}); cb.sendNotice('CURRENT SCORES:', '', '#000000', '#00FFFF', 'bold') var i; for (i = 0; i < scoreboard.length; i++){ cb.sendNotice(scoreboard[i][0] + ' with ' + scoreboard[i][1] + ' points', '', '#000000', '#00FFFF', 'bold'); }; }; // --- award medals // do nothing if nobody has scored if (scoreboard == []){return}; goldmedals = [] silvermedals = [] bronzemedals = [] var medalsawarded = 0; var i = 0; while (medalsawarded <3 && i < scoreboard.length){ //auto-add whoever is in first if (i == 0){goldmedals.push(scoreboard[i][0]); i++; continue;} // increase medals count if not tied if (scoreboard[i][1] != scoreboard[i-1][1]){medalsawarded++;} if (medalsawarded == 0){goldmedals.push(scoreboard[i][0]);}; if (medalsawarded == 1){silvermedals.push(scoreboard[i][0]);}; if (medalsawarded == 2){bronzemedals.push(scoreboard[i][0]);}; i++; }; }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.