Apps Home
|
Create an App
WTK
Author:
wethekinky
Description
Source Code
Launch App
Current Users
Created by:
Wethekinky
'use strict'; /** * Features * - Tip Tracking * - High Tipper * - Total Tips * - Custom Colors * - Secret Shows * - Dice Rolls * - Reward Menu * - Silencing Greys * - Rotating Notifications * - Announcements */ /** * WeTheKinky's Chaturbate Application * @param chaturbate * @param options * @constructor */ var WeTheKinky = function (chaturbate, options) { this.chaturbate = chaturbate; /** * @static * @type {string} * @const */ this.VERSION = '0.0.1'; /** * @static * @type {string} * @const */ this.AUTHOR = 'WeTheKinky (wethekinky+chaturbate@gmail.com)'; // Options this.Options = { Debug: true, Chaturbate: options, Commander: { Prefixes: [ '!', '/' ] } }; // Data this.Data = { Tips: { Total: 0 } }; // Instances this.room = new Room(this); this.panel = new Panel(this); // Hooks this.chaturbate.onEnter(this.onEnter.bind(this)); this.chaturbate.onMessage(this.onMessage.bind(this)); this.chaturbate.onTip(this.onTip.bind(this)); this.chaturbate.onLeave(this.onLeave.bind(this)); }; WeTheKinky.prototype = { /** * Receive a notification when a registered member enters the room. * @param user * * 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) */ onEnter: function (user) { this.log('onEnter called: ' + JSON.stringify(user)); }, /** * Receive a notification when a message is sent. * Your app can manipulate the message. * You must return the original message object. * @param message * * 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) */ onMessage: function (message) { this.log('onMessage called: ' + JSON.stringify(message)); var firstLetter = message['m'][0]; if (this.Options.Commander.Prefixes.includes(firstLetter)) { message['x-spam'] = true; message['m'] = "COMMAND: " + message['m']; } return message; }, /** * @param tip * * 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) */ onTip: function (tip) { this.log('onTip called: ' + JSON.stringify(tip)); }, /** * Receive a notification when a registered member leaves the room. * @param user * * 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) */ onLeave: function (user) { this.log('onLeave called: ' + JSON.stringify(user)); }, setTimeout: function (callback, timeout) { this.log('setTimeout called'); return this.chaturbate.setTimeout(callback, timeout); }, /** * Logs a message via cb.log * @param msg */ log: function (msg) { if (this.Options.Debug) this.chaturbate.log("[WeTheKinky] " + msg); } }; /** * Represents the room. * @constructor */ var Room = function (wtk) { this.wtk = wtk; this.Data = { Moderators: [], Users: [] }; this._subject = ""; // TODO: find out what the subject is }; Room.prototype = { get subject() { return this._subject; }, set subject(s) { this._subject = s; this.wtk.chaturbate.changeRoomSubject(this._subject); }, get slug() { return this.wtk.chaturbate.room_slug; }, /** * Logs a message via WeTheKinky.log * @param {string} msg */ log: function (msg) { this.wtk.log("[Room] " + msg); } }; /** * Represents the panel. * @param {WeTheKinky} wtk * @constructor */ var Panel = function (wtk) { this.wtk = wtk; this.row = { top: new Row(null, null), middle: new Row(null, null), bottom: new Row(null, null) }; // Gets the template name dynamically this.template = this.wtk.chaturbate.onDrawPanel(this.onDraw.bind(this)); }; Panel.prototype = { /** * Handles cb.onDrawPanel using our panel * @param e * @returns {{template: *}} */ onDraw: function (e) { this.log("onDraw called"); var panel = { template: this.getTemplate() }; this.getRows().forEach(function (row) { row.apply(panel); }); return panel; }, /** * Gets the rows from the this.row object * @returns {Array.<Row>} */ getRows: function () { return Object.keys(this.row).map(function (key) { return this.row[key]; }.bind(this)).filter(function (row) { return row !== undefined && !row.isEmpty(); }); }, /** * Gets the template name * @returns {string} */ getTemplate: function () { return this.getRows().reduce(function (template, row) { return template + '_' + row.index + row.getColumns(); }, '3_rows').replace('12_22_32', 'of_labels'); }, /** * Logs a message via WeTheKinky.log * @param {string} msg */ log: function (msg) { this.wtk.log("[Panel] " + msg); } }; /** * Represents a row in the panel. */ var Row = (function () { var index = 1; /** * A row that contains data for the panel * @param label * @param value * @constructor */ function Row(label, value) { this.label = label; this.value = value; this.index = index++; } Row.prototype = { /** * Checks if the current row has a label set * @returns {boolean} */ hasLabel: function () { return this.label !== null; }, /** * Checks if the current row is empty * @returns {boolean} */ isEmpty: function () { return this.value === null; }, /** * Gets the number of columns: 1 for just a value, 2 for a label and a value * @returns {number} */ getColumns: function () { return this.label === null ? 1 : 2; }, /** * Applies the row to the object * @param {Object} templateObj is the object that chaturbate uses to render a panel */ apply: function (templateObj) { if (this.hasLabel()) templateObj['row' + this.name + '_label'] = this.label; templateObj['row' + this.index + '_value'] = this.value; }, /** * Sets the label and value for the row * @param label * @param value */ set: function (label, value) { this.setLabel(label); this.setValue(value); }, /** * Sets the label for the row * @param label */ setLabel: function (label) { this.label = label; }, /** * Removes the label for the row by setting it to null */ removeLabel: function () { this.setLabel(null); }, /** * Sets the value for the row * @param value */ setValue: function (value) { this.value = value; }, /** * Removes the value for the row by setting it to null */ removeValue: function () { this.setValue(null); } }; return Row; })(); var User = (function () { var User = function (u) { this.source = u; this.name = u.user; this.gender = u.gender; this.isModel = false; this.isMod = u.is_mod; this.isFan = u.in_fanclub; this.hasTokens = u.has_tokens; this.getColor = (function () { if (this.isMod) return 'red'; if (this.isFan) return 'green'; if (this.hasTokens) return 'blue'; if (this.source.tipped_recently) return 'darkblue'; if (this.source.tipped_alot_recently) return 'purple'; if (this.source.tipped_tons_recently) return 'darkpurple'; return 'grey'; }).bind(this); return User; } })(); var Commander = (function () { var Commander = function (commands) { this.commands = commands || []; this.defaultExecutable = ""; }; Commander.prototype.command = function (name, desc, opts) { opts = opts || {}; var args = name.split(/ +/); var cmd = new Command(args.shift()); if (desc) { cmd.description(desc); this.hasExecutables = true; this.executables[cmd.name] = true; if (opts.isDefault && this.defaultExecutable === "") this.defaultExecutable = cmd.name; } cmd.noHelp = !!opts.noHelp; this.commands.push(cmd); cmd.parseExpectedArgs(args); cmd.parent = this; if (desc) return this; return cmd; }; return Commander; })(); var CommandOptions = { isDefault: true, noHelp: false }; var Command = (function () { var Command = function () { this.description = description; this.noHelp = true; }; var prototype = Command.prototype; prototype.describe = function (desc) { this.description = desc; return this; }; prototype.callback = function (fn) { try { var result = fn.bind(this).call(); } catch (err) { this.log(err) } }; return Command; })(); /** * Utils * @type {Object} */ var Utils = { Color: { aliceblue: "#F0F8FF", antiquewhite: "#FAEBD7", aqua: "#00FFFF", aquamarine: "#7FFFD4", azure: "#F0FFFF", beige: "#F5F5DC", bisque: "#FFE4C4", black: "#000000", blanchedalmond: "#FFEBCD", blue: "#0000FF", blueviolet: "#8A2BE2", brown: "#A52A2A", burlywood: "#DEB887", cadetblue: "#5F9EA0", chartreuse: "#7FFF00", chocolate: "#D2691E", coral: "#FF7F50", cornflowerblue: "#6495ED", cornsilk: "#FFF8DC", crimson: "#DC143C", cyan: "#00FFFF", darkblue: "#00008B", darkcyan: "#008B8B", darkgoldenrod: "#B8860B", darkgray: "#A9A9A9", darkgrey: "#A9A9A9", darkgreen: "#006400", darkkhaki: "#BDB76B", darkmagenta: "#8B008B", darkolivegreen: "#556B2F", darkorange: "#FF8C00", darkorchid: "#9932CC", darkred: "#8B0000", darksalmon: "#E9967A", darkseagreen: "#8FBC8F", darkslateblue: "#483D8B", darkslategray: "#2F4F4F", darkslategrey: "#2F4F4F", darkturquoise: "#00CED1", darkviolet: "#9400D3", deeppink: "#FF1493", deepskyblue: "#00BFFF", dimgray: "#696969", dimgrey: "#696969", dodgerblue: "#1E90FF", firebrick: "#B22222", floralwhite: "#FFFAF0", forestgreen: "#228B22", fuchsia: "#FF00FF", gainsboro: "#DCDCDC", ghostwhite: "#F8F8FF", gold: "#FFD700", goldenrod: "#DAA520", gray: "#808080", grey: "#808080", green: "#008000", greenyellow: "#ADFF2F", honeydew: "#F0FFF0", hotpink: "#FF69B4", indianred: "#CD5C5C", indigo: "#4B0082", ivory: "#FFFFF0", khaki: "#F0E68C", lavender: "#E6E6FA", lavenderblush: "#FFF0F5", lawngreen: "#7CFC00", lemonchiffon: "#FFFACD", lightblue: "#ADD8E6", lightcoral: "#F08080", lightcyan: "#E0FFFF", lightgoldenrodyellow: "#FAFAD2", lightgreen: "#90EE90", lightgrey: "#D3D3D3", lightpink: "#FFB6C1", lightsalmon: "#FFA07A", lightseagreen: "#20B2AA", lightskyblue: "#87CEFA", lightslategray: "#778899", lightslategrey: "#778899", lightsteelblue: "#B0C4DE", lightyellow: "#FFFFE0", lime: "#00FF00", limegreen: "#32CD32", linen: "#FAF0E6", magenta: "#FF00FF", maroon: "#800000", mediumaquamarine: "#66CDAA", mediumblue: "#0000CD", mediumorchid: "#BA55D3", mediumpurple: "#9370DB", mediumseagreen: "#3CB371", mediumslateblue: "#7B68EE", mediumspringgreen: "#00FA9A", mediumturquoise: "#48D1CC", mediumvioletred: "#C71585", midnightblue: "#191970", mintcream: "#F5FFFA", mistyrose: "#FFE4E1", moccasin: "#FFE4B5", navajowhite: "#FFDEAD", navy: "#000080", oldlace: "#FDF5E6", olive: "#808000", olivedrab: "#6B8E23", orange: "#FFA500", orangered: "#FF4500", orchid: "#DA70D6", palegoldenrod: "#EEE8AA", palegreen: "#98FB98", paleturquoise: "#AFEEEE", palevioletred: "#DB7093", papayawhip: "#FFEFD5", peachpuff: "#FFDAB9", peru: "#CD853F", pink: "#FFC0CB", plum: "#DDA0DD", powderblue: "#B0E0E6", purple: "#800080", red: "#FF0000", rosybrown: "#BC8F8F", royalblue: "#4169E1", saddlebrown: "#8B4513", salmon: "#FA8072", sandybrown: "#F4A460", seagreen: "#2E8B57", seashell: "#FFF5EE", sienna: "#A0522D", silver: "#C0C0C0", skyblue: "#87CEEB", slateblue: "#6A5ACD", slategray: "#708090", slategrey: "#708090", snow: "#FFFAFA", springgreen: "#00FF7F", steelblue: "#4682B4", tan: "#D2B48C", teal: "#008080", thistle: "#D8BFD8", tomato: "#FF6347", turquoise: "#40E0D0", violet: "#EE82EE", wheat: "#F5DEB3", white: "#FFFFFF", whitesmoke: "#F5F5F5", yellow: "#FFFF00", yellowgreen: "#9ACD32" }, /** * Recursively freezes an object * @param obj * @returns {Object} * @constructor */ deepFreeze: function (obj) { var keys = Object.getOwnPropertyNames(obj); keys.forEach(function (key) { var value = obj[key]; if (typeof value === 'object' && value !== null) Utils.DeepFreeze(value); }); return Object.freeze(obj); }, /** * Returns the name of the given function, or 'anonymous' if it has no name * @param fn */ getFunctionName: function (fn) { var regexpResult = fn.toString().match(/function(\s*)(\w*)/); if (regexpResult && regexpResult.length >= 2 && regexpResult[2]) { return regexpResult[2]; } return 'anonymous'; } }; function dump(msg, obj) { cb.log('[' + msg + '] (properties) ' + JSON.stringify(Object.getOwnPropertyNames(obj))); cb.log('[' + msg + '] ' + JSON.stringify(obj)); } // Tests for Panel function Test_Panel(app) { app.panel.row.top.set("Tip Received / Goal", 0); app.panel.row.middle.setLabel("Highest Tip"); app.panel.row.middle.setValue("Big Spender"); app.panel.row.bottom.set("another thing", "yay!"); dump('app.panel.row', app.panel.row); dump('app.panel.getTemplate()', app.panel.getTemplate()); dump('app.panel.getRows()', app.panel.getRows()); app.panel.getRows().forEach(function (row) { row.removeLabel(); }); dump('app.panel.row', app.panel.row); dump('app.panel.getTemplate()', app.panel.getTemplate()); dump('app.panel.getRows()', app.panel.getRows()); } // Tests for Room function Test_Room(app) { app.room.subject = new Date(); app.room.log("subject=" + app.room.subject); app.room.log("slug=" + app.room.slug); } function init() { var app = new WeTheKinky(cb); app.log("initializing..."); Test_Panel(app); Test_Room(app); } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.