Tip Menu Of MissLayla_
Author: misslayla_
Description Source Code Launch Bot Current Users

Short Description:

TipMenu Of MissLayla_

Full Description

/*
Title: "TipMenu Of MissLayla_" bot
based on the original idea of badbadbubba.
Additional changes by MissLayla_
Version 2.0: 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.
*/
cb.settings_choices = [{
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: 'chatAd',
type: 'str',
defaultValue: 3,
label: 'How often the menu (or each part) will appear in chat. Can do fractions, e.g. 2.5 = two 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 ( ei: Type '/tipmenu' to see the menu)"
},
{
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'
},
{
name: 'item1',
type: 'str',
label: "Item 1 "
},
{
name: 'itemprice1',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
label: 'Item 1 price'
},
{
name: 'item2',
type: 'str',
required: false,
label: 'Item 2'
},
{
name: 'itemprice2',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 2 price'
},
{
name: 'item3',
type: 'str',
required: false,
label: 'Item 3'
},
{
name: 'itemprice3',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 3 price'
},
{
name: 'item4',
type: 'str',
required: false,
label: 'Item 4'
},
{
name: 'itemprice4',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 4 price'
},
{
name: 'item5',
type: 'str',
required: false,
label: 'Item 5'
},
{
name: 'itemprice5',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 5 price'
},
{
name: 'item6',
type: 'str',
required: false,
label: 'Item 6'
},
{
name: 'itemprice6',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 6 price'
},
{
name: 'item7',
type: 'str',
required: false,
label: 'Item 7'
},
{
name: 'itemprice7',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 7 price'
},
{
name: 'item8',
type: 'str',
required: false,
label: 'Item 8'
},
{
name: 'itemprice8',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 8 price'
},
{
name: 'item9',
type: 'str',
required: false,
label: 'Item 9'
},
{
name: 'itemprice9',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 9 price'
},
{
name: 'item10',
type: 'str',
required: false,
label: 'Item 10'
},
{
name: 'itemprice10',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 10 price'
},
{
name: 'item11',
type: 'str',
required: false,
label: 'Item 11'
},
{
name: 'itemprice11',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 11 price'
},
{
name: 'item12',
type: 'str',
required: false,
label: 'Item 12'
},
{
name: 'itemprice12',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 12 price'
},
{
name: 'item13',
type: 'str',
required: false,
label: 'Item 13'
},
{
name: 'itemprice13',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 13 price'
},
{
name: 'item14',
type: 'str',
required: false,
label: 'Item 14'
},
{
name: 'itemprice14',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 14 price'
},
{
name: 'item15',
type: 'str',
required: false,
label: 'Item 15'
},
{
name: 'itemprice15',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 15 price'
},
{
name: 'item16',
type: 'str',
required: false,
label: 'Item 16'
},
{
name: 'itemprice16',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 16 price'
},
{
name: 'item17',
type: 'str',
required: false,
label: 'Item 17'
},
{
name: 'itemprice17',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 17 price'
},
{
name: 'item18',
type: 'str',
required: false,
label: 'Item 18'
},
{
name: 'itemprice18',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 18 price'
},
{
name: 'item19',
type: 'str',
required: false,
label: 'Item 19'
},
{
name: 'itemprice19',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 19 price'
},
{
name: 'item20',
type: 'str',
required: false,
label: 'Item 20'
},
{
name: 'itemprice20',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 20 price'
},
{
name: 'item21',
type: 'str',
required: false,
label: 'Item 21'
},
{
name: 'itemprice21',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 21 price'
},
{
name: 'item22',
type: 'str',
required: false,
label: 'Item 22'
},
{
name: 'itemprice22',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 22 price'
},
{
name: 'item23',
type: 'str',
required: false,
label: 'Item 23'
},
{
name: 'itemprice23',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 23 price'
},
{
name: 'item24',
type: 'str',
required: false,
label: 'Item 24'
},
{
name: 'itemprice24',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 24 price'
},
{
name: 'item25',
type: 'str',
required: false,
label: 'Item 25'
},
{
name: 'itemprice25',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 25 price'
},
{
name: 'item26',
type: 'str',
required: false,
label: 'Item 26'
},
{
name: 'itemprice26',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 26 price'
},
{
name: 'item27',
type: 'str',
required: false,
label: 'Item 27'
},
{
name: 'itemprice27',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 27 price'
},
{
name: 'item28',
type: 'str',
required: false,
label: 'Item 28'
},
{
name: 'itemprice28',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 28 price'
},
{
name: 'item29',
type: 'str',
required: false,
label: 'Item 29'
},
{
name: 'itemprice29',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 29 price'
},
{
name: 'item30',
type: 'str',
required: false,
label: 'Item 30'
},
{
name: 'itemprice30',
type: 'int',
minValue: 0,
maxValue: 99999,
defaultValue: 0,
required: false,
label: 'Item 30 price'
}
];
var TIPMENU = {
chatAdTime: 0,
sepChar: "| ",
tipMenu: "",
menuPart1: "",
menuPart2: "",
menuToken: 1,
tipMenuPrice: [],
backupPrice: [],
tipMenuItem: [],
initToken: true,
txtColor1: "",
bgColor1: "",
txtColor2: "",
bgColor2: "",
menuLength: 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" +
"- /tipmenurequest all: Show all the requests (up to 100).\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 independant of the cost.\n" +
"- /tipmenusale X: Will reduce the price of each item by X% rounded up.\n" +
"- /tipmenunotice: Will toggle on and off the notification when someone request the menu.",
};

