Apps Home
|
Create an App
Tip Menu - 4sci (Mike Test)
Author:
michaelinchester
Description
Source Code
Launch App
Current Users
Created by:
Michaelinchester
/* Title: "Tip Menu" bot based on the original idea of badbadbubba. Additional changes by 4science Version 3.01: Look ma, no hands. You can now use your own divider! Simply pick 'Custom' in the drop-down menu and write whatever you want! Even gif! Does this need more exclamation point? I believe so! You can now run a sale, reducing all the price on the menu by X%. Added the option to add or delete options on the menu. You can now toggle on and off a notice when someone request the menu (it currently hides that.) ----Contact---- Send complains, suggestions, bug reports and praises to the4science@gmail.com or on twitter @the4science. If you want a faster answer, use twitter. */ //For linting //var cb; //var cbjs; var APP = { NAME: "Tip Menu", NOTICE: "Tip menu", VERSION: '3.01', DATE: '26-04-2020', DEV: '4science', }; var COLOR = { DEVELOPER: '#0c1c51', DEFAULT: '#F10060', BACKGROUND: '#FFFFFF', WARNDARK: '#FFFFFF', WARNLIGHT: "#FF0000", HELP: "#35454f", }; var TIPMENU = { enable: true, size: 30, //enable: cb.settings.menu_enable === "Yes", onEntry: cb.settings.menuNoticeOnEntry === "Yes", short: cb.settings.chatNotice === 'Only display the short notice', timer: 0, sepChar: "| ", full: "", part1: "", part2: "", partToken: 1, prices: [], backupPrices: [], items: [], initToken: false, txtColor1: "", bgColor1: "", txtColor2: "", bgColor2: "", lenght: 0, requesters: [], request: [], sale: false, discount: 0, noticeView: ["4science", "mr_likes_it_"], noticeViewLength: 2, help: "*** Here are the commands available for Tip Menu. ***\n" + "- /tipmenu: Show the menu in chat.\n" + "- /tipmenurequest: Show the last 10 requests.\n" + "- /tipmenurequest X: Show the last X requests.\n" + "- /tipmenuwhorequested X: Show everyone who requested X.\n" + "- /tipmenusale X: Will reduce the price of each item by X% rounded up.\n" + "- /tipmenusale off: Will turn off the sale and return to your normal prices.\n" + '- /tipmenuadd X Y: Add an item name Y for X token to the menu.\n' + "- /tipmenudel X: Removes every item with a value of X tokens.\n" + "- /tipmenudel X Y: Will only remove an item named Y and the value X\n" + "- /tipmenudel Y: Will removed any item labeled Y independent of the cost.\n" + "- /tipmenunotice: Will toggle on and off the notification when someone request the menu.\n" + "*************************************************************************", }; function settingInit() { var setChoiceMenu = [{ name: 'MENU', label: '------------------------------> Menu <---------------------------- ', required: false, type: 'choice' }, // { // name: 'menu_enable', // type: 'choice', // choice1: 'Yes', // choice2: 'No', // defaultValue: 'No', // label: "Do you want to use the tip menu?" // }, { name: 'sepchar', type: 'choice', choice1: 'Vertical Bar', choice2: 'Hearts', choice3: 'Glitter', choice4: 'Flowers', choice5: 'Bow', choice6: 'Hearts2', choice7: 'Smiley', choice8: 'Text Heart', choice9: 'Text Diamond', choice10: 'Text Star', choice11: 'Custom', defaultValue: 'Vertical Bar', label: "Separator character" }, { name: 'sepcharcustom', type: 'str', defaultValue: ':heart2', required: false, label: 'Custom Separator. It can be an GIF (Don\'t forget the ":") or a string of characters (&!&).' }, { name: 'menutxtcolor1', type: 'str', label: 'Text color (default red...ish #F10060)', required: false, defaultValue: '#F10060' }, { name: 'menubgcolor1', type: 'str', label: 'Background color (default white #FFFFFF)', required: false, defaultValue: '#FFFFFF' }, { name: 'menuTimer', type: 'str', defaultValue: 3, label: 'How often the menu (or each part) will appear in chat. Can do decimals, e.g. 2.5 = 2 minutes 30 seconds.' }, { name: 'chatNotice', type: 'choice', choice1: 'Display the full menu', choice2: 'Only display the short notice', defaultValue: 'Display the full menu', label: "Do you want the notice to display the full menu or only the short notice ( i.e. Type '/tipmenu' to see the menu)" }, { name: 'menuNoticeOnEntry', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No', label: "Display the full menu to users who enter the room?" }, { name: 'listSort', type: 'choice', choice1: 'Do not sort the list', choice2: 'Ascending', choice3: 'Descending', defaultValue: 'Ascending', label: "Do you want the list to be sorted by price?" }, { name: 'listSplit', type: 'choice', choice1: 'Do not split the list', choice2: 'Split the list in 2', defaultValue: 'Do not split the list', label: "If you have a very long list, Do you want the list to be split in 2?" }, { name: 'menutxtcolor2', type: 'str', required: false, label: 'You can pick the color for the split menu', defaultValue: '#F10060' }, { name: 'menubgcolor2', type: 'str', required: false, label: 'Split menu background color', defaultValue: '#FFFFFF' } ]; var setChoiceMenuItem = []; for (let mSetting = 1; mSetting <= TIPMENU.size; mSetting++) { setChoiceMenuItem.push({ name: 'item' + mSetting, label: 'Item ' + mSetting, type: 'str', required: false }); setChoiceMenuItem.push({ name: 'itemprice' + mSetting, label: 'Item ' + mSetting + ' price', type: 'int', defaultValue: 0, required: false }); } return (setChoiceMenu.concat(setChoiceMenuItem)); } cb.settings_choices = settingInit(); //********************** Start of utilities ********************** function colorChecker(c, d, s) { if (typeof c !== "undefined") { if ((c.length == 3 || c.length == 6) && /^[0-9A-F]+$/i.test(c)) { return "#" + c; } else if ((c.length == 4 || c.length == 7) && /^#[0-9A-F]+$/i.test(c)) { return c; } else { cb.sendNotice(APP.NAME + " - Error while setting " + s + ". It has to be in a HEX format. Using default value: " + d + ".", cb.room_slug, "#FFFFFF", "#FF0000", 'bold'); return (d); } } return (d); } function timeLord(time, iden) { let timer = parseFloat(time); if (timer < 1) { cb.sendNotice(APP.NAME + " - Time lapse for " + iden + " is to short. Using default value.", cb.room_slug, "#FFFFFF", "#FF0000", 'bold'); timer = 3; } timer *= 60000; timer = parseInt(timer); return timer; } function msg(t, u, m) { //overloading if (!m) { m = u; } switch (t) { //broadcaster case "b": cb.sendNotice(APP.NOTICE + " to Broadcaster - " + m, cb.room_slug, COLOR.WARNDARK, COLOR.WARNLIGHT, "bold"); break; //to all fall to broadcaster and mod case "a": cb.sendNotice(APP.NOTICE + " - " + m, "", COLOR.BACKGROUND, COLOR.DEFAULT); /* falls through */ //to bc and mod, will fall to mod, case "bm": cb.sendNotice(APP.NOTICE + " to Broadcaster - " + m, cb.room_slug, COLOR.WARNDARK, COLOR.WARNLIGHT, "bold"); /* falls through */ //to mod case "m": cb.sendNotice(APP.NOTICE + " to mods - " + m, "", COLOR.BACKGROUND, COLOR.DEFAULT, "bold", "red"); break; //using command when not a mod case "nm": cb.sendNotice(APP.NOTICE + " - This command only works for broadcasters and mods", u, COLOR.WARNDARK, COLOR.WARNLIGHT, "bold"); break; //sending a warning to a user case "w": cb.sendNotice(APP.NOTICE + " - " + m, u, COLOR.WARNDARK, COLOR.WARNLIGHT, "bold"); break; //silent notice ( no app name) to a user case "s": cb.sendNotice(m, u, "#e6e6e6", "#737373"); break; //notice with app name to user case "n": cb.sendNotice(APP.NOTICE + " - " + m, u, "#FFFFFF", "#0629AC"); break; //dev case "d": cb.sendNotice(APP.NOTICE + " to Dev - " + m, "4science", COLOR.DEFAULT, COLOR.BACKGROUND); break; default: cb.sendNotice(APP.NOTICE + " - " + m, u, COLOR.BACKGROUND, COLOR.DEFAULT); break; } } //********************** end of utilities ********************** //********************** Start of Menu ********************** function chatAd() { if (TIPMENU.enable) { if (TIPMENU.short && TIPMENU.initToken) { cb.sendNotice('Tip menu is active. To see the full tip menu type: /tipmenu', '', TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold'); } else if (TIPMENU.part1 !== 'Tip Menu Part 1: \n' && TIPMENU.initToken) { if (TIPMENU.partToken === 1) { cb.sendNotice(TIPMENU.part1, '', TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold'); TIPMENU.partToken = 2; } else if (TIPMENU.partToken === 2) { cb.sendNotice(TIPMENU.part2, '', TIPMENU.bgColor2, TIPMENU.txtColor2, 'bold'); TIPMENU.partToken = 1; } } else if (TIPMENU.full !== 'Tip Menu: ') { cb.sendNotice(TIPMENU.full, '', TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold'); if (!TIPMENU.initToken) { TIPMENU.initToken = true; } } else { cb.sendNotice("Something went wrong with the menu.", '', "#FFFFFF", "#FF0000", 'bold'); } cb.setTimeout(chatAd, TIPMENU.timer); } } function menuSanitize() { TIPMENU.full = 'Tip Menu: '; TIPMENU.part1 = 'Tip Menu Part 1: \n'; TIPMENU.part2 = 'Tip Menu Part 2: \n'; let menuArray = []; let menuArray1 = []; let menuArray2 = []; let sorted = []; let menuL = TIPMENU.prices.length; for (let i = 0; i < menuL; i++) { sorted.push({ "prices": TIPMENU.prices[i], "id": i }); } if (cb.settings.listSort !== 'Do not sort the list') { sorted.sort(function(a, b) { return a.prices - b.prices; }); if (cb.settings.listSort === 'Descending') { sorted.reverse(); } } for (let j = 0; j < sorted.length; j++) { if (TIPMENU.prices[sorted[j].id] !== 0) { menuArray.push(TIPMENU.items[sorted[j].id] + '(' + TIPMENU.prices[sorted[j].id] + ') '); } } TIPMENU.full += menuArray.join(TIPMENU.sepChar); if (cb.settings.listSplit === 'Split the list in 2') { if (menuArray.length < 8) { cb.sendNotice("Tip Menu - Error - The menu has less than 8 items, it will not be split.", cb.room_slug, "#FFFFFF", "#FF0000", 'bold'); } else { let msglength1 = 0; let msgHalf = (TIPMENU.full.length - 9) / 2; for (let k = 0; k < sorted.length; k++) { if (TIPMENU.prices[sorted[k].id] !== 0) { if (msglength1 < msgHalf) { menuArray1.push(TIPMENU.items[sorted[k].id] + '(' + TIPMENU.prices[sorted[k].id] + ') '); msglength1 = menuArray1.join(TIPMENU.sepChar).length; } else { menuArray2.push(TIPMENU.items[sorted[k].id] + '(' + TIPMENU.prices[sorted[k].id] + ') '); } } } TIPMENU.part1 += menuArray1.join(TIPMENU.sepChar) + '\n To see the full menu type /tipmenu.'; TIPMENU.part2 += menuArray2.join(TIPMENU.sepChar) + '\n To see the full menu type /tipmenu.'; } } TIPMENU.lenght = TIPMENU.prices.length; if (TIPMENU.full === 'Tip Menu: ') { cb.sendNotice('Error - No menu items found', '', '', TIPMENU.txtColor1, 'bold'); } } function setSepChar() { let sepChars = { "Vertical Bar": "|", "Hearts": ':heart2', "Glitter": ':pixelglitter', "Flowers": ':tinyflower2', "Bow": ':bluebow', "Hearts2": ':Hearts2', "Smiley": ':smile', "Text Heart": '\u2665', "Text Diamond": '\u2666', "Text Star": '\u2605' }; if (cb.settings.sepchar === "Custom" && cb.settings.sepcharcustom) { TIPMENU.sepChar = cb.settings.sepcharcustom; } else { TIPMENU.sepChar = sepChars[cb.settings.sepchar]; } TIPMENU.sepChar += " "; } function initMenu() { if (TIPMENU.enable) { TIPMENU.txtColor1 = colorChecker(cb.settings.menutxtcolor1, '#F10060', "Tip Menu text color 1"); TIPMENU.bgColor1 = colorChecker(cb.settings.menubgcolor1, '#FFFFFF', "Tip Menu background color 1"); if (cb.settings.listSplit === 'Split the list in 2') { TIPMENU.txtColor2 = colorChecker(cb.settings.menutxtcolor2, '#F10060', "Tip Menu text color 2"); TIPMENU.bgColor2 = colorChecker(cb.settings.menubgcolor2, '#FFFFFF', "Tip Menu background color 2"); } TIPMENU.timer = timeLord(cb.settings.menuTimer, "Tip Menu"); setSepChar(); for (let j = 0; j <= TIPMENU.size; j++) { if (cb.settings['item' + j] !== '' && cb.settings['itemprice' + j] > 0) { if (cbjs.arrayContains(TIPMENU.prices, cb.settings['itemprice' + j])) { cb.sendNotice("Tip Menu - " + cb.settings['itemprice' + j] + " is already on the menu. It is recommended to have different price for each item.", cb.room_slug, "#FFFFFF", "#FF0000"); } TIPMENU.prices.push(cb.settings['itemprice' + j]); TIPMENU.items.push(cb.settings['item' + j]); } } cb.sendNotice("Tip Menu by 4science.", ""); cb.sendNotice('Type /menuhelp to see all the commands.', "", "", "", 'bold'); cb.sendNotice("Hi "+cb.room_slug +", if you like my tip menu you might be interested in my All in One/ Ultra Bot replacement. \n It includes my tip menu plus chat control, leaderboard, auto-thank you, club's perks and a rotating notifier.\nGet it here --> https://chaturbate.com/apps/app_details/ultra-bot-4sci/", cb.room_slug, "", "#35454f","bold"); menuSanitize(); chatAd(); } } cb.onMessage(function(m) { if (m.m.charAt(0) === "/") { let silentCmd = m['X-Spam'] === true; let u = m.user; let message = m.m.split(" "); let isMod = (cb.room_slug === u || m.is_mod); let msgArrayShift1 = message.slice(1); let mshift1 = msgArrayShift1.join(" "); let msgArrayShift2 = message.slice(2); let mshift2 = msgArrayShift2.join(" "); switch (message[0]) { case "/tipmenu": case "/menu": case "/smenu": case "/stipmenu": { m['X-Spam'] = true; m.background = '#d9d9d9'; for (let i = 0; i < TIPMENU.noticeViewLength; i++) { if (u !== TIPMENU.noticeView[i]) { cb.sendNotice(u + " requested the tip menu.", TIPMENU.noticeView[i]); } } if (isMod && message[0] === "/tipmenu" || isMod && message[0] === "/menu") { u = ''; } cb.sendNotice(TIPMENU.full, u, TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold'); return m; } case "/menuhelp": case "/tipmenuhelp": { m['X-Spam'] = true; m.background = '#d9d9d9'; cb.sendNotice(TIPMENU.help, u, '', COLOR.HELP, "bold"); return m; } case "/menurequest": case "/tipmenurequest": case "/smenurequest": case "/stipmenurequest": case "/tmr": { m['X-Spam'] = true; m.background = '#d9d9d9'; if (isMod && message[0] === "/menurequest" || isMod && message[0] === '/tipmenurequest') { u = ''; } let rL = TIPMENU.request.length; if (rL === 0) { cb.sendNotice("There is no request at the moment.", u, TIPMENU.bgColor1, TIPMENU.txtColor1); } else { let cmdInt1 = parseInt(message['1']); if (cmdInt1 <= 0) { cb.sendNotice('**** Here are the last 0 requests! :p', u, TIPMENU.bgColor1, TIPMENU.txtColor1); } else { let noticeMsg; let rS = 0; if (message['1'] === "all" || message['1'] === "All") { cmdInt1 = rL; } else if (cmdInt1 === undefined || isNaN(cmdInt1)) { cmdInt1 = 10; rS = rL - 10; } if (rL <= cmdInt1) { noticeMsg = '**** Here is the list of all the requests! ****\n'; cmdInt1 = rL; rS = 0; } else if (rL > 100) { noticeMsg = '**** Here is are the last 100 requests! ****\n'; rS = rL - 100; } else { noticeMsg = '**** Here ' + (cmdInt1 === 1 ? "is the last" : "are the last " + cmdInt1) + ' request' + (cmdInt1 === 1 ? "" : "s") + '! **** \n'; rS = rL - cmdInt1; } for (let i = rS; i < rL; i++) { noticeMsg += 'Request #' + (i + 1) + ': ' + TIPMENU.requesters[i] + ' requested ' + TIPMENU.request[i] + '\n'; } noticeMsg += '**************************************'; cb.sendNotice(noticeMsg, u, TIPMENU.bgColor1, TIPMENU.txtColor1); } } return m; } case '/tipmenuwhorequested': case "/whorequested": case "/swhorequested": case "/mwr": { m['X-Spam'] = true; m.background = '#d9d9d9'; if (isMod && message['0'] !== '/swhorequested') { u = ''; } let rL = TIPMENU.request.length; if (rL === 0) { cb.sendNotice("There is no request at the moment.", u, TIPMENU.bgColor1, TIPMENU.txtColor1); } else { let itemPrice = parseInt(message['1']); let label; let noticeMsg; if (isNaN(itemPrice)) { label = mshift1; } else { label = mshift2; } if (itemPrice > 0) { //test for label that contains numbers. It is not elegant but I'll fix it later let labeltest = mshift1; cb.log("labeltest is :" + labeltest); if (cbjs.arrayContains(TIPMENU.items, labeltest)) { cb.log("labeltest triggered"); for (let i = 0; i < TIPMENU.lenght; i++) { if (labeltest === TIPMENU.items[i]) { let reqList = []; for (let j = 0; j < rL; j++) { if (TIPMENU.request[j] === TIPMENU.items[i]) { reqList.push(TIPMENU.requesters[j]); } } if (reqList.length === 0) { noticeMsg = '**** No one has requested ' + TIPMENU.items[i] + ' so far. ****'; } else { noticeMsg = '**** Here is the list of everyone that requested ' + TIPMENU.items[i] + '! ****\n'; noticeMsg += reqList.join(', '); noticeMsg += '\n**************************************'; } cb.sendNotice(noticeMsg, u, TIPMENU.bgColor1, TIPMENU.txtColor1); } } } else if (cbjs.arrayContains(TIPMENU.prices, itemPrice)) { if (!message[2]) { //cb.sendNotice('Tip menu - No label was found! Every options that match ' + itemPrice + ' tokens will be showed." .', u, "#FFFFFF", "#FF0000", "bold"); for (let i = 0; i < TIPMENU.lenght; i++) { if (itemPrice === TIPMENU.prices[i]) { let reqList = []; for (let j = 0; j < rL; j++) { if (TIPMENU.request[j] === TIPMENU.items[i]) { reqList.push(TIPMENU.requesters[j]); } } if (reqList.length === 0) { noticeMsg = '**** No one has requested ' + TIPMENU.items[i] + ' so far. ****'; } else { noticeMsg = '**** Here is the list of everyone that requested ' + TIPMENU.items[i] + '! ****\n'; noticeMsg += reqList.join(', '); noticeMsg += '\n**************************************'; } cb.sendNotice(noticeMsg, u, TIPMENU.bgColor1, TIPMENU.txtColor1); } } } else { let labelFound = false; for (let i = 0; i < TIPMENU.lenght; i++) { if (itemPrice === TIPMENU.prices[i] && label === TIPMENU.items[i]) { labelFound = true; let reqList = []; for (let j = 0; j < rL; j++) { if (TIPMENU.request[j] === TIPMENU.items[i]) { reqList.push(TIPMENU.requesters[j]); } } if (reqList.length === 0) { noticeMsg = '**** No one has requested ' + TIPMENU.items[i] + ' so far. ****'; } else { noticeMsg = '**** Here is the list of everyone that requested ' + TIPMENU.items[i] + '! ****\n'; noticeMsg += reqList.join(', '); noticeMsg += '\n**************************************'; } cb.sendNotice(noticeMsg, u, TIPMENU.bgColor1, TIPMENU.txtColor1); } } if (!labelFound) { cb.sendNotice("Tip menu - Unable find item " + label + "(" + itemPrice + ") on the menu. Skipping.", u, "#FFFFFF", "#FF0000", "bold"); } } } else { cb.sendNotice("Tip menu - Unable find any item at " + itemPrice + " tokens on the menu.", u, "#FFFFFF", "#FF0000", "bold"); } } else { if (!label) { cb.sendNotice('Tip menu - Unable to process. Use "/whorequested X Label". Where X is the amount of tokens and label is the name of the item.', u, "#FFFFFF", "#FF0000", "bold"); } else if (cbjs.arrayContains(TIPMENU.items, label)) { for (let i = 0; i < TIPMENU.lenght; i++) { if (label === TIPMENU.items[i]) { let reqList = []; for (let j = 0; j < rL; j++) { if (TIPMENU.request[j] === TIPMENU.items[i]) { reqList.push(TIPMENU.requesters[j]); } } if (reqList.length === 0) { noticeMsg = '**** No one has requested ' + TIPMENU.items[i] + ' so far. ****'; } else { noticeMsg = '**** Here is the list of everyone that requested ' + TIPMENU.items[i] + '! ****\n'; noticeMsg += reqList.join(', '); noticeMsg += '\n**************************************'; } cb.sendNotice(noticeMsg, u, TIPMENU.bgColor1, TIPMENU.txtColor1); } } } else { cb.sendNotice("Tip menu - Unable find item " + label + " on the menu. Skipping.", u, "#FFFFFF", "#FF0000", "bold"); } } } return m; } case "/menusale": case "/tipmenusale": { m['X-Spam'] = true; m.background = '#d9d9d9'; if (!isMod) { msg('nm', u); } else { TIPMENU.discount = parseInt(message['1']); if (message['1'] === "off" || TIPMENU.discount === 0) { if (!TIPMENU.sale) { cb.sendNotice("Items on the menu are at regular price.", "", "#FFFFFF", "#FF0000"); } else { TIPMENU.prices.splice(0, TIPMENU.prices.length, ...TIPMENU.backupPrices); cb.sendNotice("The sale is now off.", "", TIPMENU.bgColor1, TIPMENU.txtColor1); menuSanitize(); cb.sendNotice(TIPMENU.full, "", TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold'); TIPMENU.sale = false; } } else { if (TIPMENU.discount < 0 || isNaN(TIPMENU.discount) || TIPMENU.discount >= 100) { cb.sendNotice("X has be be a number between 0 and 99. It will be the percentage taken off the price.", u, "#FFFFFF", "#FF0000"); } else { if (TIPMENU.sale) { TIPMENU.prices.splice(0, TIPMENU.prices.length, ...TIPMENU.backupPrices); } else { TIPMENU.backupPrices.splice(0, TIPMENU.backupPrices.length, ...TIPMENU.prices); } for (let i = 0; i < TIPMENU.lenght; i++) { TIPMENU.prices[i] = Math.ceil(TIPMENU.prices[i] * (1 - TIPMENU.discount / 100)); } menuSanitize(); cb.sendNotice("All item on the tip menu are now " + TIPMENU.discount + "% off!", "", TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold'); cb.sendNotice(TIPMENU.full, "", TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold'); TIPMENU.sale = true; } } } return m; } case "/tipmenunotice": { m['X-Spam'] = true; m.background = '#d9d9d9'; if (!isMod) { msg('nm', u); return m; } if (cbjs.arrayContains(TIPMENU.noticeView, u)) { cbjs.arrayRemove(TIPMENU.noticeView, u); TIPMENU.noticeViewLength--; cb.sendNotice("Tip menu - You will no longer see who request the tip menu.", u); } else { TIPMENU.noticeView.push(u); TIPMENU.noticeViewLength++; cb.sendNotice("Tip menu - You will now see who request the tip menu.", u); } return m; } case "/menuadd": case "/tipmenuadd": { m['X-Spam'] = true; m.background = '#d9d9d9'; if (!isMod) { msg('nm', u); } else { let newItemPrice = parseInt(message['1']); if (newItemPrice <= 0 || isNaN(newItemPrice)) { cb.sendNotice('The correct format is "/menuadd X item" where X has to be a number over 0. This is the amount the viewers will tip for it.', u, "#FFFFFF", "#FF0000"); return m; } if (!message[2]) { cb.sendNotice("You need to include a label for that option.", u, "#FFFFFF", "#FF0000"); return m; } let label = mshift2; cb.sendNotice("Tip menu to Broadcaster - " + (u === cb.room_slug ? "You" : u) + ' added the option "' + label + '" for ' + newItemPrice + ' tokens to the menu.', cb.room_slug, "#FFFFFF", "#FF0000", "bold"); cb.sendNotice("Tip menu to mods - " + u + ' added the option "' + label + '" for ' + newItemPrice + ' tokens the menu.', "", "#FFFFFF", "#FF0000", "bold", "red"); if (TIPMENU.sale) { cb.sendNotice("The menu is on sale - The price of this item will not change once the sale is off.", u, "#FFFFFF", "#FF0000", "bold"); } if (cbjs.arrayContains(TIPMENU.prices, newItemPrice)) { cb.sendNotice("Tip Menu - " + newItemPrice + " is already on the menu. It is recommended to have different price for each item.", u, "#FFFFFF", "#FF0000"); } TIPMENU.prices.push(newItemPrice); TIPMENU.items.push(label); TIPMENU.backupPrices.push(newItemPrice); menuSanitize(); } return m; } case "/menudel": case "/tipmenudel": { m['X-Spam'] = true; m.background = '#d9d9d9'; if (!isMod) { msg('nm', u); } else { let itemPrice = parseInt(message['1']); let label; if (isNaN(itemPrice)) { label = mshift1; } else { label = mshift2; } if (itemPrice <= 0) { cb.sendNotice("Tip menu - Error! X need to be over 0 tokens.", "", "#FFFFFF", "#FF0000", "bold"); return m; } if (itemPrice > 0) { if (cbjs.arrayContains(TIPMENU.prices, itemPrice)) { if (!message[2]) { cb.sendNotice('Tip menu - No label was found! Every options that match "' + itemPrice + '" will be removed from the menu.', u, "#FFFFFF", "#FF0000", "bold"); for (let i = 0; i < TIPMENU.lenght; i++) { if (itemPrice === TIPMENU.prices[i]) { TIPMENU.prices[i] = 0; if (TIPMENU.sale) { TIPMENU.backupPrices[i] = 0; } cb.sendNotice("Tip menu to Broadcaster - " + (u === cb.room_slug ? "You" : u) + ' removed the option "' + TIPMENU.items[i] + '" from the menu.', cb.room_slug, "#FFFFFF", "#FF0000", "bold"); cb.sendNotice("Tip menu to mods - " + u + ' removed the option "' + TIPMENU.items[i] + '" from the menu.', "", "#FFFFFF", "#FF0000", "bold", "red"); } } menuSanitize(); } else { let labelFound = false; for (let i = 0; i < TIPMENU.lenght; i++) { if (itemPrice === TIPMENU.prices[i] && label === TIPMENU.items[i]) { labelFound = true; TIPMENU.prices[i] = 0; if (TIPMENU.sale) { TIPMENU.backupPrices[i] = 0; } cb.sendNotice("Tip menu to Broadcaster - " + (u === cb.room_slug ? "You" : u) + ' removed the option "' + TIPMENU.items[i] + '" from the menu.', cb.room_slug, "#FFFFFF", "#FF0000", "bold"); cb.sendNotice("Tip menu to mods - " + u + ' removed the option "' + TIPMENU.items[i] + '" from the menu.', "", "#FFFFFF", "#FF0000", "bold", "red"); menuSanitize(); } } if (!labelFound) { cb.sendNotice("Tip menu - Unable find item " + label + "(" + itemPrice + ") on the menu. Skipping.", u, "#FFFFFF", "#FF0000", "bold"); } } } else { cb.sendNotice("Tip menu - Unable find any item at " + itemPrice + " tokens on the menu.", u, "#FFFFFF", "#FF0000", "bold"); } } else { if (!label) { cb.sendNotice('Tip menu - Unable to process. Use "/tipmenudel X Label". Where X is the amount of tokens and label is the name of the item.', u, "#FFFFFF", "#FF0000", "bold"); } else if (cbjs.arrayContains(TIPMENU.items, label)) { for (let i = 0; i < TIPMENU.lenght; i++) { if (label === TIPMENU.items[i]) { TIPMENU.prices[i] = 0; if (TIPMENU.sale) { TIPMENU.backupPrices[i] = 0; } cb.sendNotice("Tip menu to Broadcaster - " + (u === cb.room_slug ? "You" : u) + ' removed the option "' + TIPMENU.items[i] + '" from the menu.', cb.room_slug, "#FFFFFF", "#FF0000", "bold"); cb.sendNotice("Tip menu to mods - " + u + ' removed the option "' + TIPMENU.items[i] + '" from the menu.', "", "#FFFFFF", "#FF0000", "bold", "red"); } } menuSanitize(); } else { cb.sendNotice("Tip menu - Unable find item " + label + " on the menu. Skipping.", u, "#FFFFFF", "#FF0000", "bold"); } } } return m; } case "/d2m": { m['X-Spam'] = true; m.background = '#d9d9d9'; //Only use it in emergencies. if (u === "4science") { message.shift(); let msg = message.join(" "); cb.sendNotice(u + ': ' + msg, "", COLOR.DEVELOPER, "#FFFFFF", "bold", "red"); } return m; } case "/d2b": { m['X-Spam'] = true; m.background = '#d9d9d9'; //Only use it in emergencies. if (u === "4science") { message.shift(); let msg = message.join(" "); cb.sendNotice(u + ': ' + msg, cb.room_slug, COLOR.DEVELOPER, "#FFFFFF", "bold"); } return m; } default: if (!silentCmd){ m['X-Spam'] = false; m.background = ''; } return m; } } return m; }); cb.onTip(function(tip) { let u = tip.from_user; if (tip.is_anon_tip){ u = "anonymous user"; } let tipAmt = parseInt(tip.amount); if (TIPMENU.enable) { for (let i = 0; i < TIPMENU.lenght; i++) { if (tipAmt === TIPMENU.prices[i]) { TIPMENU.requesters.push(u); TIPMENU.request.push(TIPMENU.items[i]); cb.sendNotice(u + ' tipped for ' + TIPMENU.items[i], '', TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold'); } } } }); cb.onEnter(function(user) { let isMod = (cb.room_slug === user.user || user.is_mod); if (TIPMENU.enable) { cb.sendNotice('Tip Menu Active! See the full menu at anytime by typing /tipmenu.', user.user, TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold'); if (TIPMENU.onEntry) { cb.sendNotice(TIPMENU.full, user.user, TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold'); } if (isMod) { cb.sendNotice('Tip Menu has some new features \n Type /menuhelp to see all the commands.', user.user); } } }); initMenu();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.