Apps Home
|
Create an App
IvyWard Single Goal
Author:
ivyward
Description
Source Code
Launch App
Current Users
Created by:
Ivyward
cb.settings_choices = [ {name: 'goalAmount', type: 'int', required: true, label: 'Goal Amount'}, {name: 'goalDescription', type: 'str', required: true, label: 'Goal Description'}, {name: 'noticeDelay', type: 'int', defaultValue: 5, label: 'Notice Timer'}, {name: 'showLastTipper', type: 'choice', choice1: 'yes', choice2: 'no', defaultValue: 'yes', label: 'Show Last Tip'}, ]; const noticeDelay = cb.settings.noticeDelay; const goalDescription = cb.settings.goalDescription; const goalAmount = cb.settings.goalAmount; const showLastTipper = cb.settings.showLastTipper === 'yes' let tippedAmount = 0; let lastTipAmount = 0; let lastTipper = null; let timer = null; let goalReached = false; showNotice(); if(!goalReached && goalAmount){ cb.changeRoomSubject(`${goalDescription}`, false); // cb.changeRoomSubject(`${goalDescription} | Tokens Remaining: ${goalAmount}`, false); } cb.onTip(tip => { const amt = tip.amount; lastTipper = tip.from_user; lastTipAmount = amt; tippedAmount += amt; const remaining = goalAmount - tippedAmount; if(!goalReached && remaining <= 0){ goalReached = true; cb.sendNotice('Goal has been reached!', null, '#ffd700', null, 'bold'); cb.changeRoomSubject(`${goalDescription} | Goal Reached!`, false); } if(!goalReached){ // cb.changeRoomSubject(`${goalDescription} | Tokens Remaining: ${remaining}`, false); } cb.drawPanel(); }); cb.onMessage(msg => { const user = msg.user; const txt = msg.m; if(user === cb.room_slug){ switch(txt){ case '/total': cb.sendNotice(`Total Tipped: ${tippedAmount}`, cb.room_slug, null, null, 'bold'); msg['X-Spam'] = true; break; default: break; } } return msg; }); function showNotice(){ cb.sendNotice(goalDescription, null, '#E7C8C8', null, 'bold'); if(!goalReached){ timer = setTimeout(showNotice, noticeDelay * 60 * 1000); } } cb.onDrawPanel(user => { if(goalReached){ return { template: '3_rows_11_21_31', row1_value: 'Goal Reached!' }; } let amount = goalAmount - tippedAmount; const obj = { template: '3_rows_of_labels', row1_label: 'Tokens remaining: ', row1_value: `${amount}` }; if(showLastTipper && lastTipper){ obj.row2_label = 'Last tip: '; obj.row2_value = `${lastTipper} (${lastTipAmount})`; } return obj; });
© Copyright Freesexcam 2011- 2024. All Rights Reserved.