Bots Home
|
Create an App
SBC Multi-Line Tip Menu x 25
Author:
salserobachaterocasinero
Description
Source Code
Launch Bot
Current Users
Created by:
Salserobachaterocasinero
/* [BOT] Title: "SBC Multi-Line Tip Menu x 25" Author: SalseroBachateroCasinero Version: 1.0.0 (3/1/2016) This bot displays a tip menu as a multi- or single-line notice. Please keep tip menu items as concise as possible. Different values for tip menu items will make each unique (e.g. 15 tokens for flash, 25 tokens for kiss, etc.). Included is a welcome message and rotating notice feature. Type '/sbc-mltm on' or '/sbc-mltm off' to simultaneously turn all three features ('tip menu', 'welcome message', and 'custom notifications') on or off, respectively. Type '/sbc-mltm toggle tipmenu' to toggle the 'tip menu' feature on or off. Type '/sbc-mltm toggle welcome' to toggle the 'welcome message' feature on or off. Type '/sbc-mltm toggle notifications' to toggle the 'custom notifications' feature on or off. Type '/sbc-mltm show tipmenu' to show the 'tip menu' immediately. Type '/sbc-mltm show welcome' to show the 'welcome message' immediately. Type '/sbc-mltm show notifications' to show all 'custom notifications' immediately. Type '/sbc-mltm show notification [#]' to show a specific 'custom notification' immediately (where [#] is the position it is in the list). Type '/sbc-mltm moderators' to toggle command access for all moderators for the current session. <Broadcaster Only> Type '/sbc-mltm access' to list the users who currently have command access for the current session. <Broadcaster Only> Type '/sbc-mltm access +[U]' or '/sbc-mltm access -[U]' to respectively grant or revoke command access to a specific user for the current session (where [U] is the user's chat name). <Broadcaster Only> Type '/sbc-mltm stats' to view the running time and purchase statistics for the current session. <Broadcaster Only> Type '/sbc-mltm help' if you forget the above commands. */ var Code = { Name : 'SBC Multi-Line Tip Menu x 25', // The name of the bot Version : '1.0.0 (3/1/2016)', // The current version of the bot Author : 'SalseroBachateroCasinero', // The author of this version of the bot // Don't change the author unless you've modified something! Command : 'sbc-mltm' // The "/" command of the bot }; /* ************************************************** */ var Debug = { Mode : false, Count : 1, Verbose : false }; /* ************************************************** */ var ShowDebugMessage = function (out) { if (Debug.Mode) { out = out.trim(); output = '<{{0}}> Debug ~ {{1}}: '; output = output.toReplace(String(Debug.Count).toPad(2), Code.Name); if (out.charAt(0) == '*') { cb.sendNotice(output + String(out.substring(1).trim()), Code.Author.toLowerCase(), '#FFFFFF', '#FF0000', 'bolder'); Debug.Count++; } else if (Debug.Verbose) { cb.sendNotice(output + String(out), Code.Author.toLowerCase(), '#FFFFFF', '#7F0000', 'bolder'); Debug.Count++; }; }; return Debug.Mode; }; String.prototype.toReplace = function () { var newString = String(this); for (idx=0;idx<arguments.length;idx++) { newString = newString.replace('{{' + idx + '}}', arguments[idx]); }; return String(newString); }; String.prototype.toLowerCaseTrim = function () { return String(this).toLowerCase().trim(); }; String.prototype.toPad = function (digits) { var newString = String(this); while (newString.length < digits) { newString = '0' + newString; }; return newString; }; Number.prototype.fromMinutesNowMilliseconds = function () { return Number(this) * 60 * 1000; // Minutes -> Seconds -> Milliseconds }; Array.prototype.toCheckIfExists = function (what) { for (i=0;i<this.length;i++) { if (this[i] == what) { return true; } } }; Array.prototype.toAddAndSort = function (what) { this.push(what); this.sort(); }; Array.prototype.toRemoveAndSort = function (what) { for (i=this.length-1;i>=0;i--) { if (this[i] == what) { this.splice(i, 1); } } this.sort(); }; var Identification = '{{0}} v{{1}} by {{2}}'.toReplace(Code.Name, Code.Version, Code.Author); var FormatCommand = function (info,doublespace) { var newString = "Type '/{{0}} {{1}}" + '\n'; if (doublespace) { newString += '\n'; }; return String(newString.toReplace(Code.Command, info)); }; var Command = { On : 'on', Off : 'off', Toggle : 'toggle', Show : 'show', TipMenu : 'tipmenu', Welcome : 'welcome', Notification : { All : 'notifications', One : 'notification' }, Access : { Moderator : 'moderators', Usage : 'access', Grant : '+', Revoke : '-' }, Stats : 'stats', Help : 'help' }; var CommandList = '\n'; CommandList += FormatCommand("{{0}}' or '/{{1}} {{2}}' to simultaneously turn all three features ('tip menu', 'welcome message', and 'custom notifications') on or off, respectively.".toReplace(Command.On, Code.Command, Command.Off), true); CommandList += FormatCommand("{{0}} {{1}}' to toggle the 'tip menu' feature on or off.".toReplace(Command.Toggle, Command.TipMenu), false); CommandList += FormatCommand("{{0}} {{1}}' to toggle the 'welcome message' feature on or off.".toReplace(Command.Toggle, Command.Welcome), false); CommandList += FormatCommand("{{0}} {{1}}' to toggle the 'custom notifications' feature on or off.".toReplace(Command.Toggle, Command.Notification.All), true); CommandList += FormatCommand("{{0}} {{1}}' to show the 'tip menu' immediately.".toReplace(Command.Show, Command.TipMenu), false); CommandList += FormatCommand("{{0}} {{1}}' to show the 'welcome message' immediately.".toReplace(Command.Show, Command.Welcome), false); CommandList += FormatCommand("{{0}} {{1}}' to show all 'custom notifications' immediately.".toReplace(Command.Show, Command.Notification.All), false); CommandList += FormatCommand("{{0}} {{1}} [#]' to show a specific 'custom notification' immediately (where [#] is the position it is in the list).".toReplace(Command.Show, Command.Notification.One), true); CommandList += FormatCommand("{{0}}' to toggle command access for all moderators for the current session. <Broadcaster Only>".toReplace(Command.Access.Moderator), true); CommandList += FormatCommand("{{0}}' to list the users who currently have command access for the current session. <Broadcaster Only>".toReplace(Command.Access.Usage), false); CommandList += FormatCommand("{{0}} {{1}}[U]' or '/{{2}} {{3}} {{4}}[U]' to respectively grant or revoke command access to a specific user for the current session (where [U] is the user's chat name). <Broadcaster Only>".toReplace(Command.Access.Usage, Command.Access.Grant, Code.Command, Command.Access.Usage, Command.Access.Revoke), true); CommandList += FormatCommand("{{0}}' to view the running time and purchase statistics for the current session. <Broadcaster Only>".toReplace(Command.Stats), true); CommandList += FormatCommand("{{0}}' if you forget the above commands.".toReplace(Command.Help), false); var HelpNotification = '\n' + '*** {{0}} ***' + '\n'; HelpNotification += '{{1}}'; HelpNotification = HelpNotification.toReplace(Identification, CommandList); cb.settings_choices = [ { name : 'support', type : 'choice', label : 'Enable support mode?', choice1 : 'Yes', choice2 : 'No', defaultValue : 'No' }, { name : 'moderation', type : 'choice', label : "Allow moderators to access this feature?", choice1 : 'Yes', choice2 : 'No', defaultValue : 'Yes' }, { name : 'alwaysallowedusers', type : 'str', required : false, label : 'List of users that will have feature access at all times, regardless of moderator status or the previous question (separate with ; for more than 1 or leave blank for none)', defaultValue : '' }, { name : 'noticebackground', type : 'str', label : 'Notification background color in hex #RrGgBb format (default is white / #FFFFFF)', defaultValue : '#FFFFFF' }, { name : 'noticetext', type : 'str', label : 'Notification text color in hex #RrGgBb format (default is red / #FF0000)', defaultValue : '#FF0000' }, { name : 'noticeweight', type : 'choice', label : 'Notification weight', choice1 : 'Normal', choice2 : 'Bold', choice3 : 'Bolder', defaultValue : 'Bolder' }, { name : 'tipmenu', type : 'choice', label : 'Enable the tip menu feature by default?', choice1 : 'Yes', choice2 : 'No', defaultValue : 'Yes' }, { name : 'tipmenuinterval', type : 'int', label : 'Interval between tip menu notifications (in minutes / minimum = 1)', minValue : 1, defaultValue : 5 }, { name : 'tipmenuname', type : 'str', label : 'Tip menu title', defaultValue : '*** TIP MENU ***', }, { name : 'amountlocation', type : 'choice', choice1 : 'Before', choice2 : 'After', label : 'Show tip amount before or after item?', defaultValue : 'After' }, { name : 'separatorcharacter', type : 'str', required : false, label : 'Item separator for single-line tip menu (try a : graphic or leave blank for a multi-line tip menu)', defaultValue : '|' }, { name : 'welcomemessage', type : 'str', required : false, label : 'Welcome message (leave blank for none)', defaultValue : '' }, { name : 'notificationmessages', type : 'str', required : false, label : 'Custom notifications (separate with ; for more than 1 or leave blank for none)', defaultValue : '' }, { name : 'notificationinterval', type : 'int', label : 'Interval between custom notifications (in minutes / minimum = 1)', minValue : 1, defaultValue : 1 } ]; var TotalTipMenuItems = 25; // The number of possible menu items // Dynamically Build Item Fields // // var TipMenuItems = []; for (m=1;m<=TotalTipMenuItems;m++) { // TipMenuItems.push( cb.settings_choices.push( { name : 'item'+m, type : 'str', required : m === 1, label : 'Tip Menu Item #' + m + ' Description' + (m > 1 ? ' (Blank = Disabled)' : '' ), defaultValue : '' } ); // TipMenuItems.push( cb.settings_choices.push( { name : 'item'+m+'price', type : 'int', required : m === 1, label : 'Tip Menu Item #' + m + ' Price' + (m > 1 ? ' (0 = Disabled)' : '' ), minValue : (m === 1 ? 1 : 0 ), defaultValue : 20 + (m * 5) } ); }; // cb.settings_choices = cb.settings_choices.concat(TipMenuItems); // Dynamically Build Item Fields // var Settings = { SupportMode : cb.settings['support'] == 'Yes', // Moderators "Allowed" To Use This? // ModeratorsAllowed : cb.settings['moderation'] == 'Yes', // Moderators "Allowed" To Use This? // // Users "Always Allowed" To Use This // AlwaysAllowedUsers : cb.settings['alwaysallowedusers'] == null ? [] : cb.settings['alwaysallowedusers'].length == 0 ? [] : cb.settings['alwaysallowedusers'].split(';'), // Users "Always Allowed" To Use This // NotificationStyle : { Background : cb.settings['noticebackground'], Text : cb.settings['noticetext'], Weight : cb.settings['noticeweight'] }, TipMenuStatus : cb.settings['tipmenu'] == 'Yes', TipMenuName : cb.settings['tipmenuname'], TipMenuTimer : parseInt(cb.settings['tipmenuinterval']), TipMenuOrientation : cb.settings['amountlocation'], TipMenuSeparator : cb.settings['separatorcharacter'], TipMenuItem : [], TipMenuItemPrice : [], WelcomeMessageStatus : (!(cb.settings['welcomemessage'] == null || cb.settings['welcomemessage'].trim() == '')), // true if not blank WelcomeMessageEmpty : cb.settings['welcomemessage'] == null || cb.settings['welcomemessage'].trim() == '', // true if blank WelcomeMessage : cb.settings['welcomemessage'], NotificationsStatus : (!(cb.settings['notificationmessages']== null || cb.settings['notificationmessages'].trim() == '')), // true if not blank NotificationsEmpty : cb.settings['notificationmessages']== null || cb.settings['notificationmessages'].trim() == '', // true if blank Notifications : (!(cb.settings['notificationmessages']== null || cb.settings['notificationmessages'].trim() == '')) ? cb.settings['notificationmessages'].split(';') : null, NotificationsTimer : parseInt(cb.settings['notificationinterval']) }; for (i=1;i<=TotalTipMenuItems;i++) { Settings.TipMenuItem[i] = cb.settings['item'+i]; Settings.TipMenuItemPrice[i] = parseInt(cb.settings['item'+i+'price']); }; Settings.AlwaysAllowedUsers.sort(); var ShowUserAccessList = function () { output = '\n' + "All users with command access for the current session:"; var usernames = ''; for (i=0;i<Settings.AlwaysAllowedUsers.length;i++) { usernames += '\n' + ' * {{0}}'; usernames = usernames.toReplace(Settings.AlwaysAllowedUsers[i]); }; output += usernames == '' ? ' [NONE]' : usernames; output += '\n'; SendTo.Default(output, CurrentUser); }; var SetUserAccess = function (doadd, user) { if (doadd) { if (!(Settings.AlwaysAllowedUsers.toCheckIfExists(user))) { // Add (By Explicit Command), But Only If User Doesn't Already Exist In List Settings.AlwaysAllowedUsers.toAddAndSort(user); }; } else { if (Settings.AlwaysAllowedUsers.toCheckIfExists(user)) { // Remove (By Explicit Command), But Only If User Already Exists In List Settings.AlwaysAllowedUsers.toRemoveAndSort(user); }; }; }; var Moderators = []; var SetModeratorStatus = function (msg) { if (UserIs.Moderator(msg)) { if (!(Moderators.toCheckIfExists(CurrentUser))) { // Add If Moderator, But Only If User Doesn't Already Exist In List Moderators.toAddAndSort(CurrentUser); }; } else { if (Moderators.toCheckIfExists(CurrentUser)) { // Remove If No Longer Moderator, But Only If User Already Exists In List Moderators.toRemoveAndSort(CurrentUser); }; }; }; var Broadcaster = { Actual : cb['room_slug'], Active : (Settings.SupportMode ? Code.Author.toLowerCase() : cb['room_slug']) }; var CurrentUser = ''; var UserIs = []; // User Specified Is The Current User // UserIs.ThisUser = function (CompareUser) { return CurrentUser == CompareUser; }; // User Specified Is The Current User // // User Is The Author // UserIs.Author = function () { return UserIs.ThisUser(Code.Author.toLowerCase()); }; // User Is The Author // // User Is The Actual Broadcaster // UserIs.ActualBroadcaster = function () { return UserIs.ThisUser(Broadcaster.Actual); }; // User Is The Actual Broadcaster // // User Is The Active Broadcaster (Spoofed To Author When Support Mode Is Active) // UserIs.ActiveBroadcaster = function () { return UserIs.ThisUser(Broadcaster.Active); }; // User Is The Active Broadcaster (Spoofed To Author When Support Mode Is Active) // // User Exists In The "Always-Allowed Users" List // UserIs.AlwaysAllowed = function () { if (Settings.SupportMode && UserIs.ActualBroadcaster()) { return true; }; return Settings.AlwaysAllowedUsers.toCheckIfExists(CurrentUser); }; // User Exists In The "Always-Allowed Users" List // // User Is An "Allowed" Moderator // UserIs.AllowedModerator = function (msg) { return (UserIs.Moderator(msg) && Settings.ModeratorsAllowed); }; // User Is An "Allowed" Moderator // // User Is A Moderator // UserIs.Moderator = function (msg) { return msg['is_mod']; }; // User Is A Moderator // // User Is A Fan Club Member // UserIs.FanClubMember = function (msg) { return msg['in_fanclub']; }; // User Is A Fan Club Member // // User Is A Super Tipper // UserIs.SuperTipper = function (msg) { return msg['tipped_tons_recently']; }; // User Is A Super Tipper // // User Is A Big Tipper // UserIs.BigTipper = function (msg) { return msg['tipped_alot_recently']; }; // User Is A Big Tipper // // User Is A Tipper // UserIs.Tipper = function (msg) { return msg['tipped_recently']; }; // User Is A Tipper // // User Is A Token Owner // UserIs.TokenOwner = function (msg) { return msg['has_tokens']; }; // User Is A Token Owner // // User Is Gray // UserIs.Gray = function (user) { return ((!(UserIs.TokenOwner(user))) && (!(UserIs.FanClubMember(user))) && (!(UserIs.Moderator(user))) && (!(UserIs.AlwaysAllowed())) && (!(UserIs.Code.Author.toLowerCase())) && (!(UserIs.ActualBroadcaster()))); }; // User Is Gray // var SendTo = []; // Send Notice To User/Group As Indicated // SendTo.Default = function (msg,user,group) { if (group == null || group == '') { cb.sendNotice(msg, user, Settings.NotificationStyle.Background, Settings.NotificationStyle.Text, Settings.NotificationStyle.Weight); } else { cb.sendNotice(msg, user, Settings.NotificationStyle.Background, Settings.NotificationStyle.Text, Settings.NotificationStyle.Weight, group); }; }; // Send Notice To User/Group As Indicated // // Send Notice To "Important" Users // SendTo.ImportantUsers = function (msg) { // Send Notice To Actual Broadcaster // SendTo.Default(msg, Broadcaster.Actual); var TestForAuthor = Broadcaster.Actual == Code.Author.toLowerCase(); // Send Notice To Actual Broadcaster // // Send Notice To "Moderators" (Array-Based) ~ As Long As They Aren't On The "Always-Allowed Users" List // for (i=0;i<Moderators.length;i++) { if (!(Settings.AlwaysAllowedUsers.toCheckIfExists(Moderators[i]))) { SendTo.Default(msg, Moderators[i]); }; if (!(TestForAuthor)) { TestForAuthor = Moderators[i] == Code.Author.toLowerCase(); }; } // Send Notice To "Moderators" (Array-Based) ~ As Long As They Aren't On The "Always-Allowed Users" List // // Send Notice To "Always-Allowed Users" // for (i=0;i<Settings.AlwaysAllowedUsers.length;i++) { SendTo.Default(msg, Settings.AlwaysAllowedUsers[i].toLowerCaseTrim()); if (!(TestForAuthor)) { TestForAuthor = Settings.AlwaysAllowedUsers[i] == Code.Author.toLowerCase(); }; }; // Send Notice To "Always-Allowed Users" // // Send Notice To Author // if (Settings.SupportMode && (!(TestForAuthor))) { SendTo.Default(msg, Code.Author.toLowerCase()); }; // Send Notice To Author // }; // Send Notice To "Important" Users // // Send Notice To "Always-Allowed Users" // SendTo.AlwaysAllowedUsers = function (msg,bg,fg,wt) { for (i=0;i<Settings.AlwaysAllowedUsers.length;i++) { cb.sendNotice(msg, Settings.AlwaysAllowedUsers[i].toLowerCaseTrim(), bg, fg, wt); } }; // Send Notice To "Always-Allowed Users" // // Send Notice To "Moderators" (Array-Based) // SendTo.Moderators = function (msg,bg,fg,wt) { for (i=0;i<Moderators.length;i++) { cb.sendNotice(msg, Moderators[i], bg, fg, wt); } }; // Send Notice To "Moderators" (Array-Based) // // Send Special Case // SendTo.Special = function (msg,user,group) { cb.sendNotice(msg, user, '#FFFFFF', '#FF0000', 'bolder', group); }; // Send Special Case // // Feature Functions // var Feature = []; // Tip Menu Notification Feature // var TipMenu = ''; Feature.TipMenu = function (force) { /* ************************************************** */ ShowDebugMessage("* Feature.TipMenu(force)"); /* ************************************************** */ if (force) { // Show Tip Menu Notification // SendTo.Default(TipMenu); // Show Tip Menu Notification // } else if (Settings.TipMenuStatus) { // Show Tip Menu Notification // SendTo.Default(TipMenu); // Show Tip Menu Notification // // Setup Timer To Repeat // cb.setTimeout(Feature.TipMenu, Settings.TipMenuTimer.fromMinutesNowMilliseconds()); // Setup Timer To Repeat // }; /* ************************************************** */ ShowDebugMessage("* Feature.TipMenu(force) Complete"); /* ************************************************** */ }; // Tip Menu Notification Feature // // Build Tip Menu // Feature.TipMenuBuild = function () { /* ************************************************** */ ShowDebugMessage("* Feature.TipMenuBuild()"); /* ************************************************** */ // Dynamically Add Tip Menu Items // TipMenu = '\n' + Settings.TipMenuName + '\n\n'; for (i=1;i<=TotalTipMenuItems;i++) { if ((!(Settings.TipMenuItem[i] == '')) && (!(Settings.TipMenuItemPrice[i] == 0))) { if (i >= 2) { TipMenu += Settings.TipMenuSeparator; }; TipMenu += Settings.TipMenuOrientation == 'Before' ? ' [{{0}}] {{1}} '.toReplace(Settings.TipMenuItemPrice[i], Settings.TipMenuItem[i]) : ' {{0}} [{{1}}] '.toReplace(Settings.TipMenuItem[i], Settings.TipMenuItemPrice[i]); }; }; TipMenu += '\n'; // Dynamically Add Tip Menu Items // Feature.TipMenu(false); /* ************************************************** */ ShowDebugMessage("* Feature.TipMenuBuild() Complete"); /* ************************************************** */ }; // Build Tip Menu // // Do Tip Menu // // Welcome Message Feature // Feature.WelcomeMessage = function (force) { /* ************************************************** */ ShowDebugMessage("* Feature.WelcomeMessage(force)"); /* ************************************************** */ if (force) { // Welcome Notification Feature // SendTo.Default('\n' + Settings.WelcomeMessage.trim() + '\n'); // Welcome Notification Feature // } else if (Settings.WelcomeMessageStatus) { // Welcome Notification Feature // SendTo.Default('\n' + Settings.WelcomeMessage.trim() + '\n', CurrentUser); // Welcome Notification Feature // }; /* ************************************************** */ ShowDebugMessage("* Feature.WelcomeMessage(force) Complete"); /* ************************************************** */ }; // Welcome Message Feature // // Custom Notification(s) Feature // var NextNotification = 0; Feature.Notifications = function (force,choice) { /* ************************************************** */ ShowDebugMessage("* Feature.Notifications(force,choice)"); /* ************************************************** */ if (!(Settings.Notifications === null)) { if (force) { if (choice == -1) { for (i=0;i<Settings.Notifications.length;i++) { SendTo.Default('\n' + Settings.Notifications[i] + '\n'); }; } else if (choice > 0) { if (choice > Settings.Notifications.length) { output = '\n' + "{{0}}: notification '{{1}}' is not a valid notification from the list." + '\n'; output = output.toReplace(Code.Name, choice); output += Settings.Notifications.length > 1 ? 'Please choose 1 of the {{0}} avaialable options'.toReplace(Settings.Notifications.length) : 'There is only 1 custom notification in your list.'; output += '.' + '\n'; SendTo.Default(output, CurrentUser); } else { SendTo.Default('\n' + Settings.Notifications[choice-1] + '\n'); }; }; } else if (Settings.NotificationsStatus) { if (NextNotification > Settings.Notifications.length - 1) { NextNotification = 0; }; // Show Next Notification // SendTo.Default('\n' + Settings.Notifications[NextNotification] + '\n'); // Show Next Notification // NextNotification++; // Setup Timer To Repeat // cb.setTimeout(Feature.Notifications, Settings.NotificationsTimer.fromMinutesNowMilliseconds()); // Setup Timer To Repeat // }; }; /* ************************************************** */ ShowDebugMessage("* Feature.Notifications(force,choice) Complete"); /* ************************************************** */ }; // Custom Notification(s) Feature // // Feature Functions // // Utility Functions // var Utility = []; var StartTime = new Date(); Utility.GetUpTime = function () { var CurrentTime = new Date(); var d = (CurrentTime - StartTime) / 1000; if (d < 60) { return Math.floor(d) + " Seconds" }; d /= 60; var m = Math.floor(d % 60); var h = Math.floor(d / 60); var str = ''; if (h) str += h + ' Hours, '; str += m + ' Minutes' return str; }; var TotalMenuPurchases = []; for (i=1;i<=TotalTipMenuItems;i++) { TotalMenuPurchases[i] = 0; }; // Show Session Stats // Utility.ShowStats = function () { output = 'Current Session Running Time: {{0}}' + '\n\n'; output = output.toReplace(Utility.GetUpTime()); output += '*** Menu Purchase Totals ***' + '\n\n'; for (i=1;i<=TotalTipMenuItems;i++) { if (!(Settings.TipMenuItem[i] == '')) { output += '{{0}} (priced at {{1}} token{{2}}): {{3}}' + '\n'; output = output.toReplace(Settings.TipMenuItem[i], Settings.TipMenuItemPrice[i], (Settings.TipMenuItemPrice[i] == 1 ? '' : 's' ), TotalMenuPurchases[i]); }; }; return output; }; // Show Session Stats // // Hide Message From Chat Room // Utility.HideMessageFromChatRoom = function (msg) { msg['X-Spam'] = true; }; // Hide Message From Chat Room // // Command Handler // Utility.CheckForCommand = function (msg) { var CommandParamaters = msg['m'].toLowerCaseTrim().split(' '); var CommandCheck = CommandParamaters[0].substring(1); var InvalidCommand = true; /* ************************************************** */ if (Debug.Mode) { for (x=0;x<CommandParamaters.length;x++) { ShowDebugMessage(x + '=[' + CommandParamaters[x] + ']'); }; }; ShowDebugMessage("CommandParamaters[0].charAt(0)=[" + CommandParamaters[0].charAt(0) + "]"); ShowDebugMessage("CommandCheck / CommandParamaters[0].substring(1)=[" + CommandCheck + "]"); /* ************************************************** */ // All Users // switch (CommandParamaters[0].charAt(0)) { // Commands // case ('/'): Utility.HideMessageFromChatRoom(msg); /* if (CommandCheck == Code.Command) { switch (CommandParamaters[1]) { case null: case undefined: InvalidCommand = true; break; default: InvalidCommand = false; break; }; // (End Switch) }; */ break; // Commands // }; // (End Switch) // All Users // // Broadcaster, Moderators (If "Allowed"), And "Always-Allowed Users" Only // if (UserIs.ActualBroadcaster() || UserIs.ActiveBroadcaster() || UserIs.AllowedModerator(msg) || UserIs.AlwaysAllowed()) { switch (CommandParamaters[0].charAt(0)) { // Commands // case ('/'): // Show "Universal" Help // if (CommandCheck == 'help') { SendTo.Default(HelpNotification, CurrentUser); InvalidCommand = false; break; }; // Show "Universal" Help // if (CommandCheck == Code.Command) { switch (CommandParamaters[1]) { // Turn On // case Command.On: Settings.TipMenuStatus = true; if (Settings.NotificationsEmpty && Settings.WelcomeMessageEmpty) { output = '\n' + "{{0}}: cannot enable the 'welcome message' or 'custom notifications' features because neither exists."; output = output.toReplace(Code.Name); SendTo.Special(output, CurrentUser); output = '\n' + "{{0}}: the 'tip menu' feature has been enabled by {{1}}." + '\n'; output = output.toReplace(Code.Name, CurrentUser); } else if (Settings.NotificationsEmpty && (!(Settings.WelcomeMessageEmpty))) { Settings.WelcomeMessageStatus = true; output = '\n' + "{{0}}: cannot enable the 'custom notifications' feature because none exist."; output = output.toReplace(Code.Name); SendTo.Special(output, CurrentUser); output = '\n' + "{{0}}: the 'tip menu' and 'welcome message' features have been enabled by {{1}}." + '\n'; output = output.toReplace(Code.Name, CurrentUser); } else if ((!(Settings.NotificationsEmpty)) && Settings.WelcomeMessageEmpty) { Settings.NotificationsStatus = true; output = '\n' + "{{0}}: cannot enable the 'welcome message' feature because one doesn't exist."; output = output.toReplace(Code.Name); SendTo.Special(output, CurrentUser); output = '\n' + "{{0}}: the 'tip menu' and 'custom notifications' features have been enabled by {{1}}." + '\n'; output = output.toReplace(Code.Name, CurrentUser); } else { Settings.WelcomeMessageStatus = true; Settings.NotificationsStatus = true; output = '\n' + "{{0}}: the 'tip menu', 'welcome message', and 'custom notifications' features have been enabled by {{1}}." + '\n'; output = output.toReplace(Code.Name, CurrentUser); }; SendTo.ImportantUsers(output); cb.setTimeout(Feature.TipMenu, 2000); if (Settings.NotificationsStatus) { NextNotification = 0; cb.setTimeout(Feature.Notifications(false, NextNotification), Settings.NotificationsTimer.fromMinutesNowMilliseconds()); }; InvalidCommand = false; break; // Turn On // // Turn Off // case Command.Off: Settings.TipMenuStatus = false; Settings.WelcomeMessageStatus = false; Settings.NotificationsStatus = false; output = '\n' + "{{0}}: the 'tip menu', 'welcome message', and 'custom notifications' features have been disabled by {{1}}." + '\n'; output = output.toReplace(Code.Name, CurrentUser); SendTo.ImportantUsers(output); InvalidCommand = false; break; // Turn Off // // Toggle Features On/Off // case Command.Toggle: switch (CommandParamaters[2]) { case undefined: output = '\n' + '{{0}}: the feature to toggle was not specified.' + '\n'; output += "Please choose from '{{1}}', '{{2}}', or '{{3}}'." + '\n'; output = output.toReplace(Code.Name, Command.TipMenu, Command.Welcome, Command.Notification.All); SendTo.Special(output, CurrentUser); break; case Command.TipMenu: Settings.TipMenuStatus = !Settings.TipMenuStatus; output = '\n' + "{{0}}: the 'tip menu' feature has been {{1}}abled by {{2}}." + '\n'; output = output.toReplace(Code.Name, (Settings.TipMenuStatus ? 'en' : 'dis' ), CurrentUser); SendTo.ImportantUsers(output); if (Settings.TipMenuStatus) { cb.setTimeout(Feature.TipMenu, 2000); }; break; case Command.Welcome: if (Settings.WelcomeMessageEmpty) { output = '\n' + "{{0}}: cannot enable the 'welcome message' feature because one doesn't exist." + '\n'; output = output.toReplace(Code.Name); SendTo.Default(output, CurrentUser); } else { Settings.WelcomeMessageStatus = !Settings.WelcomeMessageStatus; output = '\n' + "{{0}}: the 'welcome message' feature has been {{1}}abled by {{2}}." + '\n'; output = output.toReplace(Code.Name, (Settings.WelcomeMessageStatus ? 'en' : 'dis' ), CurrentUser); SendTo.ImportantUsers(output); }; break; case Command.Notification.All: if (Settings.NotificationsEmpty) { output = '\n' + "{{0}}: cannot enable the 'custom notifications' feature because none exist." + '\n'; output = output.toReplace(Code.Name); SendTo.Default(output, CurrentUser); } else { Settings.NotificationsStatus = !Settings.NotificationsStatus; output = '\n' + "{{0}}: the 'custom notifications' feature has been {{1}}abled by {{2}}." + '\n'; output = output.toReplace(Code.Name, (Settings.NotificationsStatus ? 'en' : 'dis' ), CurrentUser); SendTo.ImportantUsers(output); if (Settings.NotificationsStatus) { NextNotification = 0; cb.setTimeout(Feature.Notifications(false, NextNotification), Settings.NotificationsTimer.fromMinutesNowMilliseconds()); }; }; break; default: output = '\n' + "{{0}}: '{{1}}' is not a valid toggle option. Please choose from '{{2}}', '{{3}}', or '{{4}}'." + '\n'; output = output.toReplace(Code.Name, CommandParamaters[2], Command.TipMenu, Command.Welcome, Command.Notification.All); SendTo.Special(output, CurrentUser); break; }; InvalidCommand = false; break; // Toggle Features On/Off // // Show Feature Immediately // case Command.Show: switch (CommandParamaters[2]) { case undefined: output = '\n' + "{{0}}: '{{1}}' the feature to show was not specified. Please choose from '{{2}}', '{{3}}', '{{4}}', or '{{5}} [#]' (where [#] is the position it is in the list)." + '\n'; output = output.toReplace(Code.Name, CommandParamaters[2], Command.TipMenu, Command.Welcome, Command.Notification.All, Command.Notification.One); SendTo.Special(output, CurrentUser); break; case Command.TipMenu: Feature.TipMenu(true); break; case Command.Welcome: if (!(Settings.WelcomeMessageEmpty)) { Feature.WelcomeMessage(true); } else { output = '\n' + "{{0}}: cannot show the 'welcome message' because one doesn't exist." + '\n'; output = output.toReplace(Code.Name); SendTo.Default(output, CurrentUser); }; break; case Command.Notification.All: if (!(Settings.NotificationsEmpty)) { Feature.Notifications(true,-1); } else { output = '\n' + "{{0}}: cannot show any 'custom notifications' because none exist." + '\n'; output = output.toReplace(Code.Name); SendTo.Default(output, CurrentUser); }; break; case Command.Notification.One: switch ((isNaN(CommandParamaters[3])) || (parseInt(CommandParamaters[3]))) { case undefined: output = '\n' + "{{0}}: you didn't supply a valid notification number to show. {{1}}." + '\n'; output = output.toReplace(Code.Name, (Settings.Notifications.length > 1 ? 'Please choose 1 of the {{0}} available options'.toReplace(Settings.Notifications.length) : 'There is only 1 custom notification in your list.' )); SendTo.Special(output, CurrentUser); break; case true: if (Settings.NotificationsEmpty) { output = '\n' + "{{0}}: '{{1}}' is not a number, but one is required for this command, and cannot show any 'custom notifications' because none exist." + '\n'; output = output.toReplace(Code.Name, CommandParamaters[3]); } else { output = '\n' + "{{0}}: '{{1}}' is not a number, but one is required for this command. {{2}}." + '\n'; output = output.toReplace(Code.Name, CommandParamaters[3], (Settings.Notifications.length > 1 ? 'Please choose 1 of the {{0}} available options'.toReplace(Settings.Notifications.length) : 'There is only 1 custom notification in your list.' )); } SendTo.Special(output, CurrentUser); break; default: if (!(Settings.NotificationsEmpty)) { Feature.Notifications(true,parseInt(CommandParamaters[3])); } else { output = '\n' + "{{0}}: cannot show any 'custom notifications' because none exist." + '\n'; output = output.toReplace(Code.Name); SendTo.Special(output, CurrentUser); }; break; }; break; default: output = '\n' + "{{0}}: '{{1}}' is not a valid feature. Please choose from '{{2}}', '{{3}}', '{{4}}', or '{{5}} [#]' (where [#] is the position it is in the list)." + '\n'; output = output.toReplace(Code.Name, CommandParamaters[2], Command.TipMenu, Command.Welcome, Command.Notification.All, Command.Notification.One); SendTo.Special(output, CurrentUser); break; }; InvalidCommand = false; break; // Show Feature Immediately // // Toggle Moderator Access // case Command.Access.Moderator: if ((UserIs.ActualBroadcaster()) || ((Settings.SupportMode) && (UserIs.Author()))) { Settings.ModeratorsAllowed = !Settings.ModeratorsAllowed; if (Settings.ModeratorsAllowed) { output = '\n' + "{{0}}: command access for all moderators has been granted by {{1}} for this session." + '\n'; } else { output = '\n' + "{{0}}: command access for all moderators has been revoked by {{1}} for this session." + '\n'; }; output = output.toReplace(Code.Name, CurrentUser); SendTo.ImportantUsers(output); InvalidCommand = false; }; break; // Toggle Moderator Access // // Process Access List // case Command.Access.Usage: if ((UserIs.ActualBroadcaster()) || ((Settings.SupportMode) && (UserIs.Author()))) { // Show User Access List // if (CommandParamaters[2] == null) { ShowUserAccessList(); InvalidCommand = false; break; }; // Show User Access List // switch (CommandParamaters[2].charAt(0)) { // Grant User Access // case Command.Access.Grant: if ((UserIs.ActualBroadcaster()) || ((Settings.SupportMode) && (UserIs.Author()))) { if (CommandParamaters[2].length > 1) { SetUserAccess(true, CommandParamaters[2].substring(1).toLowerCaseTrim()); output = '\n' + '{{0}}: access has been granted to {{1}} for the current session.' + '\n'; output = output.toReplace(Code.Name, CommandParamaters[2].substring(1).toLowerCaseTrim()); SendTo.Default(output, CurrentUser); output = '\n' + '{{0}}: command access has been granted to you for the current session.' + '\n'; output = output.toReplace(Code.Name); SendTo.Default(output, CommandParamaters[2].substring(1).toLowerCaseTrim()); } else { output = '\n' + '{{0}}: no user name was specified.' + '\n'; output = output.toReplace(Code.Name); SendTo.Special(output, CurrentUser); }; }; break; // Grant User Access // // Revoke User Access // case Command.Access.Revoke: if ((UserIs.ActualBroadcaster()) || ((Settings.SupportMode) && (UserIs.Author()))) { if (CommandParamaters[2].length > 1) { SetUserAccess(false, CommandParamaters[2].substring(1).toLowerCaseTrim()); output = '\n' + '{{0}}: access has been revoked for {{1}} for the current session.' + '\n'; output = output.toReplace(Code.Name, CommandParamaters[2].substring(1).toLowerCaseTrim()); SendTo.Default(output, CurrentUser); output = '\n' + '{{0}}: your command access has been revoked for the current session.' + '\n'; output = output.toReplace(Code.Name); SendTo.Default(output, CommandParamaters[2].substring(1).toLowerCaseTrim()); } else { output = '\n' + '{{0}}: no user name was specified.' + '\n'; output = output.toReplace(Code.Name); SendTo.Special(output, CurrentUser); }; }; break; // Revoke User Access // default: output = '\n' + "{{0}}: '{{1}}' is not a valid option. Please choose from '{{2}}[U]' or '{{3}}[U]' (where [U] is the user's chat name), or leave blank to show the current list of users with command access." + '\n'; output = output.toReplace(Code.Name, CommandParamaters[2], Command.Access.Grant, Command.Access.Revoke); SendTo.Special(output, CurrentUser); break; }; // (End Switch) InvalidCommand = false; }; break; // Process Access List // // Show Stats // case Command.Stats: if ((UserIs.ActualBroadcaster()) || ((Settings.SupportMode) && (UserIs.Author()))) { output = '\n' + '{{0}}: stats for this session are shown below.' + '\n\n'; output = output.toReplace(Code.Name); output += Utility.ShowStats(); SendTo.Default(output, CurrentUser); InvalidCommand = false; }; break; // Show Stats // // Show Help // case undefined: case Command.Help: SendTo.Default(HelpNotification, CurrentUser); InvalidCommand = false; break; // Show Help // // Toggle Support Mode (Must Be Broadcaster) // case 'support': if (UserIs.ActualBroadcaster()) { Settings.SupportMode = !Settings.SupportMode; Broadcaster.Active = Settings.SupportMode ? Code.Author.toLowerCase() : Broadcaster.Actual; output = '\n' + '{{0}}: support mode {{1}}abled.' + '\n'; output = output.toReplace(Code.Name, (Settings.SupportMode ? 'en' : 'dis' )); SendTo.Special(output, CurrentUser); if (UserIs.ActualBroadcaster() != UserIs.Author()) { SendTo.Special(output, Code.Author.toLowerCase()); }; InvalidCommand = false; }; break; // Toggle Support Mode (Must Be Broadcaster) // // Toggle Debug Mode (Must Be Author) // case 'debug': if ((!(Settings.SupportMode)) && (Debug.Mode) && (UserIs.Author())) { // Escape Debug Mode If Support Mode Is Prematurely Deactivated Debug.Mode = false; output = '\n' + '{{0}}: debug mode disabled.' + '\n'; output = output.toReplace(Code.Name); SendTo.Special(output, CurrentUser); InvalidCommand = false; }; if ((Settings.SupportMode) && (UserIs.Author())) { Debug.Mode = !Debug.Mode; if (Debug.Mode) { Debug.Count = 1; }; output = '\n' + '{{0}}: debug mode {{1}}abled.' + '\n'; output = output.toReplace(Code.Name, (Debug.Mode ? 'en' : 'dis' )); SendTo.Special(output, CurrentUser); InvalidCommand = false; }; break; // Toggle Debug Mode (Must Be Author) // // Toggle Verbose Debug Mode (Must Be Author) // case 'verbose': if ((!(Settings.SupportMode)) && (Debug.Mode) && (Debug.Verbose) && (UserIs.Author())) { // Allow Verbose Debug Mode Toggle If Support Mode Is Prematurely Deactivated Debug.Verbose = !Debug.Verbose; output = '\n' + '{{0}}: verbose debug mode {{1}}abled.' + '\n'; output = output.toReplace(Code.Name, (Debug.Verbose ? 'en' : 'dis' )); SendTo.Special(output, CurrentUser); InvalidCommand = false; }; if ((Settings.SupportMode) && (UserIs.Author())) { if (Debug.Mode) { Debug.Verbose = !Debug.Verbose; } else { Debug.Mode = true; Debug.Verbose = true; }; output = '\n' + '{{0}}: verbose debug mode {{1}}abled.' + '\n'; output = output.toReplace(Code.Name, (Debug.Verbose ? 'en' : 'dis' )); SendTo.Special(output, CurrentUser); InvalidCommand = false; }; break; // Toggle Verbose Debug Mode (Must Be Author) // // Invalid Command Option // default: InvalidCommand = true; break; // Invalid Command Option // }; // (End Switch) }; break; // Commands // }; // (End Switch) }; // Broadcaster, Moderators (If "Allowed"), And "Always-Allowed Users" Only // /* ************************************************** */ ShowDebugMessage("InvalidCommand=" + InvalidCommand); /* ************************************************** */ if ((Debug.Mode && UserIs.Author()) || CommandCheck == Code.Command) { if (InvalidCommand && CommandParamaters[0].charAt(0) == '/') { output = '\n' + "{{0}}: invalid command or access denied: '{{1}}'." + '\n' if (UserIs.ActualBroadcaster() || UserIs.ActiveBroadcaster() || UserIs.AllowedModerator(msg) || UserIs.AlwaysAllowed()) { output += '\n' + FormatCommand("{{2}}' to see a list of the available commands.", false); output = output.toReplace(Code.Name, msg['m'].trim(), Command.Help); } else { output = output.toReplace(Code.Name, msg['m'].trim()); }; SendTo.Special(output, CurrentUser); }; }; /* Disabled: NOT COMPATIBLE WITH MULTIPLE APP/BOT COMBINATIONS if (CommandCheck == Code.Command) { output = "Command {{0}}executed: '{{1}}'"; output = output.toReplace((InvalidCommand ? 'not ' : '' ), msg['m']); msg['m'] = output; }; */ }; // Command Handler // // Utility Functions // // Chaturbate Tip Handler // var AllTipsAmount = 0; var LastTipAmount = 0; var LastTipper = null; function onTip(tip) { /* ************************************************** */ ShowDebugMessage("* onTip(tip)"); /* ************************************************** */ LastTipAmount = parseInt(tip['amount']); LastTipper = tip['from_user']; /* ************************************************** */ ShowDebugMessage("LastTipper=" + LastTipper); ShowDebugMessage("LastTipAmount=" + LastTipAmount); /* ************************************************** */ CurrentUser = LastTipper; if (Settings.TipMenuStatus) { for (i=1;i<=TotalTipMenuItems;i++) { if (!(Settings.TipMenuItem[i] == '')) { /* ************************************************** */ ShowDebugMessage("item"+i+"price=[" + Settings.TipMenuItemPrice[i] + "]"); ShowDebugMessage("item"+i+"=[" + Settings.TipMenuItem[i] + "]"); /* ************************************************** */ if (LastTipAmount == Settings.TipMenuItemPrice[i]) { // Send Notification About Purchased Tip Menu Item // output = '\n' + "{{0}} tipped for '{{1}}'." + '\n'; output = output.toReplace(LastTipper, Settings.TipMenuItem[i]); SendTo.Default(output); // Send Notification About Purchased Tip Menu Item // }; }; }; }; /* ************************************************** */ ShowDebugMessage("* onTip(tip) Complete"); /* ************************************************** */ }; cb.onTip(function(tip) { return onTip(tip); }); // Chaturbate Tip Handler // // Chaturbate Welcome Handler // function onEnter(user) { /* ************************************************** */ ShowDebugMessage("* onEnter(user)"); /* ************************************************** */ CurrentUser = user['user']; SetModeratorStatus(user); // Send Welcome Message // Feature.WelcomeMessage(false); // Send Welcome Message // if (UserIs.Author() && (!(UserIs.ActualBroadcaster()))) { output = '{{0}} is being used by {{1}}.' + '\n'; output = output.toReplace(Identification, Broadcaster.Actual); SendTo.Special(output, Code.Author.toLowerCase()); }; /* ************************************************** */ ShowDebugMessage("* onEnter(user) Complete"); /* ************************************************** */ }; cb.onEnter(function(user) { return onEnter(user); }); // Chaturbate Welcome Handler // // Chaturbate Message Handler // function onMessage(msg) { /* ************************************************** */ ShowDebugMessage("* onMessage(msg)"); /* ************************************************** */ CurrentUser = msg['user']; SetModeratorStatus(msg); msg['m'] = msg['m'].replace(/\s\s+/g, ' '); /* ************************************************** */ ShowDebugMessage("msg=" + msg['m']); // if (Debug.Mode) { // for (i=0;i<msg['m'].length;i++) { // ShowDebugMessage("msg['m'].substring("+i+"," + (i+1) + ")=[" + msg['m'].substring(i,i+1) + "] / msg['m'].charAt("+i+")=[" + msg['m'].charAt(i) + "]"); // }; // }; /* ************************************************** */ Utility.CheckForCommand(msg); /* ************************************************** */ ShowDebugMessage("* onMessage(msg) Complete"); /* ************************************************** */ return msg; }; cb.onMessage(function (msg) { return onMessage(msg); }); // Chaturbate Message Handler // // Startup // var Startup = {}; Startup.Message = '\n' + '{{0}} has been activated.' + '\n'; Startup.Message = Startup.Message.toReplace(Identification); Startup.Init = function () { /* ************************************************** */ ShowDebugMessage("* Startup.Init()"); /* ************************************************** */ Settings.NotificationStyle.Weight = Settings.NotificationStyle.Weight.toLowerCase(); // Multi-Line vs. Single-Line Display // Settings.TipMenuSeparator = Settings.TipMenuSeparator.trim() == '' ? '\n' : Settings.TipMenuSeparator; // Multi-Line vs. Single-Line Display // SendTo.Default(Startup.Message); cb.setTimeout(Startup.Delay, 2000); /* ************************************************** */ ShowDebugMessage("* Startup.Init() Complete"); /* ************************************************** */ }; Startup.Delay = function () { /* ************************************************** */ ShowDebugMessage('* Startup.Delay()'); /* ************************************************** */ /* cb.setTimeout(SendTo.ImportantUsers(CommandList), 2000); */ cb.setTimeout(SendTo.ImportantUsers('\n' + FormatCommand("{{0}}' to see a list of the available commands.".toReplace(Command.Help), false)), 2000); cb.setTimeout(Feature.TipMenuBuild, 4000); cb.setTimeout(Feature.Notifications(false,0), Settings.NotificationsTimer.fromMinutesNowMilliseconds()); /* ************************************************** */ ShowDebugMessage('* Startup.Delay() Complete'); /* ************************************************** */ }; cb.setTimeout(Startup.Init, 1); // Startup //
© Copyright Chaturbate 2011- 2026. All Rights Reserved.