Apps Home
|
Create an App
Simple-Tip-Menu3
Author:
broadtester
Description
Source Code
Launch App
Current Users
Created by:
Broadtester
// Simple-Tip-Menu by Luvdoinit // 30 May 2021 // v1.0.0 cb.settings_choices = [ { name: "tipMenu", type: "str", label: `Use "|" to separate menu items. Use "~" to separate tip amount. For example: "Show Cock~100|Show Arse~80|Show Feet~20"`, required: true, }, { name: "noticeTimeout", type: "int", minValue: 0, maxValue: 3600, label: `Tip menu notice timeout (in seconds). Use "0" to disable`, defaultValue: 300, required: true, }, ]; const nfError = { back: "#FF0000", fore: "#FFFFFF", weight: "bold", }; const nfMessage = { back: "#FFFF00", fore: "#000000", weight: "bold", }; const nfTip = { back: "#0000FF", fore: "#FFFFFF", weight: "bold", }; const symbol = { king: "\u2654", star: "\u2605", threeLeftArrows: "\u2B9C\u2B9C\u2B9C", threeRightArrows: "\u2B9E\u2B9E\u2B9E", redCross: "\u274C", }; const tipMenuOptions = { tipMenu: [], totalTips: 0, lastTip: 0, lastTipper: "", highestTip: 0, highestTipper: undefined, tippedItem: undefined, }; const initTipMenuOptions = function initTipMenuOptions() { let ret = true; const errors = []; if (cb.settings.tipMenu) { cb.settings.tipMenu.split("|").forEach((mi, i) => { const tmp = mi.split("~"); if (tmp.length === 2) { const menuItem = { label: tmp[0], amount: parseInt(tmp[1], 10) }; if (menuItem.amount > 0) { tipMenuOptions.tipMenu.push(menuItem); } else { errors.push( `${symbol.redCross} ${symbol.threeRightArrows} ${menuItem.label} amount must be > 0 ${symbol.threeLeftArrows} ${symbol.redCross}` ); } } else { errors.push(`${symbol.redCross} ${symbol.threeRightArrows} Menu Item ${i} has no "~" ${symbol.threeLeftArrows} ${symbol.redCross}`); } }); if (tipMenuOptions.tipMenu.length < 1) { errors.push(`${symbol.redCross} ${symbol.threeRightArrows} No valid tip menu items found ${symbol.threeLeftArrows} ${symbol.redCross}`); } } else { errors.push(`${symbol.redCross} ${symbol.threeRightArrows} The tip menu has not been set ${symbol.threeLeftArrows} ${symbol.redCross}`); } if (errors.length > 0) { ret = false; errors.forEach((err) => { cb.sendNotice(err, cb.room_slug, nfError.back, nfError.fore, nfError.weight); }); } return ret; }; const setTip = function setTip(tip) { tipMenuOptions.tippedItem = tipMenuOptions.tipMenu.find((mi) => mi.amount === tip.amount); tipMenuOptions.totalTips += tip.amount; tipMenuOptions.lastTip = tip.amount; tipMenuOptions.lastTipper = tip.from_user; if (tip.amount > tipMenuOptions.highestTip) { tipMenuOptions.highestTip = tip.amount; tipMenuOptions.highestTipper = tip.from_user; } }; const displayTipThanks = function displayTipThanks() { if (tipMenuOptions.tippedItem && tipMenuOptions.lastTipper) { const text = `${symbol.threeRightArrows} ${tipMenuOptions.lastTipper} has tipped for ${tipMenuOptions.tippedItem.label}, thank you so much ${symbol.threeLeftArrows}`; cb.sendNotice(text, "", nfTip.back, nfTip.fore, nfTip.weight); } }; const displayTipMenuNotice = function displayTipMenuNotice(toUser) { const lines = []; lines.push(`${symbol.star} ${cb.room_slug}'s Tip Menu`); tipMenuOptions.tipMenu.forEach((mi) => { lines.push(`${mi.label} ... ${mi.amount}`); }); lines.push(`be courteous and please tip ${cb.room_slug} if you enjoy the show ${symbol.star}`); const text = lines.join(` ${symbol.star} `); cb.sendNotice(text, toUser, nfMessage.back, nfMessage.fore, nfMessage.weight); }; const noticeFunction = function noticeFunction() { displayTipMenuNotice(""); const to = cb.settings.noticeTimeout * 1000; if (to > 0) cb.setTimeout(noticeFunction, to); }; const init = function init() { if (initTipMenuOptions()) { noticeFunction(); cb.drawPanel(); cb.onTip((tip) => { setTip(tip); displayTipThanks(); cb.drawPanel(); }); cb.onMessage((msg) => { if (msg.m === "/menu") { displayTipMenuNotice(msg.user === cb.room_slug ? "" : msg.user); } if (msg.user === tipMenuOptions.highestTipper) { msg.m = `${symbol.king} ${msg.m} ${symbol.king}`; } return msg; }); cb.onDrawPanel(() => { const pt = { template: "3_rows_11_21_31", row1_value: `${symbol.star} type /menu to see ${cb.room_slug}'s tip menu ${symbol.star}`, row2_value: `${symbol.star} ${tipMenuOptions.tipMenu[0].label} ... ${tipMenuOptions.tipMenu[0].amount} ${symbol.star}`, row3_value: tipMenuOptions.highestTipper ? `${symbol.king} ${tipMenuOptions.highestTipper} ... ${tipMenuOptions.highestTip} ${symbol.king}` : `${symbol.king} none ${symbol.king}`, }; return pt; }); } }; init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.