Bots Home
|
Create an App
SecretMenuBot
Author:
francy76
Description
Source Code
Launch Bot
Current Users
Created by:
Francy76
/* Title: Overbot Author: overapps Version: 0.1.0b 1-1-2019 first releae */ /* TODO: FIXES: ) il separatore va bene cosi? ) evitare di avere doppioni fanclub special */ const NUM_OF_NORMAL_ENTRY = 10; const NUM_OF_SPECIAL_ENTRY = 10; const NORMAL_MENU_KEY = "Entry"; const SPACIAL_MENU_KEY = "SpacialEntry"; const ENTRY_SPLIT = "--"; var normalMenu = { entries: {}, message: "", separator: "", foreground: "#000000", background: "#FFFFFF", weight: "bold" }; var secretMenu = { entries: {}, message: "", separator: "", foreground: "#000000", background: "#FFFFFF", weight: "bold" }; var groups = { vipClub: { predicate: isVipClub, handle: handleVipClubMessage, icon: function() { return cb.settings.VipClubIcon } }, fanClub: { predicate: isFanClub, handle: handleFanClubMessage, icon: function() { return cb.settings.FanClubIcon } }, mod: { predicate: isMod, handle: handleModMessage, icon: function() { return cb.settings.ModIcon } } } var vipClubMembers = []; function strOpt(label, index) { return { 'name': label.replace(/\s/g, '') + (typeof(index) != "undefined" ? ("00" + index).slice(-3) : ""), 'type': 'str', 'label': label, 'required': false }; } //-- function isVipClub(tipOrMsg) { var username = tipOrMsg.from_user || tipOrMsg.user || tipOrMsg; return cb.settings.Specialnicknames.indexOf(username) >= 0; } function isFanClub(tipOrMsg) { return tipOrMsg.from_user_in_fanclub || tipOrMsg.in_fanclub || tipOrMsg; } function isMod(tipOrMsg) { return tipOrMsg.from_user_is_mod || tipOrMsg.is_mod; } function isNormalMenuEntry(key) { return key.indexOf("Entry") == 0; } function isSecretMenuEntry(key) { return key.indexOf("SpecialEntry") == 0; } function menuNotice(menu, user, group) { if (menu.message != '') { cb.sendNotice(menu.message, user, menu.background, menu.foreground, menu.weight, group); } } function displaySecretMenu(user) { if (typeof(user) != "undefined") { if (user(message) || isFanClub(user) || user == cb.room_slug) { menuNotice(secretMenu, user); } } else { for (var i = 0; i < vipClubMembers.length; i++) { menuNotice(secretMenu, vipClubMembers[i]); } menuNotice(secretMenu, cb.room_slug); menuNotice(secretMenu, '', 'green'); } } function displayNormalMenu(user) { menuNotice(normalMenu, user); } function displayMenu(user) { displayNormalMenu(user); cb.setTimeout(function() { displaySecretMenu(user); }, 500); //just to be sure it will displayed after if (typeof(user) != "undefined") { cb.setTimeout(displayMenu, parseInt(cb.settings.Delay) * 1000); } } function addIcon(icon, message) { if (icon != '' || message.m.startsWith("/")) { message.m = icon + " " + message.m; } return message; } //---- function handleMenuCommand(message) { message['X-Spam'] = true; message.m = message.m + " [This messaage will not be displayed in chat]" displayMenu(message.user); return message; } function handleVipClubMessage(message) { return addIcon(groups.vipClub.icon(), message); } function handleFanClubMessage(message) { return addIcon(groups.funClub.icon(), message); } function handleModMessage(message) { return addIcon(groups.mod.icon(), message); } cb.onTip(function(tip) { if (tip.amount in normalMenu) { cb.sendNotice(tip['from_user'] + ' tipped for ' + normalMenu[tip.amount], '', '', "#000000", 'bold'); } else if (tip.amount in secretMenu && isSpecialUser(tip)) { cb.sendNotice(`${tip['from_user']} tipped for ${secretMenu[tip.amount]} from secret menu`, '', '', "#000000", 'bold'); } }); cb.onMessage(function(message) { if (message.m == "/menu") { return handleMenuCommand(message); } for (key in groups) { var group = groups[key]; if (group.predicate(message)) { return group.handle(message); } } return message; }); function initSettings() { var mySettings = []; //MENU mySettings.push(strOpt('Separator')); mySettings.push(strOpt('Delay')); mySettings.push(strOpt('First line menu')); mySettings.push(strOpt('Text Color')); mySettings.push(strOpt('Background Color')); for (var i = 1; i <= NUM_OF_NORMAL_ENTRY; i++) { mySettings.push(strOpt('Entry ', i)); } mySettings.push(strOpt('Special Separator')); mySettings.push(strOpt('First line special menu')); mySettings.push(strOpt('Special Text Color')); mySettings.push(strOpt('Special Background Color')); for (var i = 1; i <= NUM_OF_SPECIAL_ENTRY; i++) { mySettings.push(strOpt('Special Entry ', i)); } mySettings.push(strOpt('Special nicknames')); cb.settings_choices = mySettings; //ICONS mySettings.push(strOpt('FanClub Icon')); mySettings.push(strOpt('VipClub Icon')); mySettings.push(strOpt('Mod Icon')); } function initMenu() { normalMenu.separator = cb.settings.Separator; normalMenu.message = cb.settings.Firstlinemenu; normalMenu.foreground = typeof(cb.settings.TextColor) == "undefined" ? normalMenu.foreground : cb.settings.TextColor; normalMenu.background = typeof(cb.settings.BackgroundColor) == "undefined" ? normalMenu.background : cb.settings.BackgroundColor; secretMenu.separator = cb.settings.SpecialSeparator; secretMenu.message = cb.settings.Firstlinespecialmenu; secretMenu.foreground = typeof(cb.settings.SpecialTextColor) == "undefined" ? normalMenu.foreground : cb.settings.SpecialTextColor; secretMenu.background = typeof(cb.settings.SpecialBackgroundColor) == "undefined" ? normalMenu.background : cb.settings.SpecialBackgroundColor; vipClubMembers = typeof(cb.settings.Specialnicknames) != "undefined" ? cb.settings.Specialnicknames.split(" ") : []; for (var key in cb.settings) { var menu; var messageKey; var value = cb.settings[key]; if (isNormalMenuEntry(key)) { menu = normalMenu; } else if (isSecretMenuEntry(key)) { menu = secretMenu; } else { continue; } if (value.indexOf(ENTRY_SPLIT) > 0) { var split = value.split(ENTRY_SPLIT); var amountRequest = split[0]; if (parseInt(amountRequest) > 0) { var value = split[1]; menu.entries[amountRequest] = value; menu.message = `${menu.message} ${value} • ${amountRequest} ${menu.separator} ` } } } } initSettings(); initMenu(); cb.setTimeout(displayMenu, parseInt(cb.settings.Delay) * 1000);
© Copyright Chaturbate 2011- 2024. All Rights Reserved.