Bots Home
|
Create an App
Welp
Author:
spaceball3
Description
Source Code
Launch Bot
Current Users
Created by:
Spaceball3
/*------------SETTINGS------------*/ //initial settings cb.settings_choices = [ {name: 'commanders', label: 'Users who can use commands', type: 'str', defaultValue: 'codeanon', required: false}, {name: 'roomfgcolor', label: '[SETTINGS] -------------------------------- Room notice font color', type: 'str', defaultValue: '#000000'}, {name: 'roombgcolor', label: 'Room notice background color', type: 'str', defaultValue: '#FFFFFF'}, {name: 'milestone_bradcast_delay', label: 'Interval (in minutes) to display offerings to chat room.', type: 'int', defaultValue: 5}, {name: 'goal_name', label: 'Goal Title', type: 'str', defaultValue: 'goal'}, {name: 'goal_amt', label: 'Tokens Per Goal', type: 'int', defaultValue: '15'}, {name: 'goal_msg', label: 'Message when goal reached', type: 'str', defaultValue: 'The mother of dragons thanks you.'}, {name: 'adv', label: 'Special advertisement', type: 'str', required: false}, {name: 'mst1_val', label: '[MILESTONES] -------------------------------- Milestone 1 - Name', type: 'str', required: false, defaultValue: 'shirt off'}, {name: 'mst1_num', label: 'Milestone 1 - Goals Needed', type: 'int', required: false, defaultValue: 20}, {name: 'mst2_val', label: 'Milestone 2 - Name', type: 'str', required: false, defaultValue: 'bra off'}, {name: 'mst2_num', label: 'Milestone 2 - Goals Needed', type: 'int', required: false, defaultValue: 40}, {name: 'mst3_val', label: 'Milestone 3 - Name', type: 'str', required: false, defaultValue: 'pants off'}, {name: 'mst3_num', label: 'Milestone 3 - Goals Needed', type: 'int', required: false, defaultValue: 60}, {name: 'mst4_val', label: 'Milestone 4 - Name', type: 'str', required: false, defaultValue: 'totally naked'}, {name: 'mst4_num', label: 'Milestone 4 - Goals Needed', type: 'int', required: false, defaultValue: 80}, {name: 'mst5_val', label: 'Milestone 5 - Name', type: 'str', required: false, defaultValue: 'cum show'}, {name: 'mst5_num', label: 'Milestone 5 - Goals Needed', type: 'int', required: false, defaultValue: 100} ]; /********** ------------ DECLARATIONS ------------ **********/ var tipCount = 0; var goalCount = 0; var goalTimer = 0; ///////////////////// var milestones = function () { var arr = []; function makeMilestone(num, val) { if (num && val) { if (num <= goalCount) { tellBoth('ERROR: Cannot add a milestone at a number already passed'); } else { arr.push({'number': num, 'value': val}); } } } makeMilestone(cb.settings.mst1_num, cb.settings.mst1_val); makeMilestone(cb.settings.mst2_num, cb.settings.mst2_val); makeMilestone(cb.settings.mst3_num, cb.settings.mst3_val); makeMilestone(cb.settings.mst4_num, cb.settings.mst4_val); makeMilestone(cb.settings.mst5_num, cb.settings.mst5_val); arr.sort(function (a, b) { return parseInt(b.number) - parseInt(a.number); }); return arr; }(); var mscount = milestones.length; ///////////////////// ///////////////////// var commanders = function () { var arr = []; if (cb.settings.commanders) { arr = cb.settings.commanders.split(','); for (var i = 0; i < arr.length; i++) { arr[i] = arr[i].trim(); } } return arr; }(); ///////////////////// ///////////////////// var advertisement = function () { if (cb.settings.adv) return ' | ' + cb.settings.adv.trim(); return ''; }(); ///////////////////// /********** ------------ PANEL ------------ **********/ //app panel format cb.onDrawPanel(function () { return { 'template': '3_rows_12_22_31', 'row1_label': 'NEXT ' + cb.settings.goal_name.toUpperCase() + ':', 'row1_value': tipCount % cb.settings.goal_amt + '/' + cb.settings.goal_amt, 'row2_label': 'TOTAL ' + cb.settings.goal_name.toUpperCase() + 'S:', 'row2_value': goalCount + ' (' + tipCount + ' tokens)', 'row3_value': goalLastReached() }; }); function getMinutes () { return Math.floor(goalTimer/60); } function goalLastReached () { var min = getMinutes(); if (goalCount > 0) return capitalizeFirstLetter(cb.settings.goal_name) + ' reached ' + min + ' minute' + plural(min) + ' ago'; return 'Goal has not been reached yet!'; } function checkGoalTimer() { var oldMinutes = getMinutes(); goalTimer = goalTimer + 5; var newMinutes = getMinutes(); if (newMinutes > oldMinutes) { cb.drawPanel(); } cb.setTimeout(checkGoalTimer, 5000); } /********** ------------ TIPS ------------ **********/ cb.onTip(function(tip) { tipCount += tip.amount; calcGoal(); cb.drawPanel(); }); function calcGoal() { var oldGoalCount = goalCount; goalCount = Math.floor(tipCount / cb.settings.goal_amt); if (goalCount > oldGoalCount) { goalTimer = 0; var output = '\u2605 \u2605 \u2605 ' + cb.settings.goal_name + ' has been reached ' + plural(goalCount) + ' time' + plural + '! \u2605 \u2605 \u2605'; cb.sendNotice(output, '', cb.settings.roombgcolor, cb.settings.roomfgcolor, 'bold', ''); calcMilestone(); } } function calcMilestone() { cb.log('GOALS: ' + goalCount); for (var i = 1; i < milestones.length + 1; i++) { cb.log('Checking milestone ' + (i - 1) + '...'); if (goalCount >= milestones[i - 1].number) { cb.log('Milestone passed: ' + i); if (mscount !== i - 1) { mscount = i - 1; milestoneReached(); } break; } } } /********** ------------ MILESTONES ------------ **********/ function milestoneReached() { if (mscount === 0) { cb.changeRoomSubject(milestones[mscount].value + '! | ' + cb.settings.adv); } else { cb.changeRoomSubject(milestones[mscount - 1].value + ' at ' + milestones[mscount - 1].number + ' ' + cb.settings.goal_name + 's!' + advertisement); } } function sortMilestones() { milestones.sort(function (a, b) { return parseInt(b.number) - parseInt(a.number); }); } function showMilestones() { var output = ''; for (var i = milestones.length - 1; i > -1; i--) { if (milestones[i].number > goalCount) { output += '\n' + milestones[i].value + ' at ' + milestones[i].number + ' ' + cb.settings.goal_name + 's!'; } } tellUser(output.trim()); } function autoBroadcastMilestones() { showMilestones(); cb.setTimeout(autoBroadcastMilestones, (cb.settings.milestone_bradcast_delay * 60000)); } /********** ------------ COMMUNICATION ------------ **********/ //send a notification to a user (leave blank for entire room) function tellUser(msg, user) { cb.sendNotice(newLines(msg), user, cb.settings.roombgcolor, cb.settings.roomfgcolor, 'bold', ''); } //send a notification to the broadcaster only function tellMe(msg) { cb.sendNotice(newLines(msg), cb.room_slug, cb.settings.roombgcolor, cb.settings.roomfgcolor, 'bold', ''); } //send a notification to mods only function tellMods(msg) { cb.sendNotice(newLines(msg), '', cb.settings.roombgcolor, cb.settings.roomfgcolor, 'bold', 'red'); } //send a notification to the broadcaster and mods function tellBoth(msg) { tellMe(msg); tellMods(msg); } /********** ------------ MISCELLANEOUS ------------ **********/ function newLines(input) { return '\u25CF ' + input.replace(new RegExp('\n', 'g'), '\n\u25CF '); } function plural(n) { if (n === 1) return ''; return 's'; } function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } /********** ------------ COMMANDS ------------ **********/ cb.onMessage(function (msg) { if (msg['m'].charAt(0) === '/' && isCommander(msg['user'])) { cmd(msg); msg['X-Spam'] = true; } return msg; }); function isCommander(user) { return commanders.indexOf(user) > -1 || user === cb.room_slug; } function cmd(msg) { var text = msg.m.substring(1).split(' '); switch (text[0]) { case 'mod_tipcount': setTipCount(text[1]); break; case 'mod_add': addMilestone(paramString(msg.m)); break; case 'mod_rem': removeMilestone(text[1]); break; case 'mod#': evaluate(paramString(msg.m), msg.user); break; } } function addMilestone(input) { var text = input.split(' '); var num = Number(text[0]); text.splice(0, 1); var val = text.join(' '); if (num && !isNaN(num) && val && val.length > 0) { removeMilestone(num); milestones.push({number: num, value: val}); mscount = milestones.length; sortMilestones(); calcMilestone(); milestoneReached(); cb.drawPanel(); tellBoth('New milestone successfully added.'); } } function removeMilestone(input) { if (input && !isNaN(Number(input))) { cb.log('removing'); var num = Number(input); for (var i = 0; i < milestones.length; i++) { if (milestones[i].number === num) { milestones.splice(i, 1); mscount = milestones.length; sortMilestones(); calcMilestone(); milestoneReached(); cb.drawPanel(); tellBoth('Milestone successfully removed.'); break; } } } } function evaluate(input, user) { if (input) { cb.setTimeout(function () { var command = paramString(input); try {eval(command)} catch (e) {tellUser('JS-ERR :: ' + e.message, user, '#CC0000')} }, 150); } } function paramString(input, stringToIndex) { cb.log('Geting paramString...'); if (input) { if (!stringToIndex) { return input.substring(input.indexOf(' ') + 1); } else { return input.substring(input.indexOf(stringToIndex) + stringToIndex.length + 1); } } return void 0; } /********** ------------ EXECUTE ------------ **********/ (function () { var ms = milestones[milestones.length - 1]; if (ms) cb.changeRoomSubject(ms.value + ' at ' + ms.number + ' ' + cb.settings.goal_name + 's!' + advertisement); autoBroadcastMilestones(); cb.setTimeout(checkGoalTimer, 5000); })();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.