function chatAd() {
if (cb.settings.chatNotice === 'Only display the short notice' && !TIPMENU.initToken) {
cb.sendNotice('Tip menu is active. To see the full tip menu type: /tipmenu', '', TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold');
} else if (TIPMENU.menuPart1 !== 'Tip Menu Part 1: \n' && !TIPMENU.initToken) {
if (TIPMENU.menuToken === 1) {
cb.sendNotice(TIPMENU.menuPart1, '', TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold');
TIPMENU.menuToken = 2;
} else if (TIPMENU.menuToken === 2) {
cb.sendNotice(TIPMENU.menuPart2, '', TIPMENU.bgColor2, TIPMENU.txtColor2, 'bold');
TIPMENU.menuToken = 1;
}
} else if (TIPMENU.tipMenu !== 'Tip Menu: ') {
cb.sendNotice(TIPMENU.tipMenu, '', TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold');
if (TIPMENU.initToken) {
TIPMENU.initToken = false;
}
} else {
cb.sendNotice("Something went wrong with the menu.", '', "#FFFFFF", "#FF0000", 'bold');
}
cb.setTimeout(chatAd, TIPMENU.chatAdTime);
}

function chatAdTimer() {
let timer = parseFloat(cb.settings.chatAd);
if (timer < 1) {
cb.sendNotice("Tip Menu - Time lapse is to short. Using default value.", cb.room_slug, "#FFFFFF", "#FF0000", 'bold');
timer = 3;
}
timer *= 60000;
timer = parseInt(timer);
TIPMENU.chatAdTime = timer;
}

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("BAMA - 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 menuSanitize() {
TIPMENU.tipMenu = 'Tip Menu: ';
TIPMENU.menuPart1 = 'Tip Menu Part 1: \n';
TIPMENU.menuPart2 = 'Tip Menu Part 2: \n';
let menuArray = [];
let menuArray1 = [];
let menuArray2 = [];
let sorted = [];
let menuL = TIPMENU.tipMenuPrice.length;
for (let i = 0; i < menuL; i++) {
sorted.push({
"prices": TIPMENU.tipMenuPrice[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.tipMenuPrice[sorted[j].id] !== 0) {
menuArray.push(TIPMENU.tipMenuItem[sorted[j].id] + '(' + TIPMENU.tipMenuPrice[sorted[j].id] + ') ');
}
}
TIPMENU.tipMenu += 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.tipMenu.length - 9) / 2;
for (let k = 0; k < sorted.length; k++) {
if (TIPMENU.tipMenuPrice[sorted[k].id] !== 0) {
if (msglength1 < msgHalf) {
menuArray1.push(TIPMENU.tipMenuItem[sorted[k].id] + '(' + TIPMENU.tipMenuPrice[sorted[k].id] + ') ');
msglength1 = menuArray1.join(TIPMENU.sepChar).length;
} else {
menuArray2.push(TIPMENU.tipMenuItem[sorted[k].id] + '(' + TIPMENU.tipMenuPrice[sorted[k].id] + ') ');
}
}
}
TIPMENU.menuPart1 += menuArray1.join(TIPMENU.sepChar) + '\n To see the full menu type /tipmenu.';
TIPMENU.menuPart2 += menuArray2.join(TIPMENU.sepChar) + '\n To see the full menu type /tipmenu.';
}
}
TIPMENU.menuLength = TIPMENU.tipMenuPrice.length;
if (TIPMENU.tipMenu === 'Tip Menu: ') {
cb.sendNotice('Error - No menu items found', '', '', TIPMENU.txtColor1, 'bold');
}
}

function setSepChar() {
switch (cb.settings.sepchar) {
case "Custom":
{
if (cb.settings.sepcharcustom) {
TIPMENU.sepChar = cb.settings.sepcharcustom;
} else {
TIPMENU.sepChar = "|";
}
}
break;
case "Hearts":
{
TIPMENU.sepChar = ':heart2';
}
break;
case "Glitter":
{
TIPMENU.sepChar = ':pixelglitter';
}
break;
case "Flowers":
{
TIPMENU.sepChar = ':tinyflower2';
}
break;
case "Bow":
{
TIPMENU.sepChar = ':bluebow';
}
break;
case "Hearts2":
{
TIPMENU.sepChar = ':Hearts2';
}
break;
case "Smiley":
{
TIPMENU.sepChar = ':smile';
}
break;
case "Text Heart":
{
TIPMENU.sepChar = '\u2665';
}
break;
case "Text Diamond":
{
TIPMENU.sepChar = '\u2666';
}
break;
case "Text Star":
{
TIPMENU.sepChar = '\u2605';
}
break;
default:
TIPMENU.sepChar = "|";
}
TIPMENU.sepChar += " ";
}

function initMenu() {
let maxItems = 30;
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");
}
chatAdTimer();
setSepChar();

for (let j = 0; j <= maxItems; j++) {
if (cb.settings['item' + j] !== '' && cb.settings['itemprice' + j] > 0) {
if (cbjs.arrayContains(TIPMENU.tipMenuPrice, 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.tipMenuPrice.push(cb.settings['itemprice' + j]);
TIPMENU.tipMenuItem.push(cb.settings['item' + j]);
}
}
cb.sendNotice("Tip Menu by 4science.", "");
cb.sendNotice('Type /menuhelp to see all the commands.', "", "", "", 'bold');
menuSanitize();
chatAd();
}
cb.onTip(function(tip) {
let tipAmt = parseInt(tip.amount);
for (let i = 0; i < TIPMENU.menuLength; i++) {
if (tipAmt === TIPMENU.tipMenuPrice[i]) {
TIPMENU.requesters.push(tip.from_user);
TIPMENU.request.push(TIPMENU.tipMenuItem[i]);
cb.sendNotice(tip.from_user + ' tipped for ' + TIPMENU.tipMenuItem[i], '', TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold');
}
}
});
cb.onMessage(function(m) {
if (m.m.charAt(0) === "/") {
let u = m.user;
let message = m.m.split(" ");
let isMod = (cb.room_slug === u || m.is_mod);
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.tipMenu, u, TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold');
return m;
}
case "/menuhelp":
case "/tipmenuhelp":
{
m['X-Spam'] = true;
m.background = '#d9d9d9';
cb.sendNotice(TIPMENU.help, u);
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 "/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;
let s = 2;
if (isNaN(itemPrice)) {
s = 1;
}
for (let i = s; i < message.length; i++) {
if (i === s) {
label = message[i];
} else {
label += " " + message[i];
}
}
if (itemPrice > 0) {

//test for label that contains numbers. It is not elegant but I'll fix it later

let labeltest;
for (let i = 1; i < message.length; i++) {
if (i === 1) {
labeltest = message[i];
} else {
labeltest += " " + message[i];
}
}
cb.log("labeltest is :" + labeltest);
if (cbjs.arrayContains(TIPMENU.tipMenuItem, labeltest)) {
cb.log("labeltest triggered");
for (let i = 0; i < TIPMENU.menuLength; i++) {
if (labeltest === TIPMENU.tipMenuItem[i]) {
let reqList = [];
for (let j = 0; j < rL; j++) {
if (TIPMENU.request[j] === TIPMENU.tipMenuItem[i]) {
reqList.push(TIPMENU.requesters[j]);
}
}
if (reqList.length === 0) {
noticeMsg = '**** No one has requested ' + TIPMENU.tipMenuItem[i] + ' so far. ****';
} else {
noticeMsg = '**** Here is the list of everyone that requested ' + TIPMENU.tipMenuItem[i] + '! ****\n';
noticeMsg += reqList.join(', ');
noticeMsg += '\n**************************************';
}
cb.sendNotice(noticeMsg, u, TIPMENU.bgColor1, TIPMENU.txtColor1);
}
}
} else if (cbjs.arrayContains(TIPMENU.tipMenuPrice, 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.menuLength; i++) {
if (itemPrice === TIPMENU.tipMenuPrice[i]) {
let reqList = [];
for (let j = 0; j < rL; j++) {
if (TIPMENU.request[j] === TIPMENU.tipMenuItem[i]) {
reqList.push(TIPMENU.requesters[j]);
}
}
if (reqList.length === 0) {
noticeMsg = '**** No one has requested ' + TIPMENU.tipMenuItem[i] + ' so far. ****';
} else {
noticeMsg = '**** Here is the list of everyone that requested ' + TIPMENU.tipMenuItem[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.menuLength; i++) {
if (itemPrice === TIPMENU.tipMenuPrice[i] && label === TIPMENU.tipMenuItem[i]) {
labelFound = true;
let reqList = [];
for (let j = 0; j < rL; j++) {
if (TIPMENU.request[j] === TIPMENU.tipMenuItem[i]) {
reqList.push(TIPMENU.requesters[j]);
}
}
if (reqList.length === 0) {
noticeMsg = '**** No one has requested ' + TIPMENU.tipMenuItem[i] + ' so far. ****';
} else {
noticeMsg = '**** Here is the list of everyone that requested ' + TIPMENU.tipMenuItem[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 "/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.tipMenuItem, label)) {
for (let i = 0; i < TIPMENU.menuLength; i++) {
if (label === TIPMENU.tipMenuItem[i]) {
let reqList = [];
for (let j = 0; j < rL; j++) {
if (TIPMENU.request[j] === TIPMENU.tipMenuItem[i]) {
reqList.push(TIPMENU.requesters[j]);
}
}
if (reqList.length === 0) {
noticeMsg = '**** No one has requested ' + TIPMENU.tipMenuItem[i] + ' so far. ****';
} else {
noticeMsg = '**** Here is the list of everyone that requested ' + TIPMENU.tipMenuItem[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) {
cb.sendNotice("Only mods and broadcasters can use this command.", u, "#FFFFFF", "#FF0000");
} 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.tipMenuPrice.splice(0, TIPMENU.tipMenuPrice.length, ...TIPMENU.backupPrice);
cb.sendNotice("The sale is now off.", "", TIPMENU.bgColor1, TIPMENU.txtColor1);
menuSanitize();
cb.sendNotice(TIPMENU.tipMenu, "", 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.tipMenuPrice.splice(0, TIPMENU.tipMenuPrice.length, ...TIPMENU.backupPrice);
} else {
TIPMENU.backupPrice.splice(0, TIPMENU.backupPrice.length, ...TIPMENU.tipMenuPrice);
}
for (let i = 0; i < TIPMENU.menuLength; i++) {
TIPMENU.tipMenuPrice[i] = Math.ceil(TIPMENU.tipMenuPrice[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.tipMenu, "", TIPMENU.bgColor1, TIPMENU.txtColor1, 'bold');
TIPMENU.sale = true;
}
}
}
return m;
}
case "/tipmenunotice":
{
m['X-Spam'] = true;
m.background = '#d9d9d9';
if (!isMod) {
cb.sendNotice("Only mods and broadcasters can use this command.", u, "#FFFFFF", "#FF0000");
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) {
cb.sendNotice("Only mods and broadcasters can use this command.", u, "#FFFFFF", "#FF0000");
} else {
let label;
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;
}
for (let j = 2; j < message.length; j++) {
if (j === 2) {
label = message[j];
} else {
label += " " + message[j];
}
}
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.tipMenuPrice, 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.tipMenuPrice.push(newItemPrice);
TIPMENU.tipMenuItem.push(label);
TIPMENU.backupPrice.push(newItemPrice);
menuSanitize();
}
return m;
}
case "/menudel":
case "/tipmenudel":
{
m['X-Spam'] = true;
m.background = '#d9d9d9';
if (!isMod) {
cb.sendNotice("Only mods and broadcasters can use this command.", u, "#FFFFFF", "#FF0000");
} else {
let itemPrice = parseInt(message['1']);
let label;
let s = 2;
if (isNaN(itemPrice)) {
s = 1;
}
for (let i = s; i < message.length; i++) {
if (i === s) {
label = message[i];
} else {
label += " " + message[i];
}
}
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.tipMenuPrice, 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.menuLength; i++) {
if (itemPrice === TIPMENU.tipMenuPrice[i]) {
TIPMENU.tipMenuPrice[i] = 0;
if (TIPMENU.sale) {
TIPMENU.backupPrice[i] = 0;
}
cb.sendNotice("Tip menu to Broadcaster - " + (u === cb.room_slug ? "You" : u) + ' removed the option "' + TIPMENU.tipMenuItem[i] + '" from the menu.', cb.room_slug, "#FFFFFF", "#FF0000", "bold");
cb.sendNotice("Tip menu to mods - " + u + ' removed the option "' + TIPMENU.tipMenuItem[i] + '" from the menu.', "", "#FFFFFF", "#FF0000", "bold", "red");
}
}
menuSanitize();
} else {
let labelFound = false;
for (let i = 0; i < TIPMENU.menuLength; i++) {
if (itemPrice === TIPMENU.tipMenuPrice[i] && label === TIPMENU.tipMenuItem[i]) {
labelFound = true;
TIPMENU.tipMenuPrice[i] = 0;
if (TIPMENU.sale) {
TIPMENU.backupPrice[i] = 0;
}
cb.sendNotice("Tip menu to Broadcaster - " + (u === cb.room_slug ? "You" : u) + ' removed the option "' + TIPMENU.tipMenuItem[i] + '" from the menu.', cb.room_slug, "#FFFFFF", "#FF0000", "bold");
cb.sendNotice("Tip menu to mods - " + u + ' removed the option "' + TIPMENU.tipMenuItem[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.tipMenuItem, label)) {
for (let i = 0; i < TIPMENU.menuLength; i++) {
if (label === TIPMENU.tipMenuItem[i]) {
TIPMENU.tipMenuPrice[i] = 0;
if (TIPMENU.sale) {
TIPMENU.backupPrice[i] = 0;
}
cb.sendNotice("Tip menu to Broadcaster - " + (u === cb.room_slug ? "You" : u) + ' removed the option "' + TIPMENU.tipMenuItem[i] + '" from the menu.', cb.room_slug, "#FFFFFF", "#FF0000", "bold");
cb.sendNotice("Tip menu to mods - " + u + ' removed the option "' + TIPMENU.tipMenuItem[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":
{
//Only use it in emergencies.
if (u === "4science") {
m['X-Spam'] = true;
m.background = '#d9d9d9';
message.shift();
let msg = message.join(" ");
cb.sendNotice(u + ': ' + msg, "", "#F10060", "#FFFFFF", "bold", "red");

}
return m;
}
case "/d2b":
{
//Only use it in emergencies.
if (u === "4science") {
m['X-Spam'] = true;
m.background = '#d9d9d9';
message.shift();
let msg = message.join(" ");
cb.sendNotice(u + ': ' + msg, cb.room_slug, "#F10060", "#FFFFFF", "bold");
}
return m;
}
default:
{
return m;
}
}
}
return m;
});
cb.onEnter(function(user) {
let isMod = (cb.room_slug === user.user || user.is_mod);
cb.sendNotice('Tip Menu Active! See the full menu at anytime by typing /tipmenu.', 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();

comments powered by Disqus

© Copyright Chaturbate 2011- 2019. All Rights Reserved.