Apps Home
|
Create an App
Bob's Mod
Author:
andrew121007
Description
Source Code
Launch App
Current Users
Created by:
Andrew121007
// changeable vars var subject = null; var superAdmin = null; var startWithTokens = 0; var showGoal = 2; var showHighestTipper = 'Yes'; var showLastTip = 'Yes'; var goal = 0; var keepCounting = 'Yes'; //private vars var totalTipped = 0; var totalTippedCapped = 0; var highestTip = 0; var highestTipUser = null; var lastTip = 0; var lastTipUser = null; cb.settings_choices = [{ name: 'subject', label: 'Subject/goal', type: 'str', minLength: 1, maxLength: 255 }, { name: 'superAdmin', label: '(Dangerous!) Super admin username. Comma formatted list', type: 'str', required: false }, { name: 'startWithTokens', label: 'Start with tokens', type: 'int', defaultValue: 0 }, { name: 'showGoal', label: 'How to show goal', type: 'choice', choice1: 'Only show total tips', choice2: 'Total tips / goal', choice3: 'Keep Blank', defaultValue: 'Total tips / goal' }, { name: 'showHighestTipper', label: 'Show Highest Tipper', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, { name: 'showLastTip', label: 'Show Last Tip', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, { name: 'goal', label: 'Goal (in tokens)', type: 'int', defaultValue: 0 }, { name: 'keepCounting', label: 'Keep counting tokens after goal', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No' }]; // handlers cb.onTip(function(tip) { totalTipped += tip['amount']; if (tipsRemaining() > 0) totalTippedCapped = goal; if (tip['amount'] > highestTip) { highestTip = tip['amount']; highestTipUser = tip['from_user']; } lastTip = tip['amount']; lastTipUser = tip['from_user']; cb.drawPanel(); }); cb.onDrawPanel(function(user) { var returnArray = null; var tipsReceived = ''; var tipsReceivedTotal = ''; var highestTipLabel = 'Highest Tip:'; var highestTipValue = formatUsername(highestTipUser) + ' (' + highestTip + ')'; var lastTipLabel = 'Latest Tip Received:'; var lastTipValue = formatUsername(lastTipUser) + ' (' + lastTip + ')'; if (showGoal === 1) { tipsReceived = 'Tip Received:'; tipsReceivedTotal = (keepCounting === 'Yes' ? totalTipped : totalTippedCapped); } else if (showGoal == 2) { tipsReceived = 'Tip Received/Goal:'; tipsReceivedTotal = (keepCounting === 'Yes' ? totalTipped : totalTippedCapped) + ' / ' + goal; } if (showGoal === 2 || showGoal === 1) { if (showHighestTipper === 'Yes' && showLastTip === 'Yes') { returnArray = {}; returnArray['template'] = '3_rows_of_labels'; returnArray['row1_label'] = tipsReceived; returnArray['row1_value'] = tipsReceivedTotal; returnArray['row2_label'] = highestTipLabel; returnArray['row2_value'] = highestTipValue; returnArray['row3_label'] = lastTipLabel; returnArray['row3_value'] = lastTipValue; } else if (showHighestTipper === 'No' && showLastTip === 'Yes') { returnArray = {}; returnArray['template'] = '3_rows_of_labels'; returnArray['row2_label'] = tipsReceived; returnArray['row2_value'] = tipsReceivedTotal; returnArray['row3_label'] = lastTipLabel; returnArray['row3_value'] = lastTipValue; } else if (showHighestTipper === 'Yes' && showLastTip === 'No') { returnArray = {}; returnArray['template'] = '3_rows_of_labels'; returnArray['row2_label'] = tipsReceived; returnArray['row2_value'] = tipsReceivedTotal; returnArray['row3_label'] = highestTipLabel; returnArray['row3_value'] = highestTipValue; } else if (showHighestTipper === 'No' && showLastTip === 'No') { returnArray = {}; returnArray['template'] = '3_rows_of_labels'; returnArray['row2_label'] = tipsReceived; returnArray['row2_value'] = tipsReceivedTotal; } } else { if (showHighestTipper === 'Yes' && showLastTip === 'Yes') { returnArray = {}; returnArray['template'] = '3_rows_of_labels'; returnArray['row2_label'] = highestTipLabel; returnArray['row2_value'] = highestTipValue; returnArray['row3_label'] = lastTipLabel; returnArray['row3_value'] = lastTipValue; } else if (showHighestTipper === 'No' && showLastTip === 'Yes') { returnArray = {}; returnArray['template'] = '3_rows_of_labels'; returnArray['row3_label'] = lastTipLabel; returnArray['row3_value'] = lastTipValue; } else if (showHighestTipper === 'Yes' && showLastTip === 'No') { returnArray = {}; returnArray['template'] = '3_rows_of_labels'; returnArray['row3_label'] = highestTipLabel; returnArray['row3_value'] = highestTipValue; } } return returnArray; }); cb.onMessage(function(e) { var message = e.m; var user = e.user; var isMod = e.is_mod; if (isMod && message.startsWith('\\/')) { //Command found var parameters = message.split(' '); var cmd = parameters[0]; if (parameters.length > 0) { e['X-Spam'] = true; switch (cmd) { case "/t": case "/topic": if (parameters.length < 2) { cb.sendNotice("Wrong usage: /t /topic topic_message", user); break; } cb.sendNotice(user + " changed the channel topic"); break; case "/sg": case "/setgoal": var usage = "Wrong usage: /sg /setgoal subject goalTokens [startWithTokens]"; if (parameters.length < 2) { cb.sendNotice(usage, user); break; } break; } } } return e; }); // helper functions /*function updateSubject(msg) { if (tips_remaining() == 0) { if (subject_is_set_with_0) { return; } subject_is_set_with_0 = true; } else { subject_is_set_with_0 = false; } var new_subject = cb.settings.goal_description + " [" + tips_remaining() + " tokens remaining]"; cb.log("Changing subject to: " + new_subject); cb.changeRoomSubject(msg); }*/ function tipsRemaining() { var r = goal - totalTipped; if (r < 0) { return 0; } else { return r; } } function formatUsername(val) { if (val === null) { return "--"; } else { return val.substring(0, 12); } } function init() { subject = cb.settings.subject; superAdmin = cb.settings.superAdmin == null || cb.settings.superAdmin == '' ? null : cb.settings.superAdmin.replace(/\s/g, '').split(','); startWithTokens = cb.settings.startWithTokens; showGoal = cb.settings.showGoal; if (showGoal === 'Only show total tips') showGoal = 1; else if (showGoal === 'Total tips / goal') showGoal = 2; showHighestTipper = cb.settings.showHighestTipper; showLastTip = cb.settings.showLastTip; goal = cb.settings.goal; keepCounting = cb.settings.keepCounting; cb.changeRoomSubject(subject); } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.