Bots Home
|
Create an App
ttttttttttt
Author:
test012135896
Description
Source Code
Launch Bot
Current Users
Created by:
Test012135896
/********************************************** * App name: "Vicky's Nickname Bot" * Author: "radiantgecko" * ———————————————————————————————————— * Version: 0.1.1 * Build date: 14 June 2016 * ———————————————————————————————————— * Based on concept by K. de Haan * ———————————————————————————————————— **********************************************/ "use strict"; var _createClass = (function() { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function(Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } if (cb == null) { var cb = { changeRoomSubject: function changeRoomSubject(new_subject) {}, drawPanel: function drawPanel() {}, log: function log(message) {}, onDrawPanel: function onDrawPanel(func) {}, onEnter: function onEnter(func) {}, onLeave: function onLeave(func) {}, onMessage: function onMessage(func) {}, onShowStatus: function onShowStatus(func) {}, onTip: function onTip(func) {}, room_slug: "", sendNotice: function sendNotice(message, to_user, background, foreground, weight, to_group) { console.log(message); }, setTimeout: function setTimeout(func, msec) {}, settings_choices: { label: "Nicknames Pre-set List (user@alias,...)", minLength: 5, name: "presets", required: !1, type: "str" }, settings: {}, tipOptions: function tipOptions(func) {}, limitCam_start: function limitCam_start(message, allowed_users) {}, limitCam_stop: function limitCam_stop() {}, limitCam_addUsers: function limitCam_addUsers(allowed_users) {}, limitCam_removeUsers: function limitCam_removeUsers(removed_users) {}, limitCam_removeAllUsers: function limitCam_removeAllUsers() {}, limitCam_userHasAccess: function limitCam_userHasAccess(user) {}, limitCam_allUsersWithAccess: function limitCam_allUsersWithAccess() {}, limitCam_isRunning: function limitCam_isRunning() {} }; } else { cb.settings_choices = [{ label: "Nicknames Pre-set List (allfanclubmembers@alias,user@alias,...)", minLength: 5, name: "presets", required: !1, type: "str" }]; } var App = function App(name, version, type) { _classCallCheck(this, App); this.name = name; this.version = version; this.type = type; this.callCbHandlers = (function() { cb.log("calling onenter handler"); cb.onEnter(function(user) { UserHandler.onEnter(user); }); cb.log("calling onmsg handler"); cb.onMessage(function(msg) { MsgHandler.onMessage(msg); }); })(); }; var NBotMain = (function(_App) { _inherits(NBotMain, _App); function NBotMain() { _classCallCheck(this, NBotMain); _get(Object.getPrototypeOf(NBotMain.prototype), "constructor", this).call(this, "Bubble's Nickname Bot", "0.1.0", "bot"); this.version_extra = "gold"; // internal: script version - extra info (e.g. alpha1, beta1, rc1). set to null if stable this.version_type = "stable"; // internal: script version type (stable, alpha, beta, dev preview, experimental, release candidate) this.revision = null; // internal: script revision (set to null if none). Don't use with experimental versions this.rc_version = null; // internal: script RC version number. Use only with release candidates this.author = "radiantgecko"; // developer this.build_date = "8 June 2016"; // script build date // colors this.Color = { dark_green: "#002a15", med_green: "#0ad80a", lite_green: "#a2ffa2", dark_red: "#4a0000", med_red: "#d80a00", lite_red: "#ff0a11", dark_blue: "#001a70", med_blue: "#000adc", lite_blue: "#1144ff", holo_blue: "#33b5e5", mtrl_teal: "#009688", mtrl_bluegray: "#607d8b", pink_lace: "#ffddf4", white: "#fff", black: "#000", // misc syntax: "#995b00", notice_grn: "#284", notice_prp: "#6900cc", notice_red: "#e84a10", hilite: "#eee5ff", hvtext: "#d80a00", hvback: "#ffffbf", info: "#144d8c", error: "#b94a48" }; this.Command = { addhl: "/addhilite", addnick: "/addnick", addtc: "/addtextcolor", listhl: "/listhilite", listnick: "/listnick", presets: "/presets", listtc: "/listtextcolor", removehl: "/removehilite", removenick: "/removenick", removetc: "/removetextcolor", nbhelp: "/nbhelp" }; this.List = { customHilite: {}, customNick: {}, customTC: {}, }; this.Misc = { start_time: new Date(), dash_line: new Array(37).join("\u2014"), room_host: cb.room_slug }; } _createClass(NBotMain, [{ key: "main", value: function main() { cb.sendNotice(dashLine + "\n* \"" + this.name, broadcaster, "", color.notice_grn, "bold"); if (this.revision != null) { cb.sendNotice("* Version: " + this.version + " (" + this.revision + ")", broadcaster, "", color.notice_grn, "bold"); } else if (this.version_type == "release_candidate") { cb.sendNotice("* Version: " + this.version + "-" + this.version_extra + " (" + this.rc_version + ")", broadcaster, "", color.notice_grn, "bold"); } else if (this.version_type == "alpha" || this.version_type == "beta" || this.version_type == "devpreview" || this.version_type == "experimental") { cb.sendNotice("* Version: " + this.version + "-" + this.version_extra, broadcaster, "", color.notice_grn, "bold"); } else { cb.sendNotice("* Version: " + this.version, broadcaster, "", color.notice_grn, "bold"); } cb.sendNotice("* Build date: " + this.build_date, broadcaster, "", color.notice_grn, "bold"); cb.sendNotice("* Type \"" + command.nbhelp + "\" for a list of available commands." + "\n" + dashLine, broadcaster, "", color.notice_grn, "bold"); if (this.revision != null) { cb.sendNotice("\"" + this.name + "\" version " + this.version + " (" + this.revision + ") (" + this.build_date + ") has started.", "", "", color.info, "bold"); } else if (this.version_type == "release_candidate") { cb.sendNotice("\"" + this.name + "\" version " + this.version + "-" + this.version_extra + " (" + this.rc_version + ") (" + this.build_date + ") has started.", "", "", color.info, "bold"); } else if (this.version_type == "alpha" || this.version_type == "beta" || this.version_type == "devpreview" || this.version_type == "experimental") { cb.sendNotice("\"" + this.name + "\" version " + this.version + "-" + this.version_extra + " (" + this.build_date + ") has started.", "", "", color.info, "bold"); } else { cb.sendNotice("\"" + this.name + "\" version " + this.version + " (" + this.build_date + ") has started.", "", "", color.info, "bold"); } cb.sendNotice(dashLine + "\n* \"" + this.name + "\" is running.\n* Type \"" + command.nbhelp + "\" for a list of available commands.\n" + dashLine, "", "", color.notice_prp, "bold", "red"); var e, h; var c = (cb.settings.presets || "").split(/[\s,]+/); var b = 0; for (e = c.length; b < e; b++) h = c[b].split("@"), 2 === h.length && h[0].length && h[1].length ? this.List.customNick[h[0].toLowerCase().trim()] = this.sanitize(h[1]) : cb.sendNotice("Error: malformed alias record (user@alias): " + c[b], cb.room_slug, "#f37e7e"); } }, { key: "sanitize", value: function sanitize(a) { var c = /\\u([0-9a-f]{4})/gi, b, e = []; for (a = a || ""; null !== (b = c.exec(a));) e.push(b[1]); if (e.length) for (e = e.filter(w), c = 0, b = e.length; c < b; c++) a = a.replace(new RegExp("\\\\u" + e[c], "gi"), String.fromCharCode(parseInt(e[c], 16))); a = a.replace(/(\r\n|\n|\r|\\n)/gm, " ").trim(); /(^|\s):([\w\-][\w\-]+)$/.test(a) && (a += " "); /^:([\w\-][\w\-]+)(\s|$)/.test(a) && (a = " " + a); return a } }, { key: "addHilite", value: function addHilite(user, color) { if (this.isValidColorCode(color)) { if (color.charAt(0) == "#") this.List.customHilite[user] = color; else this.List.customHilite[user] = "#" + color; } } }, { key: "addNick", value: function addNick(user, nick) { if (nick != null) { this.List.customNick[user] = nick; } } }, { key: "addTextColor", value: function addTextColor(user, color) { if (this.isValidColorCode(color)) { if (color.charAt(0) == "#") this.List.customTC[user] = color; else this.List.customTC[user] = "#" + color; } } }, { key: "isValidColorCode", value: function isValidColorCode(code) { var validChars = /[A-F0-9]+$/i; var invalidChars = /[G-Z]+/i; if (code != null) { if (code.length == 3 || code.length == 6) { if (validChars.exec(code) && !invalidChars.exec(code)) { cb.log("Valid html color code; applying."); return true; } else if (invalidChars.exec(code)) { cb.log("Invalid code. Valid color codes must contain only hexadecimal numbers from 0 to F."); return false; } } else if (code.charAt(0) == "#" && (code.length == 4 || code.length == 7)) { if (validChars.exec(code) && !invalidChars.exec(code)) { cb.log("Valid html color code; applying."); return true; } else if (invalidChars.exec(code)) { cb.log("Invalid code. Valid color codes must contain only hexadecimal numbers from 0 to F."); return false; } } else { cb.log("Invalid code. Valid color codes must have between 3 or 6 chars (excluding the hash) and contain only hex numbers."); return false; } } } }, { key: "listHilite", value: function listHilite(user) { cb.sendNotice(dashLine + "\n* List of users with custom highlights", user, "", color.holo_blue, "bold"); for (var name in this.List.customHilite) { cb.sendNotice(name + " - " + this.List.customHilite[name], user, "", color.holo_blue, "bold"); } cb.sendNotice(dashLine, user, "", color.holo_blue, "bold"); } }, { key: "listNick", value: function listNick(user) { cb.sendNotice(dashLine + "\n* List of users with custom nicknames", user, "", color.holo_blue, "bold"); for (var name in this.List.customNick) { cb.sendNotice(name + " - " + this.List.customNick[name], user, "", color.holo_blue, "bold"); } cb.sendNotice(dashLine, user, "", color.holo_blue, "bold"); } }, { key: "munge", value: function munge(a) { a = (a || "").trim(); a = a.replace(/\s/g, "\\u0020").replace(/,/g, "\\u002c").replace(/@/g, "\\u0040"); return a.replace(/[^\u0020-\u007e]/g, function(a) { return "\\u" + (a.charCodeAt(0) + 65536).toString(16).slice(1).toLowerCase() }) } }, { key: "presets", value: function presets(user) { cb.sendNotice(dashLine + "\n* List of users with custom nicknames to paste into settings", user, "", color.holo_blue, "bold"); var l = []; for (var name in this.List.customNick) { l.push(name + "@" + this.munge(this.List.customNick[name])); } cb.sendNotice("Pre-set List: " + (l.length ? l.join(", ") : "(empty)"), user, "", color.holo_blue, "bold"); cb.sendNotice(dashLine, user, "", color.holo_blue, "bold"); } }, { key: "listTextColor", value: function listTextColor(user) { cb.sendNotice(dashLine + "\n* List of users with custom text colors", user, "", color.holo_blue, "bold"); for (var name in this.List.customTC) { cb.sendNotice(name + " - " + this.List.customTC[name], user, "", color.holo_blue, "bold"); } cb.sendNotice(dashLine, user, "", color.holo_blue, "bold"); } }, { key: "removeHilite", value: function removeHilite(user, mod) { if (user != null) { if (this.List.customHilite[user]) { delete this.List.customHilite[user]; cb.sendNotice("* Removed highlight color from user \"" + user + "\".", mod, "", color.med_red, "bold"); } else { cb.sendNotice("* User \"" + user + "\" doesn't have a highlight color.", mod, "", color.med_red, "bold"); } } } }, { key: "removeNick", value: function removeNick(user, mod) { if (user != null) { if (this.List.customNick[user]) { delete this.List.customNick[user]; cb.sendNotice("* Removed nickname from user \"" + user + "\".", mod, "", color.med_red, "bold"); } else { cb.sendNotice("* User \"" + user + "\" doesn't have a nickname.", mod, "", color.med_red, "bold"); } } } }, { key: "removeTextColor", value: function removeTextColor(user, mod) { if (user != null) { if (this.List.customTC[user]) { delete this.List.customTC[user]; cb.sendNotice("* Removed highlight color from user \"" + user + "\".", mod, "", color.med_red, "bold"); } else { cb.sendNotice("* User \"" + user + "\" doesn't have a highlight color.", mod, "", color.med_red, "bold"); } } } }, { key: "showHelpOptions", value: function showHelpOptions(user) { var help = dashLine + "\n***** " + this.name + " Commands List *****"; help += "\n* /addhilite <user> <HTML color code> - Adds a highlight color to a user."; help += "\n* /addnick <user> <nickname> - Adds a nickname to a user."; help += "\n* /addtextcolor <user> <HTML color code> - Adds a text color to a user."; help += "\n* /listhl - Lists all users who have highlight colors."; help += "\n* /listnick - Lists all users who have nicknames."; help += "\n* /presets - Lists all users who have nicknames to copy/paste into settings or save in a file."; help += "\n* /listtextcolor - Lists all users who have text colors."; help += "\n* /removehl <user> - Removes the highlight color from a user."; help += "\n* /removenick <user> - Removes the nickname from a user."; help += "\n* /removetextcolor <user> - Removes the text color from a user.\n" + dashLine; cb.sendNotice(help, user, "", color.info, "bold"); } }]); return NBotMain; })(App); var NickBot = new NBotMain(); var broadcaster = NickBot.Misc.room_host; var color = NickBot.Color; var command = NickBot.Command; var dashLine = NickBot.Misc.dash_line; var Handler = function Handler(name, version, parent) { _classCallCheck(this, Handler); this.name = name; this.version = version; this.parent = parent; }; var MHandler = (function(_Handler) { _inherits(MHandler, _Handler); function MHandler() { _classCallCheck(this, MHandler); _get(Object.getPrototypeOf(MHandler.prototype), "constructor", this).call(this, "Message Handler", "0.91.0001a-NickBot", NickBot); } // don't use static methods _createClass(MHandler, [{ key: "onMessage", value: function onMessage(msg) { var m = msg.m.split(" "); var u = msg.user; var isBc = u == broadcaster; var isMod = msg.is_mod; var isFan = msg.in_fanclub; var isValid = false; if (m[0].charAt(0) == "/") { msg["X-Spam"] = true; var forbidden = "* Not enough privileges to use \"" + m[0] + "\"\n* Only moderators and the room host can use this command."; var commandVal2 = null; for (var i = 2; i < m.length; i++) { if (i == 2) commandVal2 = m[i]; else commandVal2 += " " + m[i]; } switch (m[0]) { case command.addhl: isValid = true; if (isBc || isMod) { if (m[1] != null) { if (commandVal2 != null) { if (NickBot.isValidColorCode(commandVal2)) { NickBot.addHilite(m[1], commandVal2); cb.sendNotice("* Added highlight color \"" + commandVal2 + "\" to user \"" + m[1] + "\".", u, "", color.mtrl_teal, "bold"); } else { cb.sendNotice("* \"" + commandVal2 + "\" isn't a valid color code.", u, "", color.error, "bold"); } } else { cb.sendNotice("* Syntax: /addhilite <user> <color code>.", u, "", color.syntax, "bold"); } } else { cb.sendNotice("* Syntax: /addhilite <user> <color code>.", u, "", color.syntax, "bold"); } } else { cb.sendNotice(forbidden, u, "", color.error, "bold"); } break; case command.addnick: isValid = true; if (isBc || isMod) { if (m[1] != null) { if (commandVal2 != null) { NickBot.addNick(m[1], commandVal2); cb.sendNotice("* Added nickname \"" + commandVal2 + "\" to user \"" + m[1] + "\".", u, "", color.mtrl_teal, "bold"); } else { cb.sendNotice("* Syntax: /addnick <user> <nickname>.", u, "", color.syntax, "bold"); } } else { cb.sendNotice("* Syntax: /addnick <user> <nickname>.", u, "", color.syntax, "bold"); } } else { cb.sendNotice(forbidden, u, "", color.error, "bold"); } break; case command.addtc: isValid = true; if (isBc || isMod) { if (m[1] != null) { if (commandVal2 != null) { if (NickBot.isValidColorCode(commandVal2)) { NickBot.addTextColor(m[1], commandVal2); cb.sendNotice("* Added text color \"" + commandVal2 + "\" to user \"" + m[1] + "\".", u, "", color.mtrl_teal, "bold"); } else { cb.sendNotice("* \"" + commandVal2 + "\" isn't a valid color code.", u, "", color.error, "bold"); } } else { cb.sendNotice("* Syntax: /addtextcolor <user> <color code>.", u, "", color.syntax, "bold"); } } else { cb.sendNotice("* Syntax: /addtextcolor <user> <color code>.", u, "", color.syntax, "bold"); } } else { cb.sendNotice(forbidden, u, "", color.error, "bold"); } break; case command.listhl: isValid = true; if (isBc || isMod) { NickBot.listHilite(u); } else { cb.sendNotice(forbidden, u, "", color.error, "bold"); } break; case command.listnick: isValid = true; if (isBc || isMod) { NickBot.listNick(u); } else { cb.sendNotice(forbidden, u, "", color.error, "bold"); } break; case command.presets: isValid = true; if (isBc || isMod) { NickBot.presets(u); } else { cb.sendNotice(forbidden, u, "", color.error, "bold"); } break; case command.listtc: isValid = true; if (isBc || isMod) { NickBot.listTextColor(u); } else { cb.sendNotice(forbidden, u, "", color.error, "bold"); } break; case command.removehl: isValid = true; if (isBc || isMod) { if (m[1] != null) { NickBot.removeHilite(m[1], u); } else { cb.sendNotice("* Syntax: /removehilite <user>.", u, "", color.syntax, "bold"); } } else { cb.sendNotice(forbidden, u, "", color.error, "bold"); } break; case command.removenick: isValid = true; if (isBc || isMod) { if (m[1] != null) { NickBot.removeNick(m[1], u); } else { cb.sendNotice("* Syntax: /removenick <user>.", u, "", color.syntax, "bold"); } } else { cb.sendNotice(forbidden, u, "", color.error, "bold"); } break; case command.removetc: isValid = true; if (isBc || isMod) { if (m[1] != null) { NickBot.removeTextColor(m[1], u); } else { cb.sendNotice("* Syntax: /removetextcolor <user>.", u, "", color.syntax, "bold"); } } else { cb.sendNotice(forbidden, u, "", color.error, "bold"); } break; case command.nbhelp: isValid = true; if (isBc || isMod) { NickBot.showHelpOptions(u); } else { cb.sendNotice(forbidden, u, "", color.error, "bold"); } break; } if (isValid == false) cb.sendNotice("* \"" + m[0] + "\" isn't a valid command.\n* Type \"" + command.nbhelp + "\" for a full list of available commands.", u, "", color.error, "bold"); } else { if (isFan && NickBot.List.customNick["allfanclubmembers"]) { msg.m = "[ " + NickBot.List.customNick["allfanclubmembers"] + " ] " + msg.m; } else if (NickBot.List.customNick[u]) { msg.m = "[ " + NickBot.List.customNick[u] + " ] " + msg.m; } if (NickBot.List.customHilite[u]) { msg.background = NickBot.List.customHilite[u]; } if (NickBot.List.customTC[u]) { msg.c = NickBot.List.customTC[u]; } } return msg; } }]); return MHandler; })(Handler); var UHandler = (function(_Handler2) { _inherits(UHandler, _Handler2); function UHandler() { _classCallCheck(this, UHandler); _get(Object.getPrototypeOf(UHandler.prototype), "constructor", this).call(this, "User Handler", "0.91.0001a-NickBot", NickBot); } // don't use static methods _createClass(UHandler, [{ key: "onEnter", value: function onEnter(user) { if (user.is_mod) { cb.sendNotice(dashLine + "\n* \"" + NickBot.name + "\" is running.\n* Type \"/" + command.nbhelp + "\" for a list of available commands.\n" + dashLine, user, "", color.notice_prp, "bold"); } } }]); return UHandler; })(Handler); var UserHandler = new UHandler(); var MsgHandler = new MHandler(); NickBot.main();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.