Bots Home
|
Create an App
Tip Totals
Author:
chilledge
Description
Source Code
Launch Bot
Current Users
Created by:
Chilledge
let totalTipped = 0; let allTips = []; const noticeColor = '#e4adeb'; const getHighestTotalTipper = (tips) => { const byTipper = tips.reduce((totals, { amount, user }) => { if (!totals[user]) { totals[user] = 0; } totals[user] += amount; return totals; }, {}); const highestTipper = { amount: 0, user: 'no one' }; Object.keys(byTipper).forEach((user) => { const amount = byTipper[user]; if (amount > highestTipper.amount) { highestTipper.amount = amount; highestTipper.user = user; } }); return highestTipper; }; const getLargestIndividualTip = (tips) => { return tips.reduce(function(tip, total) { if (tip.amount > total.amount) { return tip; } return total; }, { amount: 0, user: 'no one' }); }; cb.onTip(function(tip) { const amount = parseInt(tip.amount, 10); totalTipped += amount; allTips.push({ amount: amount, user: tip.from_user }); }); cb.onMessage(function(msg) { if (msg.m.indexOf('/tipstats') === 0) { msg['X-Spam'] = true; if (!msg.is_mod && !msg.user === cb.room_slug) { return msg; } if (totalTipped === 0) { cb.sendNotice('No tips yet', msg.user, noticeColor); return msg; } const highestTotalTipper = getHighestTotalTipper(allTips); const largestIndividual = getLargestIndividualTip(allTips) const notice = [ `Highest overall tipper: ${highestTotalTipper.user} (${highestTotalTipper.amount})`, `Largest single tip: ${largestIndividual.user} (${largestIndividual.amount})`, `Total tips: ${totalTipped}` ]; cb.sendNotice(notice.join('\n'), msg.user, noticeColor); return msg; } });
© Copyright Chaturbate 2011- 2024. All Rights Reserved.