Bots Home
|
Create an App
bananatest
Author:
sirius
Description
Source Code
Launch Bot
Current Users
Created by:
Sirius
/* * Author: bananamilkjuicy * Description: chatbot */ var bmj = bmj || {}; var cb = cb || {}; bmj = { __namespace: true }; /* CHTBT EXAMPLES function callme() { cb.chatNotice("hello world"); cb.setTimeout(callme, 10000); } var id = cb.setTimeout(callme, 10000) cb.cancelTimeout(id); */ //cb = { /* ////////////////////////////////////////////// CHANGE ROOM SUBJECT //changeRoomSubject(new_subject) //This is only available to apps, not bots. //Changes the room subject. ////////////////////////////////////////////// CHANGE ROOM SUBJECT END ////////////////////////////////////////////// DRAWPANEL drawPanel() This function is only available to apps, not bots. Requests that all users reload the panel (the HTML info area below the cam). The contents of the panel are controlled by cb.onDrawPanel(func). ////////////////////////////////////////////// DRAWPANEL END cb.limitCam_... Functions ///////////////////////////////////// LIMITCAM cb.limitCam_start(message, [allowed_users]) Hides the cam feed from viewers and shows them a custom message. You can optionally pass in an array of usernames of whom you’d like to be able to view the cam. cb.limitCam_stop() Stops the camera from being hidden from viewers, returning the broadcaster to public broadcasting. cb.limitCam_addUsers(allowed_users): Add an array of usernames to allow viewing of the cam while it is hidden to others. You can use this before, during, or after you start/stop limiting the cam. cb.limitCam_removeUsers(removed_users): Remove an array of usernames to no longer be able to view the cam. cb.limitCam_removeAllUsers(): Remove all viewers from being able to view the cam. cb.limitCam_userHasAccess(user): Check if a particular username is in the list of those allowed to view the cam. cb.limitCam_allUsersWithAccess(): Get an array of the usernames that are allowed to view the cam. cb.limitCam_isRunning(): Check if the cam is viewable by those not in the allowed list. Example Usage You can see an example bot that demonstrates how to use the limitCam api here: https://chaturbate.com/apps/app_details/secret-show/ The source code is also listed here: cb.settings_choices = [ {name: 'min_start_tokens', type: 'int', minValue: 1, maxValue: 1000, defaultValue: 100, label: "Cost to Join Before Show Starts"}, {name: 'min_join_tokens', type: 'int', minValue: 0, maxValue: 1000, defaultValue: 100, label: "Cost to Join During Show. Set to 0 to Disable Joining During Show."}, {name: 'hide_message', label: 'Cam Message', type: 'str', minLength: 1, maxLength: 256, defaultValue: 'Secret Show in progress! Tip at least 100 tokens to join in on the fun!' }, ]; cb.onTip(function(tip) { if (!cbjs.arrayContains(cb.limitCam_allUsersWithAccess(), tip['from_user'])) { if(!cb.limitCam_isRunning() && parseInt(tip['amount']) >= cb.settings.min_start_tokens) { output('Added '+ tip['from_user'] + ' to secret show!'); cb.limitCam_addUsers([tip['from_user']]); } if(cb.limitCam_isRunning() && parseInt(tip['amount']) >= cb.settings.min_join_tokens && cb.settings.min_join_tokens > 0) { output('Added '+ tip['from_user'] + ' to secret show!'); cb.limitCam_addUsers([tip['from_user']]); } } }); cb.onMessage(function (msg) { var message = msg['m']; var user = msg['user']; var username = ""; if (cb.room_slug === user && message == '/start' && !cb.limitCam_isRunning()) { output(cb.room_slug + ' has started the show!'); cb.limitCam_start(cb.settings.hide_message); } if (cb.room_slug === user && message == '/stop' && cb.limitCam_isRunning()) { output(cb.room_slug + ' has stopped the show!'); cb.limitCam_stop(); } if (cb.room_slug === user && message.substring(0, 7) == '/remove' && cb.limitCam_allUsersWithAccess().length > 0 && cb.limitCam_isRunning()) { username = message.substring(8, message.length); if (cbjs.arrayContains(cb.limitCam_allUsersWithAccess(), username)) { cb.limitCam_removeUsers([username]); output(cb.room_slug + ' has removed ' + username + ' from the show!'); } } if (cb.room_slug === user && message.substring(0, 6) == '/check') { username = message.substring(7, message.length); if (cb.limitCam_userHasAccess(username)) { output(username + " is in the show!"); } else { output(username + " is not in the show!"); } } if (cb.room_slug === user && message === '/list') { var userlist = cb.limitCam_allUsersWithAccess(); if (userlist.length > 0) { output("" + userlist.length + (userlist.length > 1 ? " users" : " user") + " in show: " + cbjs.arrayJoin(userlist, ", ")); } else { output("No users in show."); } } if (message[0] == '/') { msg['X-Spam'] = true; } return msg; }); function output(message) { cb.chatNotice(message); } ////////////////////////////////////////////// LIMITCAM END ////////////////////////////////////////////// LOG MSG cb.log(message) Adds a debug message to the chat. These log messages are broadcast to the chat room, but you must enable debug mode to see them. To enable or disable debug mode, type /debug into chat. Example Usage App source code: cb.onMessage(function(msg) { cb.log(msg); }); Output in chat: Debug: {u'c': u'#494949', u'm': u'hello', u'user': u'testuser', u'f': u'default'} ////////////////////////////////////////////// LOG MSG END ////////////////////////////////////////////// DRAWPANEL cb.onDrawPanel(func) This function is only available to apps, not bots. Return data needed to display the info panel for a user. The func argument should be a function that receives 1 argument itself, user. These fields are available: user: user who entered the room in_fanclub: is the user in the broadcaster’s fan club has_tokens: does the user have at least 1 token is_mod: is the user a moderator tipped_recently: is the user a “dark blue”? tipped_alot_recently: is the user a “purple”? tipped_tons_recently: is the user a “dark purple”? gender: “m” (male), “f” (female), “s” (trans), or “c” (couple) The return value is a key-value set with a template key. Depending on the template chosen, additional keys should be passed in. For more information, see Available Templates https://chaturbate.com/apps/docs/api/cb.onDrawPanel.html#available-templates /* Layout is roughly {row1_label}: {row1_value} {row2_label}: {row2_value} {row3_label}: {row3_value} cb.onDrawPanel(function(user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Tip Received / Goal :', 'row1_value': '0', 'row2_label': 'Highest Tip:', 'row2_value': user['user'], 'row3_label': 'Latest Tip Received:', 'row3_value': '0' }; }); /* Layout is roughly {row1_value} {row2_value} {row3_value} cb.onDrawPanel(function(user) { return { 'template': '3_rows_11_21_31', 'row1_value': '0', 'row2_value': user['user'], 'row3_value': '0' }; }); /* Layout is roughly {row1_label}: {row1_value} {row2_value} {row3_value} cb.onDrawPanel(function(user) { return { 'template': '3_rows_12_21_31', 'row1_label': 'Tip Received / Goal :', 'row1_value': '0', 'row2_value': user['user'], 'row3_value': '0' }; }); /* Layout is roughly {row1_label}: {row1_value} {row2_label}: {row2_value} {row3_value} cb.onDrawPanel(function(user) { return { 'template': '3_rows_12_22_31', 'row1_label': 'Tip Received / Goal :', 'row1_value': '0', 'row2_label': 'Highest Tip:', 'row2_value': user['user'], 'row3_value': '0' }; }); image_template image_template offers the ability to pass a list of objects to be added to the app panel. The two types of objects are image add text. Each object is applied to the panel in the order specified by the layers list. The dimensions of the app panel are 270 X 69 pixels; text and images that overflow the app panel will be hidden. image_template also offers the ability to include a customizable table. The table has three rows and each row can consist of one or two columns. The height of each row is 23px and cannot be changed. Rows that are omitted will be left blank. A limited amount of css styling can be specified in the template. The font-family and font-size of the table are not configurable, the defaults are UbuntuRegular and 11px. api/../../../../static/images/testbed/image_template_example.png Example and Documentation Image Required fields: type: ‘image’ fileID: ID that was assigned to file during upload Optional fields: left [default=0, min=0, max=270]: number of pixels from the left of the app panel that the top, left corner of the image will be placed. top [default=0, min=0, max=69]: number of pixels from the top of the app panel that the top, left corner of the image will be placed. opacity [default=1]: specifies the opacity of image from 0.0 (fully transparent) to 1.0 (fully opaque) Text Required fields: type: ‘text’ Optional fields: color [default=black]: color of the text. font-family [default=UbuntuRegular]: font-family of the text. font-size [default=11]: font-size of the text in pixels. font-style [default=normal]: font-style of the text. left [default=0, min=0, max=270]: number of pixels from the left of the app panel that the top, left corner of the text element will be placed. top [default=0, min=0, max=69]:: number of pixels from the top of the app panel that the top, left corner of the text element will be placed. text [default=”“]: text to be displayed. width [max=270]: width of the text element, overflow will be hidden and ellipsis will be shown. max-width [max=270]: max-width of the text element, overflow will be hidden and ellipsis will be shown. Table Required fields: type: ‘table’ Optional fields (order of inheritance is table, row, header/data): color [default=black]: color of the text for the table. background-color [default=None]: color of the background for the table text-align [default=center]: alignment of the text for the table font-weight [default=normal]: weight of the font for the table font-style [default=normal]: style of the font for the table width (header only) [default=135]: width of the header column in pixels Uploading an Image File Go to the edit tab on the app page Click Upload Image Files (or Manage Image Files if you have already uploaded an image) Select one or more files and click upload If upload successful you will be redirect to the file management page Each file will have a unique ID The ID should be used as the fileID in the image layer Image for example code background_image.jpg var backgroundImage = '05b83220-1ccc-4871-9333-70f97488de00'; var tipsReceived = 3545; var highestTip = 'tipDaddy 135'; var lastTipReceived = 'big_tipper 25'; var fontSize = 11; cb.onDrawPanel(function(user) { return { "template": "image_template", "layers": [ {'type': 'image', 'fileID': backgroundImage}, { 'type': 'text', 'text': 'TIPS RECEIVED', 'top': 5, 'left': 61, 'font-size': fontSize, 'color': 'orange', }, { 'type': 'text', 'text': 'HIGHEST TIP', 'top': 29, 'left': 73, 'font-size': fontSize, 'color': 'orange', }, { 'type': 'text', 'text': 'LATEST TIP RECEIVED', 'top': 52, 'left': 28, 'font-size': fontSize, 'color': 'orange', }, { 'type': 'text', 'text': tipsReceived, 'top': 5, 'left': 147, 'font-size': fontSize, 'color': 'white', }, { 'type': 'text', 'text': highestTip, 'top': 29, 'left': 147, 'font-size': fontSize, 'color': 'white', }, { 'type': 'text', 'text': lastTipReceived, 'top': 51, 'left': 147, 'font-size': fontSize, 'color': 'white', }, ], }; }); cb.drawPanel(); ////////////////////////////////////////////// DRAWPANEL END ////////////////////////////////////////////// ON ENTER cb.onEnter(func) Receive a notification when a registered member enters the room. The func argument should be a function that receives 1 argument itself, user. These fields are available: user: user who entered the room in_fanclub: is the user in the broadcaster’s fan club has_tokens: does the user have at least 1 token is_mod: is the user a moderator tipped_recently: is the user a “dark blue”? tipped_alot_recently: is the user a “purple”? tipped_tons_recently: is the user a “dark purple”? gender: “m” (male), “f” (female), “s” (trans), or “c” (couple) Example Usage cb.onEnter(function(user) { cb.chatNotice('Welcome ' + user['user'] + '!'); }); Example Output Notice: Welcome testuser! Notice: {u'user': u'testuser', u'in_fanclub': False, u'has_tokens': False, u'is_mod': False, u'gender': u'm', u'tipped_recently': True} ////////////////////////////////////////////// ON ENTER END ////////////////////////////////////////////// ON LEAVE cb.onLeave(func) Receive a notification when a registered member leaves the room. The func argument should be a function that receives 1 argument itself, user. These fields are available: user: user who left the room in_fanclub: is the user in the broadcaster’s fan club has_tokens: does the user have at least 1 token is_mod: is the user a moderator tipped_recently: is the user a “dark blue”? tipped_alot_recently: is the user a “purple”? tipped_tons_recently: is the user a “dark purple”? gender: “m” (male), “f” (female), “s” (trans), or “c” (couple) Example Usage cb.onLeave(function(user) { cb.chatNotice('Bye ' + user['user'] + '!'); }); Example Output Notice: Bye testuser! Notice: {u'user': u'testuser', u'in_fanclub': False, u'has_tokens': False, u'is_mod': False, u'gender': u'm', u'tipped_recently': True} ////////////////////////////////////////////// ON LEAVE END ////////////////////////////////////////////// ON MESSAGE cb.onMessage(func) Receive a notification when a message is sent. The func argument should be a function that receives 1 argument itself, message. Your app can manipulate the message. You must return the original message object. The message variable passed to the function has these fields: c: message color m: the message text user: username of message sender f: message font in_fanclub: is the user in the broadcasters fan club has_tokens: does the user have at least 1 token is_mod: is the user a moderator tipped_recently: is the user a “dark blue”? tipped_alot_recently: is the user a “purple”? tipped_tons_recently: is the user a “dark purple”? gender: “m” (male), “f” (female), “s” (trans), or “c” (couple) Example Usage cb.onMessage(function (message) { cb.chatNotice(message); }); Example Output Notice: {u'c': u'#494949', u'm': u'hello', u'user': u'testuser', u'f': u'default', u'in_fanclub': False, u'has_tokens': False, u'is_mod': False, u'gender': u'm', u'tipped_recently': True} Changing the background color of a message cb.onMessage(function (msg) { msg['background'] = '#9F9'; return msg; }); Hiding a message from chat Accomplished by setting the ‘X-Spam’ attribute on the message. cb.onMessage(function (msg) { if (msg['m'] == '/stats') { msg['X-Spam'] = true; } return msg; }); ////////////////////////////////////////////// ON MESSAGE END ////////////////////////////////////////////// ON TIP cb.onTip(func) Receive a notification when a tip is sent. The func argument should be a function that receives 1 argument itself, tip. These fields are available: amount: amount of tip message: message in tip to_user: user who received tip from_user: user who sent tip from_user_in_fanclub: is the user in the broadcasters fan club from_user_has_tokens: does the user have at least 1 token from_user_is_mod: is the user a moderator from_user_tipped_recently: is the user a “dark blue”? from_user_tipped_alot_recently: is the user a “purple”? from_user_tipped_tons_recently: is the user a “dark purple”? from_user_gender: “m” (male), “f” (female), “s” (trans), or “c” (couple) Example Usage var total_tipped = 0; cb.onTip(function (tip) { total_tipped += parseInt(tip['amount']) cb.chatNotice("Total Tipped: " + total_tipped); cb.chatNotice(tip); }); Example Output Notice: Total Tipped: 5 Notice: {u'to_user': u'testuser', u'amount': 5, u'message': u'', u'from_user': u'testuser2', u'from_user_in_fanclub': False, u'from_user_has_tokens': False, u'from_user_is_mod': False, u'from_user_gender': u'm', u'from_user_tipped_recently': True} ////////////////////////////////////////////// ON TIP END ////////////////////////////////////////////// ROOM SLUG cb.room_slug A variable that contains the name of the current room. This can be used to determine if a message is being sent by the broadcaster. if (msg['user'] == cb.room_slug) { cb.chatNotice("Message sent by broadcaster") } ////////////////////////////////////////////// ROOM SLUG END ////////////////////////////////////////////// SEND NOTICE cb.sendNotice(message, [to_user], [background], [foreground], [weight], [to_group]) Send a message to the room. If to_user is given, the message will only be seen by that user. You can also use the optional params background, foreground, and weight to style your message. Only HTML color codes (such as #FF0000) may be given for the color stying, and the font weight will only accept the options normal, bold, or bolder. If you want to provide styling options, but not a to_user, just pass an empty string to to_user. You can use a \n inside the message to send a multi-line notice. You may use :emoticons in the notice. You can send a message to a certain category of users with the optional to_group param. Just provide the color of which class of users you would like the message to be sent to. Valid choices are red (moderators), green (fan club members), darkblue (users who have tipped 50 recently), lightpurple (users who have tipped 250 recently), darkpurple (users who have tipped 1000 recently), and lightblue (users who own or have purchased tokens). Keep in mind that many users will have multiple categories applied to them, for example a fan club member who is also a moderator will get messages sent with red and green, even though his name only shows in red in chat. Using to_group will always override to_user. ////////////////////////////////////////////// SENDNOTICE END ////////////////////////////////////////////// SET TIMEOUT cb.setTimeout(func, msecs) calls function func after timeout of msecs. It returns an id which can be used to cancel the timeout. Example Code This example will print “hello world” in the chat every 10 seconds. function callme() { cb.chatNotice("hello world"); cb.setTimeout(callme, 10000) } cb.setTimeout(callme, 10000) ////////////////////////////////////////////// SET TIMEOUT END ////////////////////////////////////////////// SETTINGS CHOICES cb.settings_choices Set this variable in order to have a form filled out by the broadcaster before the app is launched. Example Usage cb.settings_choices = [ {name:'tokens_per_minute_to_be_king', type:'int', minValue:1, maxValue:99, defaultValue:5, label: "Tokens per Minute"}, {name:'remove_king_when', type:'choice', choice1:'someone else outbids', choice2:'score decays to 0', defaultValue:'someone else outbids'} ]; Accessing the initialized variables For each name in cb.settings_choices, there will be a value loaded in cb.settings. For the example above, there will be a cb.settings.remove_king_when variable. Field Types int {name:'somefield', type:'int', minValue:1, maxValue:99}, str {name: 'somefield', type: 'str', minLength: 1, maxLength: 255} choice {name:'remove_king_when', type:'choice', choice1:'foo', choice2:'bar', defaultValue: 'foo'} You may add as many choices as needed. The next choice would be choice3, followed by choice4, etc. Optional fields All fields accept a required: false parameter which makes them become optional. All fields accept a label: "Some String" field. This will be the display name for the field as shown in the final rendered form. Default values All fields accept a defaultValue: parameter. ////////////////////////////////////////////// SETTINGS CHOICES END ////////////////////////////////////////////// TIP OPTIONS cb.tipOptions(func) This function is only available to apps and bots. When users send a tip, present them with a list of messages to send with their tip. These messages can be received and processed later by cb.onTip(func). Example Code cb.tipOptions(function(user) { return {options:[{label: 'choice1'}, {label: 'choice2'}, {label: 'choice3'}], label:"Select a choice:"}; }); When a tip is received, the object will look like this: {u'to_user': u'testuser', u'amount': 5, u'message': u'choice1', u'from_user': u'testuser2'} Disabling tip options If you no longer wish to display custom tip options and would prefer the user type his own message, simply return nothing. cb.tipOptions(function(user) { // If we determine we want to show no custom tip options, do this . . . return; }); ////////////////////////////////////////////// TIP OPTIONS END ////////////////////////////////////////////// ARRAY CONTAINS cbjs.arrayContains(array, object) Returns true if array contains at least once instance of object. ////////////////////////////////////////////// ARRAY CONTAINS END ////////////////////////////////////////////// ARRAY REMOVE cbjs.arrayRemove(array, object) Removes all instances of object from array and returns the new array. ////////////////////////////////////////////// ARRAY REMOVE END */ //}; bmj.ct = { test: function () { //if (msg['user'] == cb.room_slug) { //cb.chatNotice("Message sent by broadcaster") //} cb.chatNotice(cb.room_slug); }, welcome: function () { var msg = "Thank you for joining! Follow, sit back, relax and enjoy!"; var wlcm = cb.chatNotice(msg); var notice = cb.onEnter(wlcm); return notice; }, logduser: function () { cb.onEnter(function(user) { if (user['has_tokens'] == true) { cb.chatNotice("Hey "+ user['user'] +" lets have fun, tell me what you'd like with yout token tip or take me to private for the best experience!"); } }); } }; bmj.ct.welcome(); bmj.ct.logduser(); bmj.ct.test();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.