Bots Home
|
Create an App
Notifier + Auto Tip Thx
Author:
proboards
Description
Source Code
Launch Bot
Current Users
Created by:
Proboards
/** * Notifier * * Author: Proboards * Version: 0.0.1 * Last update: 27-07-2013 * * Build on: * Framework version 3.7 * <PluginBase (version 2.7.2)> * <Bobomb (version 3.8.2)> * * Usage: * Set the initial settings. The bot will now post the set message at the set interval to the room. * * For more information, type /help in chat. * * * Full list of supported commands: * /help * /showmodules * /setmodule * /showsettings * /exportsettings * /importsettings * /setmessage * /setinterval * /settipamount * /showmessage * * * Change log: * -- 0.6.6 (10-06-2013) -- * > Updated to the latest framework version. * * -- 0.6.1 (20-05-2013) -- * > Added a new module to trigger the message with tips. * * -- 0.5.7 (19-05-2013) -- * > Updated framework version. * * -- 0.5.0 (10-05-2013) -- * > Updated framework version - reworked command processing. * * -- 0.4.0 (09-05-2013) -- * > Fixed the /setmessage bug. * > Some minor performance changes under the hood. * * -- 0.3.9 (09-05-2013) -- * > Reworked to my own, new scripting framework. * > Added a new command: /showmessage. Show the message to the room. * * -- 0.1.6 (07-05-2013) -- * > Initial release. * */ /* ChaturBate set-up */ cb.settings_choices = [ { name: 'safeMode', type: 'choice', choice1: 'Enabled', choice2: 'Disabled', defaultValue: 'Disabled', label: "Safe Mode (turn this on when this bots chat commands clash with another bot)" }, { name: 'message', type: 'str', minLength: 1, label: "Message" }, { name: 'triggerInterval', type: 'choice', choice1: 'Enabled', choice2: 'Disabled', defaultValue: 'Enabled', label: "Show message at an interval" }, { name: 'interval', type: 'int', minValue: 1, defaultValue: 10, maxValue: 60, label: "The interval for posting the message (in minutes)" }, { name: 'triggerTip', type: 'choice', choice1: 'Enabled', choice2: 'Disabled', defaultValue: 'Disabled', label: "Show message when someone tips" }, { name: 'tip', type: 'int', minValue: 0, defaultValue: 0, maxValue: 9999, label: "The minimum tip amount for the message to be shown" } ]; /* END */ /* Plugin */ var Plugin = { // Variables settings: { safeMode: false, message: "", triggerInterval: true, interval: 10, triggerTip: false, tip: 0 }, // Constants name: "Notifier", commandList: [ { command: "/help", description: "show all available commands.", accessLevel: 1 }, { command: "/showmodules", description: "show all available modules to turn on and off.", accessLevel: 2 }, { command: "/setmodule", parameters: "[on/off] [module_name]", description: "turn a module on or off.", accessLevel: 2 }, { command: "/showsettings", description: "show the current settings.", accessLevel: 2 }, { command: "/exportsettings", description: "returns a JSON string that can be imported on the next run.", accessLevel: 2 }, { command: "/importsettings", description: "import settings from a previously exported JSON string.", accessLevel: 2 }, { command: "/setmessage", parameters: "x", description: "set message x to be displayed in the room.", accessLevel: 2 }, { command: "/setinterval", parameters: "#", description: "set interval # in minutes for the periodic displaying of the message.", accessLevel: 2, module: "triggerInterval" }, { command: "/settipamount", parameters: "#", description: "set amount # as the minimum tip amount to trigger the message.", accessLevel: 2, module: "triggerTip" }, { command: "/showmessage", description: "show the message to the room.", accessLevel: 1, toRoom: true } ], moduleList: [ { module: "safeMode", description: "in safe mode, chat commands will be ignored unless they use a special modifier." }, { module: "triggerInterval", description: "Trigger the message on a set interval." }, { module: "triggerTip", description: "Trigger the message when a certain amount is tipped."} ] }; /* General functions */ /* processCommand - Plugin specific command processing */ /* Gets called from within the processCommand function in Bobomb when no matches were found */ /* Note: if both this function and the processNormalMessage function is not found, the messageHandler does not get set */ /* { command, description, module, parameter, variation, accessLevel, toRoom }, fullMessage, { name, accessLevel, gender } */ Plugin.processCommand = function(command, fullMessage, user) { switch(command.command) { case "/setmessage": { var newMessage = fullMessage.split(command.command + " "); if(newMessage.length == 2 && newMessage[1].length > 0) { Plugin.settings.message = newMessage[1]; return "Message has been changed to '" + newMessage[1] + "'!"; } return Bobomb.MessageManager.errorNotice("InvalidSyntax", command.command, "No message found!"); } case "/setinterval": { var newInterval = fullMessage.match(/[0-9]{1,2}/); if(newInterval != null) { newInterval = newInterval[0]; if(isFinite(newInterval) && newInterval > 0 && newInterval <= 60) { Plugin.settings.interval = parseInt(newInterval); return "Interval has been set to " + newInterval + " minutes!"; } return Bobomb.MessageManager.errorNotice("InvalidValues", command.command, "Interval is not a valid number!"); } return Bobomb.MessageManager.errorNotice("InvalidSyntax", command.command, "No interval found!"); } case "/settipamount": { var newAmount = fullMessage.match(/[0-9]{1,4}/); if(newAmount != null) { newAmount = newAmount[0]; if(isFinite(newAmount) && newAmount >= 0) { Plugin.settings.tip = parseInt(newAmount); return "Minimum tip amount has been set to " + newAmount + " tokens!"; } return Bobomb.MessageManager.errorNotice("InvalidValues", command.command, "Tip amount is not a valid number!"); } return Bobomb.MessageManager.errorNotice("InvalidSyntax", command.command, "No tip amount found!"); } case "/showmessage": { return Plugin.settings.message; } default: { return ""; } } return ""; } /* processTip - Plugin specific tip processing */ /* Gets called from within the tipHandler function in Bobomb */ /* Note: if this function is not found, the tipHandler does not get set */ /* amount, message, { name }, { name, hasTokens, isMod, tippedRecently, isFan, gender, accessLevel } */ Plugin.processTip = function(amount, message, toUser, fromUser) { if(Plugin.settings.triggerTip && amount >= Plugin.settings.tip) { Plugin.postMessage(); } } /* postMessage */ /* Posts the set message to the room */ Plugin.postMessage = function() { cb.chatNotice(Plugin.settings.message); if(Plugin.settings.triggerInterval) { cb.setTimeout("Plugin.postMessage()", (Plugin.settings.interval * 60000)); } } /* init - Plugin specific initiation */ /* Gets called from within the init function in Bobomb */ Plugin.init = function() { Plugin.postMessage(); } /* END */ /** * Bobomb * * Author: Bobomb * Version: 3.8.2 * Last update: 10-07-2013 * * Bobomb's main module with generic functions to extend CB's functionality. Appended to the end of all apps and bots made by Bobomb. * * Change log: * -- 3.8.2 (10-07-2013) -- * > Fixed a bug with the chatcommands. * * -- 3.8.1 (10-06-2013) -- * > Added two new modifiers to the chat commands. * > Added support for safe mode. * * -- 3.7.0 (10-06-2013) -- * > Added code to make Plugin constants behave like constants. * * -- 3.6.4 (09-06-2013) -- * > Cleaned up some code. * > Added documentation. * > Expanded the translate settings logic. * > Fixed the registering for message events not working when only normal messages are being used. * * -- 3.6.1 (19-05-2013) -- * > Altered the handeling of messages and tips. * > Fixed an issue with bad switches. * > Renamed the function system to module system. * * -- 2.2.2 (16-05-2013) -- * > Reworked settings translation. * > Added functionality to work with TCE. * > Among these functionalities is the inclusion of the TipManager. * * -- 1.9.1 (10-05-2013) -- * > Added MessageManager.getCommandInfo. * > Changed the way commands are processed. * * -- 1.7.3 (09-05-2013) -- * > Initial public release. * * -- 1.3.5 (08-05-2013) -- * > Initial implementation. * */ /* Bobomb */ var Bobomb = { // Function grouping SettingsManager: {}, MessageManager: {}, TipManager: {}, UserManager: {}, // Constants positives: ["Enabled", "On", "Yes", "Enable", "True"] }; /* Settings Manager */ /* translateSetting */ /* Resolve a setting and see if there is a corresponding setting in the ChaturBate settings object */ Bobomb.SettingsManager.translateSetting = function(parentObject, settingName) { if(parentObject[settingName].constructor == Object) { for(var part in parentObject[settingName]) { Bobomb.SettingsManager.translateSetting(parentObject[settingName], part); } } else if(cb.settings[settingName] != undefined) { if(parentObject[settingName].constructor == Boolean) { if(Bobomb.positives.indexOf(cb.settings[settingName]) != -1) { parentObject[settingName] = true; } else { parentObject[settingName] = false; } } else if(parentObject[settingName].constructor == String || parentObject[settingName].constructor == Number) { parentObject[settingName] = cb.settings[settingName]; } } } /* translateSettings */ /* Loop through all settings and check for a CB version of it */ Bobomb.SettingsManager.translateSettings = function() { for(var part in Plugin) { if(Plugin[part].constructor != Function) { Bobomb.SettingsManager.translateSetting(Plugin, part); } } if(cb.settings.importString != undefined && cb.settings.importString.length > 0) { Bobomb.SettingsManager.importAll(cb.settings.importString); } } /* exportSetting */ /* Turn a setting in a JSON string */ Bobomb.SettingsManager.exportSetting = function(setting) { return '"' + setting + '":' + JSON.stringify(Plugin[setting]); } /* exportAll */ /* Loop through all settings and prepare them for export */ /* Returns: A JSON string containing all settings */ Bobomb.SettingsManager.exportAll = function() { var parts = []; for(var part in Plugin) { if(Plugin[part].constructor != Function) { parts.push(Bobomb.SettingsManager.exportSetting(part)); } } var string = ""; for(var part in parts) { if(part > 0) { string += ","; } string += parts[part]; } return "{" + string + "}"; } /* importSetting */ /* Set a given setting to the value (if any) contained in the given importObject */ Bobomb.SettingsManager.importSetting = function(importObject, setting) { if(importObject[setting] != undefined && Plugin[setting] != undefined) { Plugin[setting] = importObject[setting]; } } /* importAll */ /* Parse the given JSON string and loop through all settings to pass them the imported values */ /* Returns: a string message informing the caller of succes or failure */ Bobomb.SettingsManager.importAll = function(importString) { if(importString.indexOf("Notice:") != -1) { importString = importString.split("Notice: ")[1]; } try { var importObject = JSON.parse(importString); } catch(e) { return "Import failed!"; } for(var part in Plugin) { if(Plugin[part].constructor != Function) { Bobomb.SettingsManager.importSetting(importObject, part); } } return "Import successfull!"; } /* END */ /* Message Manager */ /* makeList */ /* This function is used to create the list of commands and modules */ /* Returns: a string containing all entries from a given list for a given user */ Bobomb.MessageManager.makeList = function(fromList, user) { var output = ""; if(fromList == Plugin.commandList) { output += "Commands for " + Plugin.name + ": \n"; var restOfOutput = ""; for(var i = 0; i < Plugin.commandList.length; i++) { if((Plugin.commandList[i].module == undefined || Plugin.settings[Plugin.commandList[i].module]) && Plugin.commandList[i].accessLevel <= user.accessLevel) { if(restOfOutput.length > 0) { restOfOutput += "\n"; } restOfOutput += Plugin.commandList[i].command; if(Plugin.commandList[i].parameters != undefined) { restOfOutput += " " + Plugin.commandList[i].parameters; } restOfOutput += " | " + Plugin.commandList[i].description; if(Plugin.commandList[i].variation != undefined) { restOfOutput += "\n" + Plugin.commandList[i].command + " " + Plugin.commandList[i].parameters + " " + Plugin.commandList[i].variation + " | " + Plugin.commandList[i].description; } } } var modifiers = "\nBy adding !private to a command, the return message will always be hidden from the room."; if(Plugin.settings.safeMode) { modifiers += "\nBy adding !" + Plugin.name.toLowerCase() + " to a command, the command is intercepted by this bot."; } else { modifiers += "\nBy adding !" + Plugin.name.toLowerCase() + "-ignore to a command, this bot will not respond to the command."; } output = output + restOfOutput + modifiers; } else if(fromList == Plugin.moduleList) { output += "Modules for " + Plugin.name + ": \n"; for(var i = 0; i < Plugin.moduleList.length; i++) { if(i != 0) { output += "\n"; } output += Plugin.moduleList[i].module + " | " + Plugin.moduleList[i].description; } } return output; } /* getCommandInfo */ /* This function retrieves all information about the given command */ /* Returns: { command, description, module, parameter, variation, accessLevel, toRoom } (or null)*/ Bobomb.MessageManager.getCommandInfo = function(command) { for(var commandIndex in Plugin.commandList) { if(Plugin.commandList[commandIndex].command == command.toLowerCase()) { return Plugin.commandList[commandIndex]; } } return null; } /* errorNotice */ /* Send a chat notice to the room owner with an error message for a given command */ /* You can also pass a custom message to the function */ Bobomb.MessageManager.errorNotice = function(type, commandName, customMessage) { var user = { name: cb.room_slug }; if(customMessage == undefined) { customMessage = ""; } switch(type) { case "InvalidValues": { cb.chatNotice("Invalid values found for command " + commandName + "! " + customMessage, user.name); return ""; } case "InvalidSyntax": { cb.chatNotice("Invalid syntax found for command " + commandName + "! " + customMessage, user.name); return ""; } default: { cb.log("An error occured while processing an error! " + customMessage); return ""; } } return ""; } /* processCommand */ /* This function checks if the call to the matched command is legit and gives the implementation for the standard commands */ /* If the call is legit and it is not a standard command, the Plugin specific version of processCommand is called */ Bobomb.MessageManager.processCommand = function(command, fullMessage, user) { if(command.command != null && (command.accessLevel == undefined || user.accessLevel >= command.accessLevel) && (command.module == undefined || Plugin.settings[command.module])) { switch(command.command) { case "/help": { return Bobomb.MessageManager.makeList(Plugin.commandList, user); } case "/showsettings": { var output = "Current settings:"; for(var setting in Plugin.settings) { output += "\n" + setting + ": " + Plugin.settings[setting]; } return output; } case "/showmodules": { if(Plugin.moduleList != undefined) { return Bobomb.MessageManager.makeList(Plugin.moduleList, user); } return ""; } case "/setmodule": { if(Plugin.moduleList != undefined) { if(fullMessage.indexOf(" on") != -1) { for(var i = 0; i < Plugin.moduleList.length; i++) { var name = Plugin.moduleList[i].module; if(fullMessage.indexOf(name) != -1) { Plugin.settings[name] = true; return name.charAt(0).toUpperCase() + name.substr(1) + " turned on!"; } } return Bobomb.MessageManager.errorNotice("InvalidValues", command.command, "Unknown module!"); } else if(fullMessage.indexOf(" off") != -1) { for(var i = 0; i < Plugin.moduleList.length; i++) { var name = Plugin.moduleList[i].module; if(fullMessage.indexOf(name) != -1) { Plugin.settings[name] = false; return name.charAt(0).toUpperCase() + name.substr(1) + " turned off!"; } } return Bobomb.MessageManager.errorNotice("InvalidValues", command.command, "Unknown module!"); } return Bobomb.MessageManager.errorNotice("InvalidSyntax", command.command, "Action (on/off) not specified!"); } break; } case "/exportsettings": { return Bobomb.SettingsManager.exportAll(); } case "/importsettings": { return Bobomb.SettingsManager.importAll(fullMessage.slice(15)); } default: { return Plugin.processCommand(command, fullMessage, user); } } } return ""; } /* messageHandler */ /* Invoked for each message. Calls the appropiate function for the type of message */ Bobomb.MessageManager.messageHandler = function(message) { var command = message['m'].match(/^\/[A-z]+/); if(command != null && (!Plugin.settings.safeMode || message['m'].indexOf("!" + Plugin.name.toLowerCase()) != -1) && message['m'].indexOf("!" + Plugin.name.toLowerCase() + "-ignore") == -1) { command = Bobomb.MessageManager.getCommandInfo(command[0]); if(command != null) { var returnMessage = Bobomb.MessageManager.processCommand(command, message.m, Bobomb.UserManager.makeUserObject(message, true)); if(returnMessage.length > 0) { if(message.m.indexOf("!private") == -1 && command.toRoom) { cb.chatNotice(returnMessage); } else { cb.chatNotice(returnMessage + "\n(Not shown to room)", message.user); } message.m += " (intercepted as command by " + Plugin.name + ")"; message['X-Spam'] = true; } } } else if(Plugin.processNormalMessage != undefined) { var returnObject = Plugin.processNormalMessage(message.m, message.c, message.f, Bobomb.UserManager.makeUserObject(message)); message.m = returnObject.message; message.c = returnObject.colour; message.f = returnObject.font; } return message; } /* END */ /* Tip Manager */ /* tipHandler */ /* Invoked for each tip. Calls the Plugin's processTip function */ Bobomb.TipManager.tipHandler = function(tip) { Plugin.processTip(tip.amount, tip.message, { name: tip.to_user }, Bobomb.UserManager.makeUserObject(tip)); } /* END */ /* User Manager */ /* makeUserObject */ /* Create a standarized user object out of a given sourceobject */ /* Note: set the commandingUser parameter to any value to get a special user object for use with the processCommand function */ /* Returns: { name, hasTokens, isMod, tippedRecently, isFan, gender, accessLevel } (or null) */ Bobomb.UserManager.makeUserObject = function(sourceObject, commandingUser) { if(commandingUser != undefined) { return { name: sourceObject.user, accessLevel: Bobomb.UserManager.getAccessLevel({ name: sourceObject.user, isMod: sourceObject.is_mod }), gender: sourceObject.gender }; } else { var returnObject = {}; var prefix = ""; if(sourceObject.amount != undefined) { returnObject.name = sourceObject.from_user; prefix = "from_user"; } else { returnObject.name = sourceObject.user; } for(var field in [["is_mod", "isMod"], ["has_tokens", "hasTokens"], ["tipped_recently", "tippedRecently"], ["in_fanclub", "isFan"], ["gender", "gender"]]) { returnObject[field[1]] = sourceObject[prefix + field[0]]; } returnObject.accessLevel = Bobomb.UserManager.getAccessLevel(returnObject); return returnObject; } return null; } /* isUserInList */ /* This function is used to determine if an user is in a given list */ /* Note: it is assumed that all lists containing users are arrays of objects with a key/value pair called name to contain the name of a user */ /* Returns: a boolean value */ Bobomb.UserManager.isUserInList = function(user, target) { return (Bobomb.UserManager.findUserIndex(user, target) != -1); } /* findUserIndex */ /* This function is used to get the index of a given user in a given list */ /* Note: it is assumed that all lists containing users are arrays of objects with a key/value pair called name to contain the name of a user */ /* Returns: the numeric index of the user in the target list (or -1) */ Bobomb.UserManager.findUserIndex = function(user, target) { if(target.constructor == Array && target.length > 0) { for(var i = 0; i < target.length; i++) { if(target[i].name == user) { return i; } } return -1; } return -1; } /* getAccessLevel */ /* This function is used to retrieve the access level of a given user */ /* Returns: an integer representing the users access level */ Bobomb.UserManager.getAccessLevel = function(user) { if(user.name == cb.room_slug) { return 2; } else if(user.isMod) { return 1; } return 0; } /* END */ /* General functions */ /* init */ /* Initializes the basic parts of the framework */ Bobomb.init = function() { // Make the Plugin constants actual constants! Object.defineProperty(Plugin, "name", { enumerable: false, configurable: false, writable: false, value: Plugin.name }); Object.defineProperty(Plugin, "commandList", { enumerable: false, configurable: false, writable: false, value: Plugin.commandList }); Object.defineProperty(Plugin, "moduleList", { enumerable: false, configurable: false, writable: false, value: Plugin.moduleList }); Bobomb.SettingsManager.translateSettings(); if(Plugin.processCommand != undefined || Plugin.processNormalMessage != undefined) { cb.onMessage(Bobomb.MessageManager.messageHandler); } if(Plugin.processTip != undefined) { cb.onTip(Bobomb.TipManager.tipHandler); } if(Plugin.init != undefined) { Plugin.init(); } } /* END */ Bobomb.init(); tipper = ""; tipmsg = ""; cb.settings_choices = [ { name: 'tipamount', type: 'int', minValue: 1, defaultValue: 10, label: 'Minimum tokens required for a thank you message' } , { name: 'tipmsg', type: 'str', minLength: 8, maxLength: 128, defaultValue: '**** Thank you [tipper] for your tip!!! (: **** ', label: "Tip thank you message, [tipper] = tipper's name" } ]; cb.onTip(function (tip) { if (parseInt(tip['amount']) >= cb.settings.tipamount) { tipper = tip['from_user']; tipmsg=cb.settings.tipmsg; tipmsg = tipmsg.replace("[tipper]", tipper); cb.chatNotice(tipmsg, tipper); } }); function init() { } init();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.