Apps Home
|
Create an App
EdgeApp
Author:
entomy
Description
Source Code
Launch App
Current Users
Created by:
Entomy
/** * Manages and applies discounts */ var discount; /** * Manages and applies discounts */ (function (discount) { "use strict"; /** * Fanclub discount percentage * This should be within 0~1 */ discount.fanclub = 0; /** * Moderator discount percentage * This should be within 0~1 */ discount.moderator = 0; /** * Apply the appropriate discount to the specified item, returning the discounted cost * @param item Item to discount * @param user User information for calculating discount */ function apply(item, user) { // CB uses different property names for the same thing on different types; this is confusing // These two values are assigned from whatever is approriate, to make the actual code easier to read var in_fanclub = user.hasOwnProperty("from_user_in_fanclub") ? user.from_user_in_fanclub : user.in_fanclub; var is_mod = user.hasOwnProperty("from_user_is_mod") ? user.from_user_is_mod : user.is_mod; // If user has no applicable discount, don't bother calculating it if (!in_fanclub && !is_mod) return item.cost; // Calculate the user discount based on whatever discount is appropriate and higher if (discount.fanclub >= discount.moderator) { if (in_fanclub) return Math.floor(item.cost * (1 - discount.fanclub)); else if (is_mod) return Math.floor(item.cost * (1 - discount.moderator)); } else if (discount.moderator > discount.fanclub) { if (is_mod) return Math.floor(item.cost * (1 - discount.moderator)); else if (in_fanclub) return Math.floor(item.cost * (1 - discount.fanclub)); } return item.cost; } discount.apply = apply; })(discount || (discount = {})); /** * Provides aliases for emblem emotes */ var emblems; /** * Provides aliases for emblem emotes */ (function (emblems) { "use strict"; emblems.arrow = " :arrow16 "; emblems.ballot = " :ballot16 "; emblems.bb8 = " :miniBB-8 "; emblems.blank = " :blank16 "; emblems.bronzemedal = " :bronzemedal16c "; emblems.coppermedal = " :coppermedal16 "; emblems.crown = " :crown16 "; emblems.gavel = " :gavel16 "; emblems.goldmedal = " :goldmedal16 "; emblems.hitachi = " :hitachi16 "; emblems.notice = " :notice16 "; emblems.silvermedal = " :silvermedal16 "; emblems.song = " :song16 "; emblems.timer = " :timer16 "; emblems.tinmedal = " :tinmedal16 "; emblems.tipmenu = " :tipmenu16 "; emblems.token = " :token12 "; emblems.trusted = " :trusted16 "; emblems.whisper = " :whisper16 "; emblems.whispermod = " :whispermod16 "; })(emblems || (emblems = {})); /** * Represents a tipmenu item */ var menuitem = (function () { /** * Create a new menu item * @param name Name of the item * @param cost Cost of the item * @param active Whether the menuitem is active (on the menu) or inactive (not on the menu), defaults to always active * @param handler Handler function when this item is tipped for * @param params Parameters for the handler function */ function menuitem(name, cost, active, handler) { if (active === void 0) { active = function () { return true; }; } var params = []; for (var _i = 4; _i < arguments.length; _i++) { params[_i - 4] = arguments[_i]; } this.name = name; this.cost = cost; this.active = active; this.handler = handler; this.params = params; } /** * Handle the item, if it has a handler * This will not call the handler if one is not assigned */ menuitem.prototype.handle = function (tip, params) { if (params === void 0) { params = this.params; } if (this.handler != null) { this.handler(tip, params); } }; return menuitem; }()); /** * Represents a tipmenu section */ var menusection = (function () { function menusection(name) { var items = []; for (var _i = 1; _i < arguments.length; _i++) { items[_i - 1] = arguments[_i]; } /** * The actual items of the section */ this.items = []; this.name = name; this.items = items; } /** * Add the item to the section * @param name Name of the item * @param cost Cost of the item * @param active The condition in which the item is active * @param handler Handler for when the item is tipped for * @param params Parameters that should be passed to the handler */ menusection.prototype.add = function (name, cost, active, handler) { if (active === void 0) { active = function () { return true; }; } var params = []; for (var _i = 4; _i < arguments.length; _i++) { params[_i - 4] = arguments[_i]; } this.items[this.items.length] = new menuitem(name, cost, active, handler, params); }; /** * Clear the menu of all items */ menusection.prototype.clear = function () { this.items = []; }; /** * Delete the item from the section * @param name Name of the item */ menusection.prototype.del = function (name) { this.items = cbjs.arrayRemove(this.items, this.lookup(name)); }; /** * List all items in the section */ menusection.prototype.list = function () { return this.items; }; /** * Lookup the item * @param name Name of the item to get */ menusection.prototype.lookup = function (name) { for (var _i = 0, _a = this.items; _i < _a.length; _i++) { var item = _a[_i]; if (item.name.toLowerCase() === name.toLowerCase()) { return item; } } return null; }; /** * Tries to find a match to this section, returning the menuitem if one is found, null otherwise * @param tip Tip to try to find a match for */ menusection.prototype.match = function (tip) { cb.log("match()"); var price; for (var _i = 0, _a = this.items; _i < _a.length; _i++) { var item = _a[_i]; cb.log("item: " + item.name); if (!item.active()) { cb.log("inactive"); continue; } cb.log("active"); price = item.cost; if (tip.amount === price) { cb.log("!! match !!"); return item; } } return null; }; /** * Print this section to chat */ menusection.prototype.print = function (user, limit, discounted) { if (discounted === void 0) { discounted = false; } notice.add("=====" + this.name + "====="); var price; for (var _i = 0, _a = this.items; _i < _a.length; _i++) { var item = _a[_i]; // Discount the item's price if appropriate price = discounted ? discount.apply(item, user) : item.cost; // Skip printing the item if it is not active, or if the price is higher than a specified limit if (item.active() == false || (limit != null && price >= limit)) continue; notice.add(price + emblems.token + item.name); } notice.apply(emblems.tipmenu); notice.post(user.user); }; return menusection; }()); /** * Manages notices, especially buffering notices */ var notice; /** * Manages notices, especially buffering notices */ (function (notice_1) { "use strict"; /** * Color to use in notices, if none specified */ notice_1.color = "#000000"; /** * Buffer of notices that haven't been posted */ var buffer = []; /** * Add the notice to the buffer * @param notice Notice to add */ function add(notice) { buffer[buffer.length] = notice; } notice_1.add = add; /** * Add the notices to the buffer * @param notices Notices to add */ function adds() { var notices = []; for (var _i = 0; _i < arguments.length; _i++) { notices[_i] = arguments[_i]; } for (var _a = 0, notices_1 = notices; _a < notices_1.length; _a++) { var notice_2 = notices_1[_a]; add(notice_2); } } notice_1.adds = adds; /** * Apply the emblem to each notice in the buffer * @param emblem Emblem to apply */ function apply(emblem) { for (var _i = 0, buffer_1 = buffer; _i < buffer_1.length; _i++) { var notice_3 = buffer_1[_i]; notice_3 = emblem + notice_3; } } notice_1.apply = apply; /** * Clear the buffer */ function clear() { buffer = []; } notice_1.clear = clear; /** * Print the help menu for notices * @param message Requesting message */ function help(message) { if (permissions.isAtLeastModerator(message)) { add("/note,notice <Message> --Send a notice to chat"); post(message.user); } } notice_1.help = help; /** * Post all notices in the buffer * @param to User to send to * @param textcolor Color of the text * @param weight Weight of the font * @param autoclear Clear the buffer automatically */ function post(to, textcolor, weight, autoclear) { if (to === void 0) { to = ""; } if (textcolor === void 0) { textcolor = notice_1.color; } if (weight === void 0) { weight = "bold"; } if (autoclear === void 0) { autoclear = true; } var message = buffer.join("\n"); cb.sendNotice(message, to, "#FFFFFF", textcolor, weight); if (autoclear) clear(); } notice_1.post = post; /** * Post all notices in the buffer * @param to Group to send to * @param textcolor Color of the text * @param weight Weight of the font */ function postGroup(to, textcolor, weight, autoclear) { if (textcolor === void 0) { textcolor = notice_1.color; } if (weight === void 0) { weight = "bold"; } if (autoclear === void 0) { autoclear = true; } var message = buffer.join("\n"); cb.sendNotice(message, "", "#FFFFFF", textcolor, weight, to); if (autoclear) clear(); } notice_1.postGroup = postGroup; /** * Send a notice * @param message Message to send * @param to User to send to * @param textcolor Color of the text * @param weight Weight of the font */ function send(message, to, textcolor, weight) { if (to === void 0) { to = ""; } if (textcolor === void 0) { textcolor = notice_1.color; } if (weight === void 0) { weight = "bold"; } cb.sendNotice(message, to, "#FFFFFF", textcolor, weight); } notice_1.send = send; /** * Send a notice * @param message Message to send * @param to Group to send to * @param textcolor Color of the text * @param weight Weight of the font */ function sendGroup(message, to, textcolor, weight) { if (textcolor === void 0) { textcolor = notice_1.color; } if (weight === void 0) { weight = "bold"; } cb.sendNotice(message, "", "#FFFFFF", textcolor, weight, to); } notice_1.sendGroup = sendGroup; /** * Try to parse a valid notice command, returning true if a valid command is found * @param message Requesting message */ function tryParse(message) { if (permissions.isAtLeastModerator(message)) { var m = message.m.split(" "); if (m.length === 0) return false; var command = m.shift().toLowerCase(); switch (command) { case "/note": case "/notice": send(emblems.notice + m.join(" ")); return true; default: return false; } } return false; } notice_1.tryParse = tryParse; })(notice || (notice = {})); /** * Provides permissions checking * A lot of these are provided by the object anyways, are are implemented for the sake of orthogonality * This is solely for permissions purposes, the levels are: * broadcaster > trusted user > moderator > fanclub > tipped tons > tipped alot > tipped > has tokens > gray */ var permissions; /** * Provides permissions checking * A lot of these are provided by the object anyways, are are implemented for the sake of orthogonality * This is solely for permissions purposes, the levels are: * broadcaster > trusted user > moderator > fanclub > tipped tons > tipped alot > tipped > has tokens > gray */ (function (permissions) { "use strict"; /** * List of trusted users; users with elevated permissions */ var trusted = []; /** * Trust the users * @param users Users to trust */ function entrust() { var users = []; for (var _i = 0; _i < arguments.length; _i++) { users[_i] = arguments[_i]; } for (var _a = 0, users_1 = users; _a < users_1.length; _a++) { var user_1 = users_1[_a]; trusted[trusted.length] = user_1; } } permissions.entrust = entrust; /** * Remove trust of the users * @param users Users to detrust */ function detrust() { var users = []; for (var _i = 0; _i < arguments.length; _i++) { users[_i] = arguments[_i]; } for (var _a = 0, users_2 = users; _a < users_2.length; _a++) { var user_2 = users_2[_a]; trusted = cbjs.arrayRemove(trusted, user_2); } } permissions.detrust = detrust; /** * Is the user the broadcaster? * @param user User to check */ function isBroadcaster(user) { return user.user === cb.room_slug; } permissions.isBroadcaster = isBroadcaster; /** * Is the user a trusted user? * @param user User to check */ function isTrusted(user) { return cbjs.arrayContains(trusted, user.user); } permissions.isTrusted = isTrusted; /** * Is the user at least a trusted user? * @param user User to check */ function isAtLeastTrusted(user) { return isBroadcaster(user) || isTrusted(user); } permissions.isAtLeastTrusted = isAtLeastTrusted; /** * Is the user a moderator? * @param user User to check */ function isModerator(user) { return user.is_mod; } permissions.isModerator = isModerator; /** * Is the user at least a moderator? * @param user User to check */ function isAtLeastModerator(user) { return isAtLeastTrusted(user) || isModerator(user); } permissions.isAtLeastModerator = isAtLeastModerator; /** * Is the user in the fanclub? * @param user User to check */ function isInFanclub(user) { return user.in_fanclub; } permissions.isInFanclub = isInFanclub; /** * Is the user at least in the fanclub? * @param user User to check */ function isAtLeastInFanclub(user) { return isAtLeastModerator(user) || isInFanclub(user); } permissions.isAtLeastInFanclub = isAtLeastInFanclub; /** * Has the user tipped tons recently? * @param user User to check */ function hasTippedTons(user) { return user.tipped_tons_recently; } permissions.hasTippedTons = hasTippedTons; /** * Has the user at least tipped tons recently? * @param user User to check */ function hasAtLeastTippedTons(user) { return isAtLeastInFanclub(user) || hasTippedTons(user); } permissions.hasAtLeastTippedTons = hasAtLeastTippedTons; /** * Has the user tipped alot recently? * @param user User to check */ function hasTippedAlot(user) { return user.tipped_alot_recently; } permissions.hasTippedAlot = hasTippedAlot; /** * Has the user at least tipped alot recently? * @param user User to check */ function hasAtLeastTippedAlot(user) { return hasAtLeastTippedTons(user) || hasTippedAlot(user); } permissions.hasAtLeastTippedAlot = hasAtLeastTippedAlot; /** * Has the user tipped recently? * @param user User to check */ function hasTipped(user) { return user.tipped_recently; } permissions.hasTipped = hasTipped; /** * Has the user at least tipped recently? * @param user User to check */ function hasAtLeastTipped(user) { return hasAtLeastTippedAlot(user) || hasTipped(user); } permissions.hasAtLeastTipped = hasAtLeastTipped; /** * Does the user have tokens? * @param user User to check */ function hasTokens(user) { return user.has_tokens; } permissions.hasTokens = hasTokens; /** * Does the user at least have tokens? * @param user User to check */ function hasAtLeastTokens(user) { return hasAtLeastTipped(user) || hasTokens(user); } permissions.hasAtLeastTokens = hasAtLeastTokens; /** * Prints the help for permissions * @param message Requesting message */ function help(message) { if (permissions.isAtLeastTrusted(message)) { notice.add("/trust,trusted"); } if (permissions.isBroadcaster(message)) { notice.add(emblems.blank + "add <User>+ --Entrust the users"); notice.add(emblems.blank + "del,delete,rem,remove <User>+ --Detrust the users"); } if (permissions.isAtLeastTrusted(message)) { notice.add(emblems.blank + "list --List all trusted users"); notice.post(message.user); } } permissions.help = help; /** * Try to parse a permissions command, returning true if a valid command is found * @param message Requesting message */ function tryParse(message) { if (permissions.isBroadcaster(message)) { var m = message.m.split(" "); if (m.length === 0) return false; var command = m.shift().toLowerCase(); switch (command) { case "/detrust": for (var _i = 0, m_1 = m; _i < m_1.length; _i++) { var user_3 = m_1[_i]; detrust(user_3); } return true; case "/entrust": for (var _a = 0, m_2 = m; _a < m_2.length; _a++) { var user_4 = m_2[_a]; entrust(user_4); } return true; case "/trust": case "/trusted": if (m.length === 0) return false; var operation = m.shift().toLowerCase(); switch (operation) { case "add": for (var _b = 0, m_3 = m; _b < m_3.length; _b++) { var user_5 = m_3[_b]; entrust(user_5); } return true; case "del": case "delete": case "rem": case "remove": for (var _c = 0, m_4 = m; _c < m_4.length; _c++) { var user_6 = m_4[_c]; detrust(user_6); } return true; case "help": help(message); return true; case "list": notice.send(trusted.join(", "), message.user); return true; default: return false; } } } return false; } permissions.tryParse = tryParse; })(permissions || (permissions = {})); /** * Manages rotating notices */ var rotater; /** * Manages rotating notices */ (function (rotater) { "use strict"; /** * Number, in minutes, between notices */ rotater.lapse = 3; /** * Notices in rotation */ var pool = []; /** * Index of the notice pool; current position */ var n = 0; /** * Add a notice to rotation * @param notice Notice to add */ function add(message) { pool[pool.length] = message; notice.send(emblems.notice + "'" + message + "' has been added to rotation"); } rotater.add = add; /** * Delete a notice from rotation * @param notice Notice literal or position to delete */ function del(message) { if (typeof message === "string") { pool = cbjs.arrayRemove(pool, message); notice.send(emblems.notice + "'" + message + "' has been removed from rotation"); } else if (typeof message === "number") { notice.send(emblems.notice + "'" + pool[message - 1] + "' has been removed from rotation"); pool = cbjs.arrayRemove(pool, pool[message - 1]); } } rotater.del = del; /** * Print the help menu for rotating notices * @param message Requesting message */ function help(message) { notice.add("/rotater,rotating,rotation"); if (permissions.isAtLeastModerator(message)) { notice.add(emblems.blank + "add <Message> --Add the notice to rotation"); } if (permissions.isAtLeastTrusted(message)) { notice.add(emblems.blank + "del,delete (<Message> | <Position>) --Delete the notice from rotation"); } notice.add(emblems.blank + "list,print --List all notices in rotation"); notice.post(message.user); notice.clear(); } rotater.help = help; /** * List all notices in rotation */ function list() { return pool; } rotater.list = list; function print(user) { var i = 0; for (var _i = 0, pool_1 = pool; _i < pool_1.length; _i++) { var note = pool_1[_i]; notice.add(++i + ") " + note); } notice.post(user.user); notice.clear(); } rotater.print = print; /** * Rotate and post notice */ function rotate() { notice.send(emblems.notice + pool[n++]); n %= pool.length; cb.setTimeout(rotate, rotater.lapse * 60 * 1000); } /** * Start the rotater */ function start() { cb.setTimeout(rotate, rotater.lapse * 60 * 1000); } rotater.start = start; /** * Try to parse a rotater command, returning true if a valid command is found * @param message Requesting message */ function tryParse(message) { var m = message.m.split(" "); if (m.length === 0) return false; var command = m.shift().toLowerCase(); switch (command) { case "/rotater": case "/rotating": case "/rotation": // Command is valid, break out break; default: return false; } if (m.length === 0) return false; var operation = m.shift().toLowerCase(); switch (operation) { case "add": if (permissions.isAtLeastModerator(message)) { rotater.add(m.join(" ")); return true; } return false; case "del": case "delete": if (permissions.isAtLeastTrusted(message)) { var pos = m.shift(); if (isNaN(Number(pos))) { // pos isn't actually a position, so put it back m.unshift(pos); rotater.del(m.join(" ")); } else { rotater.del(Number(pos)); } return true; } return false; case "help": help(message); return true; case "list": case "print": print(message); return true; default: return false; } } rotater.tryParse = tryParse; })(rotater || (rotater = {})); /** * Manages the room subject */ var subject; /** * Manages the room subject */ (function (subject) { "use strict"; /** * Revert back to default room title */ function revert() { cb.changeRoomSubject(subject.defaultTitle + " " + subject.hashtags); } subject.revert = revert; /** * Sets the room title * @param title New room title */ function set(title) { cb.changeRoomSubject(title + " " + subject.hashtags); } subject.set = set; })(subject || (subject = {})); var cb; (function (cb) { cb.settings_choices = [ { name: "toyName", label: "Toy Name", type: "str", defaultValue: "Device", required: true, }, { name: "startStopCost", label: "Start/Stop Cost", type: "int", minValue: 1, required: true, }, { name: "incSpeedCost", label: "Increase Speed Cost", type: "int", minValue: 1, required: false, }, { name: "decSpeedCost", label: "Decrease Speed Cost", type: "int", minValue: 1, required: false, }, { name: "speeds", label: "Speeds", type: "int", minValue: 1, required: true, }, { name: "swcPatternCost", label: "Switch Pattern Cost", type: "int", minValue: 1, required: false, }, { name: "patterns", label: "Patterns", type: "int", minValue: 1, required: true, }, { name: "foreground", label: "Text Color", type: "str", defaultValue: "#000000", required: true, } ]; })(cb || (cb = {})); cb.onDrawPanel(function () { if (edge.speedControl() && edge.patternControl()) { return { 'template': '3_rows_of_labels', 'row1_label': 'Power', 'row1_value': edge.on ? "on" : "off", 'row2_label': 'Speed', 'row2_value': edge.currentSpeed + "/" + edge.maxSpeed, 'row3_label': 'Pattern', 'row3_value': edge.currentPattern + "/" + edge.maxPattern, }; } else if (edge.speedControl()) { return { 'template': '3_rows_12_22_31', 'row1_label': 'Power', 'row1_value': edge.on ? "on" : "off", 'row2_label': 'Speed', 'row2_value': edge.currentSpeed + "/" + edge.maxSpeed, 'row3_value': '-----', }; } else if (edge.patternControl()) { return { 'template': '3_rows_12_22_31', 'row1_label': 'Power', 'row1_value': edge.on ? "on" : "off", 'row2_label': 'Pattern', 'row2_value': edge.currentPattern + "/" + edge.maxPattern, 'row3_value': '-----', }; } else { return { 'template': '3_rows_12_21_31', 'row1_label': 'Power', 'row1_value': edge.on ? "on" : "off", 'row2_value': '-----', 'row3_value': '-----', }; } }); cb.onEnter(function (user) { notice.adds("For help with EdgeApp, see '/edgehelp'", "Check out the controls with '/edgemenu'"); notice.apply(emblems.hitachi); notice.post(user.user); notice.clear(); }); cb.onMessage(function (message) { // Mark message as spam if a foreslash is found at the begining if (message.m.trim().charAt(0) === "/") message['X-Spam'] = true; /** Whether a valid command has been found while parsing */ var validCommand = false; // Attempt to parse a command // This is goal-directed parsing, essentially, JavaScript just doesn't have any good syntax for it // While a command has not been found, keep trying to parse commands // When a command has been found, mark it as spam, which in turn avoids further attempts at parsing if (!validCommand) validCommand = bank.tryParse(message); if (!validCommand) validCommand = edge.tryParse(message); if (!validCommand) validCommand = tipmenu.tryParse(message); return message; }); cb.onTip(function (tip) { var match = tipmenu.match(tip); if (match != null) { notice.send(emblems.hitachi + tip.from_user + " has tipped for " + match.name); match.handle(tip, [tip.from_user]); cb.drawPanel(); } }); /** * Banks the excess tips for control */ var bank; /** * Banks the excess tips for control */ (function (bank) { /** * Who has start/stops and how many? */ var toggles = []; /** * Who has speed increases and how many? */ var increases = []; /** * Who has speed decreases and how many? */ var decreases = []; /** * Who has pattern shifts and how many? */ var shifts = []; /** * Prints the help menu for the bank * @param message */ function help(message) { notice.add("/bank --Get your banked device control tips"); notice.add(emblems.blank + "power,toggle --Uses a banked toggle if you have any"); notice.add(emblems.blank + "inc,increase --Uses a banked speed increase if you have any"); notice.add(emblems.blank + "dec,decrease --Uses a banked speed decrease if you have any"); notice.add(emblems.blank + "pattern,shift --Uses a banked pattern shift if you have any"); notice.post(message.user); } bank.help = help; /** * Add a toggle to the bank * Creates a new entry if necessary, otherwise adding to an existing one * @param user Username the toggle belongs to * @param amount Amount the user has */ function addToggle(user, amount) { if (amount === void 0) { amount = 1; } var item = lookupToggle(user); if (item != null) { item[1] += amount; } else { toggles[toggles.length] = [user, amount]; } } bank.addToggle = addToggle; /** * Use a toggle if any are banked * Returns true if a toggle was banked under that name, false otherwise * @param user Username the toggle belongs to */ function useToggle(user) { var item = lookupToggle(user); if (item != null) { notice.send(emblems.hitachi + user + " has used a banked power toggle"); item[1]--; edge.togglePower(); return true; } else { return false; } } bank.useToggle = useToggle; /** * Lookup if the user has any toggles banked, null if not found * @param user Name to lookup */ function lookupToggle(user) { cb.log("lookupToggle()"); cb.log("toggles: " + toggles); for (var _i = 0, toggles_1 = toggles; _i < toggles_1.length; _i++) { var item = toggles_1[_i]; if (item[0] == user) { return item; } } return null; } bank.lookupToggle = lookupToggle; /** * Add an increase to the bank * Creates a new entry if necessary, otherwise adding to an existing one * @param user Username the increase belongs to * @param amount Amount the user has */ function addIncrease(user, amount) { if (amount === void 0) { amount = 1; } cb.log("addIncrease()"); var item = lookupIncrease(user); cb.log("item: " + item); if (item != null) { item[1] += amount; } else { increases[increases.length] = [user, amount]; } } bank.addIncrease = addIncrease; /** * Use a speed increase if any banked * Returns true if an increase was banked under that name, false otherwise * @param user Username the speed increase belongs to */ function useIncrease(user) { var item = lookupIncrease(user); if (item != null) { notice.send(emblems.hitachi + user + " has used a banked speed increase"); item[1]--; edge.incSpeed(user); return true; } else { return false; } } bank.useIncrease = useIncrease; /** * Lookup if the user has any speed increases banked, null if not found * @param user Name to lookup */ function lookupIncrease(user) { cb.log("lookupIncrease()"); cb.log("increases: " + increases); for (var _i = 0, increases_1 = increases; _i < increases_1.length; _i++) { var item = increases_1[_i]; if (item[0] == user) { return item; } } return null; } bank.lookupIncrease = lookupIncrease; /** * Add a decrease to the bank * Creates a new entry if necessary, otherwise adding to an existing one * @param user Username the decrease belongs to * @param amount Amount the user has */ function addDecrease(user, amount) { if (amount === void 0) { amount = 1; } var item = lookupDecrease(user); if (item != null) { item[1] += amount; } else { decreases[decreases.length] = [user, amount]; } } bank.addDecrease = addDecrease; /** * Use a speed decrease if any banked * Returns true if a decrease was banked under that name, false otherwise * @param user Username the speed decrease belongs to */ function useDecrease(user) { var item = lookupDecrease(user); if (item != null) { notice.send(emblems.hitachi + user + " has used a banked speed decrease"); item[1]--; edge.decSpeed(user); return true; } else { return false; } } bank.useDecrease = useDecrease; /** * Lookup if the user has any speed decreases banked, null if not found * @param user Name to lookup */ function lookupDecrease(user) { cb.log("lookupDecrease()"); cb.log("decreases: " + decreases); for (var _i = 0, decreases_1 = decreases; _i < decreases_1.length; _i++) { var item = decreases_1[_i]; if (item[0] == user) { return item; } } return null; } bank.lookupDecrease = lookupDecrease; /** * Add a pattern shift to the bank * Creates a new entry if necessary, otherwise adding to an existing one * @param user Username the shift belongs to * @param amount Amount the user has */ function addShift(user, amount) { if (amount === void 0) { amount = 1; } var item = lookupShift(user); if (item != null) { item[1] += amount; } else { shifts[shifts.length] = [user, amount]; } } bank.addShift = addShift; /** * Use a pattern shift if any banked * Returns true if a shift was banked under that name, false otherwise * @param user Username the pattern shift belongs to */ function useShift(user) { var item = lookupShift(user); if (item != null) { notice.send(emblems.hitachi + user + " has used a banked pattern shift"); item[1]--; edge.swcPattern(); return true; } else { return false; } } bank.useShift = useShift; /** * Lookup if the user has any pattern shifts banked, null if not found * @param user Name to lookup */ function lookupShift(user) { cb.log("lookupShift()"); cb.log("shifts: " + shifts); for (var _i = 0, shifts_1 = shifts; _i < shifts_1.length; _i++) { var item = shifts_1[_i]; if (item[0] == user) { return item; } } return null; } bank.lookupShift = lookupShift; /** * Try to parse a bank command, return true if a valid command is found * @param message Requesting message */ function tryParse(message) { var m = message.m.split(" "); if (m.length === 0) return false; var command = m.shift().toLowerCase(); switch (command) { case "/bank": if (m.length === 0) { var toggles_2 = lookupToggle(message.user); cb.log("toggles: " + toggles_2); if (toggles_2 == null) { notice.add("Power Toggles: 0"); } else { notice.add("Power Toggles: " + toggles_2[1].toString()); } var increases_2 = lookupIncrease(message.user); cb.log("increases: " + increases_2); if (increases_2 == null) { notice.add("Speed Increases: 0"); } else { notice.add("Speed Increases: " + increases_2[1].toString()); } var decreases_2 = lookupDecrease(message.user); cb.log("decreases: " + decreases_2); if (decreases_2 == null) { notice.add("Speed Decreases: 0"); } else { notice.add("Speed Decreases: " + decreases_2[1].toString()); } var shifts_2 = lookupShift(message.user); cb.log("shifts: " + shifts_2); if (shifts_2 == null) { notice.add("Pattern Shifts: 0"); } else { notice.add("Pattern Shifts: " + shifts_2[1].toString()); } notice.post(message.user); return true; } else { var operation = m.shift().toLowerCase(); switch (operation) { case "power": case "toggle": useToggle(message.user); return true; case "inc": case "increase": useIncrease(message.user); return true; case "dec": case "decrease": useDecrease(message.user); return true; case "pattern": case "shift": useShift(message.user); return true; } } default: return false; } } bank.tryParse = tryParse; })(bank || (bank = {})); /** * Manager for edging */ var edge; /** * Manager for edging */ (function (edge) { /** * What the toy should be refered to as */ edge.toyName = "Toy"; /** * Whether edging is occuring * (or is supposed to be, anyways) */ edge.on = false; /** * The max level of speeds the toy has */ edge.maxSpeed = 1; /** * The current level of speed of the toy */ edge.currentSpeed = 1; /** * Cost to start or stop the toy */ edge.startStopCost = null; /** * Cost to increase speed of the toy */ edge.incSpeedCost = null; /** * Cost to decrease speed of the toy */ edge.decSpeedCost = null; /** * The max pattern the toy has */ edge.maxPattern = null; /** * The current pattern of the toy */ edge.currentPattern = 1; /** * Cost to switch pattern of the toy */ edge.swcPatternCost = null; /** * Decrease the speed of the toy */ function decSpeed(user) { if (edge.currentSpeed > 1) { edge.currentSpeed--; notice.send(emblems.hitachi + edge.toyName + " speed decreased"); } else { notice.send(emblems.hitachi + edge.toyName + " already at slowest speed"); bank.addDecrease(user); } } edge.decSpeed = decSpeed; /** * Increase the speed of the toy */ function incSpeed(user) { if (edge.currentSpeed < edge.maxSpeed) { edge.currentSpeed++; notice.send(emblems.hitachi + edge.toyName + " speed increased"); } else { notice.send(emblems.hitachi + edge.toyName + " already at fastest speed"); bank.addIncrease(user); } } edge.incSpeed = incSpeed; /** * Does the device have controllable patterns? */ function patternControl() { return edge.swcPatternCost != null; } edge.patternControl = patternControl; /** * Does the device have controllable speed? */ function speedControl() { return edge.incSpeedCost != null && edge.decSpeedCost != null; } edge.speedControl = speedControl; /** * Switch the pattern of the toy */ function swcPattern() { if (edge.currentPattern === edge.maxPattern) { edge.currentPattern = 1; } else { edge.currentPattern++; } notice.send(emblems.hitachi + edge.toyName + " pattern changed"); } edge.swcPattern = swcPattern; /** * Toggle the toy on or off */ function togglePower() { edge.on = !edge.on; if (edge.on) { notice.send(emblems.hitachi + edge.toyName + " turned on"); } else { notice.send(emblems.hitachi + edge.toyName + " turned off"); } tipmenu.build(); } edge.togglePower = togglePower; /** * Try to parse an edge command, returning true if a valid command is found * @param message Requesting message */ function tryParse(message) { var m = message.m.split(" "); if (m.length === 0) return false; var command = m.shift().toLowerCase(); switch (command) { case "/help": notice.send("For help with EdgeApp, please use: /edgehelp"); return true; } return false; } edge.tryParse = tryParse; })(edge || (edge = {})); var tipmenu; (function (tipmenu) { /** * Device menusection */ tipmenu.device = new menusection(edge.toyName); /** * Build the tipmenu with whatever settings were set */ function build() { tipmenu.device.clear(); if (edge.on) { tipmenu.device.add(edge.toyName + " Off", edge.startStopCost, function () { return true; }, edge.togglePower); } else { tipmenu.device.add(edge.toyName + " On", edge.startStopCost, function () { return true; }, edge.togglePower); } if (edge.incSpeedCost != null) { tipmenu.device.add("Increase Speed", edge.incSpeedCost, function () { return true; }, edge.incSpeed); } if (edge.decSpeedCost != null) { tipmenu.device.add("Decrease Speed", edge.decSpeedCost, function () { return true; }, edge.decSpeed); } if (edge.swcPatternCost != null) { tipmenu.device.add("Switch Pattern", edge.swcPatternCost, function () { return true; }, edge.swcPattern); } } tipmenu.build = build; /** * Print the help messages for tipmenu * @param message Requesting message */ function help(message) { notice.add("/edgemenu,tipmenu,menu --Get the edging tipmenu"); notice.post(message.user); } tipmenu.help = help; /** * Attempt to match the tip to an item in the menu * @param tip Tip to match */ function match(tip) { var price; for (var _i = 0, _a = tipmenu.device.list(); _i < _a.length; _i++) { var item = _a[_i]; price = item.cost; if (tip.amount === price) return item; } return null; } tipmenu.match = match; /** * Print the tipmenu to chat * @param message Requesting message */ function print(message) { tipmenu.device.print(message); } tipmenu.print = print; /** * Try to parse a tipmenu command, returning true if a valid command is found * @param message Requesting message */ function tryParse(message) { var m = message.m.split(" "); if (m.length === 0) return false; var command = m.shift().toLowerCase(); switch (command) { case "/edge": if (m.length === 0) return false; var command_1 = m.shift().toLowerCase(); switch (command_1) { case "help": help(message); return true; case "menu": print(message); return true; default: return false; } case "/edgehelp": bank.help(message); help(message); return true; case "/edgemenu": case "/tipmenu": case "/menu": print(message); return true; } return false; } tipmenu.tryParse = tryParse; })(tipmenu || (tipmenu = {})); /** * Initialization code */ { edge.toyName = cb.settings.toyName; edge.maxSpeed = cb.settings.speeds; edge.incSpeedCost = cb.settings.incSpeedCost; edge.decSpeedCost = cb.settings.decSpeedCost; edge.maxPattern = cb.settings.patterns; notice.color = cb.settings.foreground; rotater.add("Check out edging controls with: /edgemenu"); rotater.lapse = 5; rotater.start(); tipmenu.build(); }
© Copyright Chaturbate 2011- 2025. All Rights Reserved.