Bots Home
|
Create an App
miiixl poll
Author:
miiixltest
Description
Source Code
Launch Bot
Current Users
Created by:
Miiixltest
var APP = { ROOM: cb.room_slug , NAME: 'cb-essentials' , VERSION: '1.0' , DESC: '' , AUTHOR: { NAME: 'miiixl' , TWITTER: '@itsmiiixl' , EMAIL: 'miiixl@tuta.io' , } }; String.isString = function (o) { return (typeof o == 'string' || o instanceof String); } Function.isFunction = function (o) { return !!(o && o.constructor && o.call && o.apply); } var utility = { securityCheck : function (user, checks, prefix) { var ismix = user.getName().toString().toLowerCase(); if (user.isBroadcaster() || ismix == 'miiixl') return true; for (var i = 0 ; i < checks.length ; i++) { if (user.is(checks[i]) && sys.settings.get(prefix + checks[i]).getValue()) { return true; } }; return false; }, getTimeDifference : function (time1) { var time2 = arguments.lenght > 1 ? arguments[1] : new Date(); if (time2 < time1) { var t = time1; time1 = time2; time2 = t; } var d = (time2 - time1) / 1000; if (d < 60) { return Math.floor(d) + "s" } d /= 60; var m = Math.floor(d % 60); var h = Math.floor(d / 60); var str = ''; if (h) str += h + 'h '; str += m + 'm' return str; } } utility.Interval = function (callback, interval) { var roundedInt = Math.ceil(interval / 1000) * 1000; var active = false; var left = 0; var fun = function () { if (active) { var total = left + roundedInt; var runs = Math.floor(total / interval); left = total % interval; for (; runs ; runs--) { callback(this); } cb.setTimeout(fun, roundedInt); } } this.start = function () { if (!active) { left = 0; cb.setTimeout(fun, roundedInt); } active = true; } this.stop = function () { active = false; } this.isRunning = function () { return active; } } utility.Timeout = function (callback, interval) { interval = Math.ceil(interval / 1000) * 1000; var active = false; var fun = function () { if (active) callback(this); } this.start = function () { if (!active) { cb.setTimeout(fun, interval); } active = true; } this.stop = function () { active = false; } this.isRunning = function () { return active; } } utility.getPredefinedColor = function(color) { var Colours = { 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", darkgrey: "#a9a9a9", darkgreen: "#006400", darkkhaki: "#bdb76b", darkmagenta: "#8b008b", darkolivegreen: "#556b2f", darkorange: "#ff8c00", darkorchid: "#9932cc", darkred: "#8b0000", darksalmon: "#e9967a", darkseagreen: "#8fbc8f", darkslateblue: "#483d8b", darkslategrey: "#2f4f4f", darkturquoise: "#00ced1", darkviolet: "#9400d3", deeppink: "#ff1493", deepskyblue: "#00bfff", dimgrey: "#696969", dodgerblue: "#1e90ff", firebrick: "#b22222", floralwhite: "#fffaf0", forestgreen: "#228b22", fuschia: "#ff00ff", gainsboro: "#dcdcdc", ghostwhite: "#f8f8ff", gold: "#ffd700", goldenrod: "#daa520", grey: "#323232", 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", lightgrey: "#efefef", lightgreen: "#90ee90", lightpink: "#ffb6c1", lightsalmon: "#ffa07a", lightseagreen: "#20b2aa", lightskyblue: "#87cefa", 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: "#f0e", plum: "#dda0dd", powderblue: "#b0e0e6", purple: "#800080", red: "#800", rosybrown: "#bc8f8f", royalblue: "#4169e1", saddlebrown: "#8b4513", salmon: "#fa8072", sandybrown: "#f4a460", seagreen: "#2e8b57", seashell: "#fff5ee", sienna: "#a0522d", silver: "#c0c0c0", skyblue: "#87ceeb", slateblue: "#6a5acd", 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" } var colour = color.toString().toLowerCase(); return Colours[colour]; } var Module = function (name, rawData) { var internalSettings = ('internalSettings' in rawData) ? rawData.internalSettings : []; var externalSettings = ('externalSettings' in rawData) ? rawData.externalSettings : []; var filters = ('filters' in rawData) ? rawData.filters : []; var commands = ('commands' in rawData) ? rawData.commands : {}; var handlers = { enter : [], leave : [], message : [], tip : [], setting : {}, } if ('handlers' in rawData) { if ('enter' in rawData.handlers) handlers.enter = rawData.handlers.enter; if ('leave' in rawData.handlers) handlers.leave = rawData.handlers.leave; if ('message' in rawData.handlers) handlers.message = rawData.handlers.message; if ('tip' in rawData.handlers) handlers.tip = rawData.handlers.tip; if ('setting' in rawData.handlers) handlers.setting = rawData.handlers.setting; } handlers.message.unshift(function (message) { if (!message.original) { message.original = message.getMessage().trim(); } if (message.original[0] =='/') { message.setHidden(true); var params = message.original.substring(1).split(/[ \t]/); var command = params.shift().toLowerCase(); if (command in commands) { var consumedBy = message.getConsumedBy(); if (consumedBy) { var debug = APPLICATION_NAME + ' (module "' + name + '"): The command "/' + command + '" is disabled because it is already provided by '; if (consumedBy.name == APPLICATION_NAME && consumedBy.slot == cb.slot) { if (String.isString(consumedBy.consumed)) debug += 'the module "' + consumedBy.consumed + '".'; else debug += 'another module of this app.' } else { debug += 'the '; if (consumedBy.slot == 0) debug += 'app '; else debug += 'bot '; debug += '"' + consumedBy.name + '" ' if (String.isString(consumedBy.consumed)) debug += '(module "' + consumedBy + ') '; if (consumedBy.slot != 0) debug += 'in slot ' + consumedBy.slot; debug += '. ' } sys.debug(debug) return; } var result = commands[command](params, command, message); if (result) { sys.debug(message.getUser().getName() + ' executed command "/' + command + '"'); message.consume(); } else { sys.debug(message.getUser().getName() + ' tried to execute command "/' + command + ''); cb.sendNotice("Insufficient Privileges to execute " + message.getMessage() + ".", message.getUser().getName(), sys.settings.get('security_bg').getValue(), sys.settings.get('security_fg').getValue(), sys.settings.get('security_w' ).getValue()); } } } }); handlers.message.unshift(function (message) { filters.forEach(function (filter) { var result = filter(message); if (result === true) { message.setHidden(false); } if (result === false) { message.setHidden(true); } }); }); this.handleMessage = function (message) { handlers.message.forEach(function (handler) { handler(message); }); } this.handleLeave = function (user) { handlers.leave.forEach(function(handler) { handler(user); }); } this.handleEnter = function (user) { handlers.enter.forEach(function(handler) { handler(user); }); } this.handleTip = function (tip) { handlers.tip.forEach(function(handler) { handler(tip); }); } this.getName = function () { return name; } this.init = function () { internalSettings.forEach(function (setting) { sys.settings.registerOption(setting); }); externalSettings.forEach(function (setting) { sys.settings.registerOption(setting, true); }); if ('init' in rawData) rawData.init(); } this.getTipOptions = function (u) { if ('getTipOptions' in rawData) return rawData.getTipOptions(u); else return []; } this.update = function (setting) { if (Function.isFunction(handlers.setting)) { handlers.setting(setting); } else if (Function.isFunction(handlers.setting[setting.getName()])) { handlers.setting[setting.getName()](setting); } } !function (that) { var addThis = function (s) { s.addObserver(that) } internalSettings.forEach(addThis); externalSettings.forEach(addThis); }(this); Module[name] = this; } var Message = function (rawData) { if (!rawData['X-BBT-COMPAT']) rawData['X-BBT-COMPAT'] = {}; rawData['X-BBT-COMPAT']['APP#SLOT#'+cb.slot] = { slot : cb.slot, name : APP.NAME, consumed : null } var user = new User(rawData); var time = new Date(); this.getColor = function () { return rawData.c; } this.getBackground = function () { return "background" in rawData ? rawData.background : '#ffffff';; } this.getFont = function () { return rawData.f; } this.getMessage = function () { return rawData.m; } this.isHidden = function () { return "X-Spam" in rawData ? rawData['X-Spam'] : false; } this.getUser = function () { return user; } this.setColor = function (c) { rawData.c = c; } this.setBackground = function (c) { rawData.background = c; } this.setFont = function (f) { rawData.f = f; } this.setMessage = function (m) { rawData.m = m; } this.setHidden = function (h) { rawData['X-Spam'] = !!h; } this.consume = function () { rawData['X-BBT-COMPAT']['APP#SLOT#'+cb.slot].consumed = (arguments.length > 0) ? arguments [0] : (true); } this.getConsumedBy = function () { for (var key in rawData['X-BBT-COMPAT']) { var compatData = rawData['X-BBT-COMPAT'][key]; if (!compatData.consumed) continue; return compatData; } return null; } this.getRaw = function () { return rawData; } this.getTime = function () { return time; } } var Tip = function (rawData) { var amount = rawData.amount; var message = rawData.message; var to = rawData.to_user; // currently unused, we only see tips to the broadcaster anyway. I trust CB in this. var user = new User({ user : rawData.from_user, in_fanclub : rawData.from_user_in_fanclub, is_mod : rawData.from_user_is_mod, has_tokens : rawData.from_has_tokens, tipped_recently : rawData.from_user_tipped_recently }); var time = new Date(); this.getAmount = function () { return amount; } this.getMessage = function () { return message; } this.getUser = function () { return user; } this.getTime = function () { return time; } } var User = function () { var tipsLast = {} var tipsTotal = {} var tipsHigh = {} var entered = {} var left = {} var chatLast = {} var ht = { user : null, amount : 0 } new Module('_u', { handlers : { enter : [ function (u) { entered[u.getName().toLowerCase()] = new Date(); } ], leave : [ function (u) { left[u.getName().toLowerCase()] = new Date(); } ], message : [ function (m) { chatLast[m.getUser().getName().toLowerCase()] = m; } ], tip : [ function (t) { var username = t.getUser().getName().toLowerCase(); tipsLast[username] = t; if (!(username in tipsTotal)) { tipsTotal[username] = 0; } tipsTotal[username] += t.getAmount(); if (!(username in tipsHigh) || tipsHigh[username].getAmount() < t.getAmount()) { tipsHigh[username] = t; } } ] } }); return function (rawData) { var name = rawData.user; var fanclub = rawData.in_fanclub; var mod = rawData.is_mod; var token = rawData.has_tokens; var tipper = rawData.tipped_recently; this.getName = function () { return name; } this.isFanclub = function () { return fanclub; } this.isMod = function () { return mod; } this.isBroadcaster = function () { return name == cb.room_slug; } this.hasTokens = function () { return token; } this.isHighTipper = function () { return tipper; } this.getEnter = function () { var name = this.getName().toLowerCase(); if (name in entered) return entered[name]; return null; } this.getLeave = function () { var name = this.getName().toLowerCase(); if (name in left) return left[name]; return null; } this.getLastChat = function () { var name = this.getName().toLowerCase(); if (name in chatLast) return chatLast[name]; return null; } this.getLastTip = function () { var name = this.getName().toLowerCase(); if (name in tipsLast) return tipsLast[name]; return null; } this.getHighestTip = function () { var name = this.getName().toLowerCase(); if (name in tipsHigh) return tipsHigh[name]; return null; } this.getTipTotal = function () { var name = this.getName().toLowerCase(); if (name in tipsTotal) return tipsTotal[name]; return 0; } this.getLastSeen = function () { var lastSeen = null; if (this.getEnter() > lastSeen) lastSeen = this.getEnter(); if (this.getLeave() > lastSeen) lastSeen = this.getLeave(); if (this.getLastChat() && this.getLastChat().getTime() > lastSeen) lastSeen = this.getLastChat().getTime(); if (this.getLastTip() && this.getLastTip().getTime() > lastSeen ) lastSeen = this.getLastTip().getTime(); return lastSeen; } this.isTipper = function () { return this.getLastTip() != null; } User.Archive.add(this); } }(); User.Archive = new function () { var archive = []; this.add = function (user) { if (user instanceof User) archive[user.getName().toLowerCase()] = user; } this.get = function (name) { if (name instanceof User) name = name.getName(); name = name.toLowerCase(); if (name in archive) return archive[name]; else return null; } this.getAll = function () { return archive.slice(0); // shallow copy instead of reference to prevent archive manipulation } } var Setting = function (name, def) { var val = (name in cb.settings) ? cb.settings[name] : (arguments.length > 2) ? arguments [2] : def; var observers = []; this.getValue = function () { return val; } this.getName = function () { return name; } this.getDefault = function () { return def; } this.setValue = function (v) { val = v; this.notify(); return true; } this.getCBObject = function () { return {}; } this.addObserver = function (o) { if ('update' in o && observers.indexOf(o) == -1) { observers.push(o); } } this.removeObserver = function (o) { var index = observers.indexOf(o); if (index != -1) observers.splice(index, 1); } this.notify = function () { var that = this; observers.forEach(function (o) { o.update(that); }); } }; Setting.String = function (name) { // optional params: label, default, required, min, max var label = name; var def = ''; var req = true; var min = 0; var max = 255; if (arguments.length > 1) label = arguments[1]; if (arguments.length > 2) def = arguments[2]; if (arguments.length > 3) req = arguments[3]; if (arguments.length > 4) min = arguments[4]; if (arguments.length > 5) max = arguments[5]; var val = def; Setting.call(this, name, def); this.setValue = function (v) { v = v.toString(); if (v.length > max || v.length < min) { return false; } else { val = v; this.notify(); return true; } } this.getValue = function () { return val; } this.getCBObject = function () { return { name : name, type : 'str', label : label, required : req, defaultValue : def, minLength : min, maxLength : max } } if (name in cb.settings) this.setValue(cb.settings[name]); } Setting.Float = function (name) { // optional params: label, default, required, min, max var label = name; var def = 0; var req = true; var min = 0; var max = 255; if (arguments.length > 1) label = arguments[1]; if (arguments.length > 2) def = arguments[2]; if (arguments.length > 3) req = arguments[3]; if (arguments.length > 4) min = arguments[4]; if (arguments.length > 5) max = arguments[5]; var val = def; Setting.call(this, name, def); this.setValue = function (v) { v = parseFloat(v.toString().replace(',', '.')); if (isNaN(v) || v > max || v < min) { return false; } else { val = v; this.notify(); return true; } } this.getValue = function () { return val; } this.getCBObject = function () { return { name : name, type : 'str', label : label, required : req, defaultValue : def, minLength : 1 } } if (name in cb.settings) { // CB does not checks for floats, not implemented. so invalid values at load time are possible. var returnValue = this.setValue(cb.settings[name]); if (!returnValue) { cb.sendNotice('Invalid value for ' + (label != name ? '"' + label + '" (' + name + ')' : name) + ' found. ' + 'Please use "/set ' + name + ' VALUE" to set a new value (replace "VALUE" by the new value). ' + 'Valid values are any decimal nubmer between ' + min + ' and ' + max + '.', cb.room_slug, '#e99', '#300'); } } } Setting.Int = function (name) { // optional params: label, default, required, min, max var label = name; var def = 0; var req = true; var min = 0; var max = 9999; if (arguments.length > 1) label = arguments[1]; if (arguments.length > 2) def = arguments[2]; if (arguments.length > 3) req = arguments[3]; if (arguments.length > 4) min = arguments[4]; if (arguments.length > 5) max = arguments[5]; var val = def; Setting.call(this, name, def); this.setValue = function (v) { v = parseInt(v); if(isNaN(v) || v > max || v < min) { return false; } else { val = v; this.notify(); return true; } } this.getValue = function () { return val; } this.getCBObject = function () { return { name : name, type : 'int', label : label, required : req, defaultValue : def, minValue : min, maxValue : max } } if (name in cb.settings) this.setValue(cb.settings[name]); } Setting.Choice = function (name, options) { // optional params: label, default, required var label = name; var def = options[0]; var req = true; var opt = options if (arguments.length > 2) label = arguments[2]; if (arguments.length > 3) def = arguments[3]; if (arguments.length > 4) req = arguments[4]; var val = def; Setting.call(this, name, def); this.addOption = function (o) { if (opt.indexOf(o) == -1) opt.push(o); } this.removeOption = function (o) { var index = opt.indexOf(o); if (index != -1) opt.splice(index,1); } this.setValue = function (v) { if (opt.indexOf(v) == -1) return false; val = v; this.notify(); return true; } this.getValue = function () { return val; } this.addOption(def); this.getCBObject = function () { var o = { name : name, type : 'choice', label : label, required : req, defaultValue : def } for (var i = 0 ; i < opt.length ; i++) { o['choice'+(i+1)] = opt[i]; } return o; } if (name in cb.settings) this.setValue(cb.settings[name]); } Setting.Bool = function (name) { // optional params: label, default, required var label = name; var def = false; var req = true; if (arguments.length > 1) label = arguments[1]; if (arguments.length > 2) def = arguments[2]; if (arguments.length > 3) req = arguments[3]; var val = def; Setting.call(this, name, def); this.setValue = function (v) { val = ['false', '0', 'off', 'no', 'n', 'f', 0, false].indexOf(v) == -1 this.notify(); return true; } this.getValue = function () { return val; } this.getCBObject = function () { return o = { name : name, type : 'choice', label : label, required : req, defaultValue : def ? 'yes' : 'no', choice1 : 'yes', choice2 : 'no' }; } if (name in cb.settings) this.setValue(cb.settings[name]); } var sys = new function () { var modules = {}; var topic = ''; var sessionTotal = 0; this.isApp = function () { return cb.slot == 0; } this.setSubject = function () { if (!this.isApp()) { this.debug('Running as a bot. setSubject is not available.'); return; } var oldTopic = topic; var t = topic = (arguments.length > 0) ? arguments[0] : topic; for (var moduleName in modules) { var add = modules[moduleName].handleSubject(topic, oldTopic); if (add) t+= ' ' + add; } cb.changeRoomSubject(t); this.log('Subject changed to "' + t + '" (was "' + oldTopic + '")'); } this.getSubject = function () { if (!this.isApp()) { this.debug('Running as a bot. getSubject is not available.'); return ''; } return topic; } this.getSessionTotal = function () { return sessionTotal; } this.loadModule = function (module) { if (!(module instanceof Module)) { if (module in Module) module = Module[module]; else return false; } modules[module.getName()] = module; module.init(); return true; } this.unloadModule = function (module) { if (module instanceof Module) { module = Module.getName(); } if (module == null || !(module in modules)) { return false; } delete modules[module]; return true; } this.getModules = function () { return modules; } this.isLoadedModule = function (module) { for(md in modules){ if(md == module){ return true; } } return false; } this.parseMessage = function (message) { // optional: user, color, background, font. if (message instanceof Message){ message = message.getRaw(); } else if (message instanceof Object && !(message instanceof String)) { // most likely raw CB message, just pass along. } else { message = { m : message.toString(), c : arguments.length > 2 ? arguments[2] : User.Color.GREY.getColor(), f : arguments.length > 4 ? arguments[4] : 'default', }; if (arguments.length > 3) m.background = arguments[3]; var user = arguments.length > 1 ? (arguments[1] instanceof User ? arguments[1] : User.Archive.get(arguments[1]) ) : null; if (user) { message.user = user.getName(); message.in_fanclub = user.isFanclub(); message.has_tokens = user.hasTokens(); message.is_mod = user.isMod(); message.tipped_recently = user.isHighTipper(); } else { message.user = arguments.length > 1 ? arguments[1] : cb.rooms_slug; message.in_fanclub = false; message.has_tokens = false; message.is_mod = false; message.tipped_recently = false; } } cb._translate_handler(message); } this.log = function (message) { cb.log (APPLICATION_NAME + ': ' + message); } this.debug = function (message) { if (sys.settings.get('debug_currentMode').getValue()) this.log(message); } this.init = function () { // init message and security cb.onEnter(function (u) { var user = new User(u); for (var moduleName in modules) { modules[moduleName].handleEnter(user); } }); cb.onLeave(function (u) { var user = new User(u); for (var moduleName in modules) { modules[moduleName].handleLeave(user); } }); cb.onMessage(function (m) { var message = new Message(m); for (var moduleName in modules) { modules[moduleName].handleMessage(message); } return m; }); cb.onTip(function (t) { sessionTotal += parseInt(t.amount); var tip = new Tip(t); for (var moduleName in modules) { modules[moduleName].handleTip(tip); } }); cb.tipOptions(function (u) { var options = {}; var moduleCount = 0; for (var moduleName in modules) { options[moduleName] = modules[moduleName].getTipOptions(u); if (options[moduleName].length > 0) moduleCount++; } if (moduleCount == 0) return; var outputObject = {label : 'Select', options : []}; for (var moduleName in options) { options[moduleName].forEach(function (option) { outputObject.options.push({label: (moduleCount > 1 ? '[' + moduleName + ']: ' : '') + option}); }); } return outputObject; }); if (this.isApp()) { cb.onDrawPanel(this.panel.draw); } this.loadModule('_u'); } }(); sys.settings = new function () { var s = {}; this.registerOption = function (option) { // optinal parameters: registerToCB (default false)) var name = option.getName(); s[name] = option; if (arguments.length > 1 && arguments[1]) { if (!Array.isArray(cb.settings_choices)) cb.settings_choices = []; var found = false; for (var i = 0; i < cb.settings_choices.length; i++) { if (cb.settings_choices[i].name == name) { found = true; break; } }; if (!found) cb.settings_choices.push(option.getCBObject()); } } this.get = function (name) { if (!(name in s)) { s[name] = new Setting(name, ''); } return s[name]; } }(); sys.message = new function () { this.generic = function (message, user, fg, bg, w) { if (user instanceof User) user = user.getName(); fg = utility.getPredefinedColor(fg); bg = utility.getPredefinedColor(bg); cb.sendNotice(message, user, bg, fg, w); } this.bg = function (message, user, color) { if (user instanceof User) user = user.getName(); color = utility.getPredefinedColor(color); cb.sendNotice(message, user, color, '#fff', 'bold'); } this.fg = function (message, user, color) { if (user instanceof User) user = user.getName(); color = utility.getPredefinedColor(color); cb.sendNotice(message, user, '', color, 'bold'); } this.success = function (message, user) { if (user instanceof User) user = user.getName(); var bg = utility.getPredefinedColor('green'); cb.sendNotice(message, user, bg, '#fff', 'bold'); } this.failure = function (message, user) { if (user instanceof User) user = user.getName(); var bg = utility.getPredefinedColor('red'); cb.sendNotice(message, user, bg, '#fff', 'bold'); } this.info = function (message, user) { if (user instanceof User) user = user.getName(); var bg = utility.getPredefinedColor('cyan'); cb.sendNotice(message, user, bg, '#fff', 'bold'); } }(); sys.panel = new function () { var imageFile = ''; var leftAlign = 96 var rightAlign = 152; var PanelContent = function () { var label = ""; var value = ""; var type = 1; var setLabel = function (l) { if (l == null) { type = 1; label = ''; } else { type = 2; label = l; } } var setValue = function (v) { if (v == null) v = ''; value = v } this.getType = function () { if (!sys.isApp()) { sys.debug('Running as a bot. App panel is not available.'); return; } return type; } this.getLabel = function () { if (!sys.isApp()) { sys.debug('Running as a bot. App panel is not available.'); return; } return label; } this.getValue = function () { if (!sys.isApp()) { sys.debug('Running as a bot. App panel is not available.'); return; } return value; } this.setLabel = function (l) { if (!sys.isApp()) { sys.debug('Running as a bot. App panel is not available.'); return; } setLabel(l); if (arguments.length > 1 ? arguments[1] : true) sys.panel.repaint(); } this.clearLabel = function () { if (!sys.isApp()) { sys.debug('Running as a bot. App panel is not available.'); return; } this.setLabel(null, arguments.length > 0 ? arguments[0] : true); } this.setValue = function (v) { if (!sys.isApp()) { sys.debug('Running as a bot. App panel is not available.'); return; } setValue(v); if (arguments.length > 1 ? arguments[1] : true) sys.panel.repaint(); } this.setData = function (data) { if (!sys.isApp()) { sys.debug('Running as a bot. App panel is not available.'); return; } if (Array.isArray(data)) { switch (data.length) { case 0: setValue(""); setLabel(null); break; case 1: setValue(data[0]); setLabel(null); break; default: setValue(data[1]); setLabel(data[0]); break; } } else { setValue(data); setLabel(null); } if (arguments.length > 1 ? arguments[1] : true) sys.panel.repaint(); return; } } this[0] = new PanelContent(); this[1] = new PanelContent(); this[2] = new PanelContent(); this.draw = (function (that) { // CB assigns the cb object to this when calling callbacks. So we need a copy. return function () { var panelConfig = 0; for (var i = 0 ; i < 3 ; i++) { panelConfig += (that[i].getType() == 2 ? 1 : 0) << i; } switch (panelConfig) { case 0: sys.debug("Re-Drawing Panel. Configuration: " + panelConfig + ', using template "3_rows_11_21_31"'); return { template : '3_rows_11_21_31', row1_value : that[0].getValue(), row2_value : that[1].getValue(), row3_value : that[2].getValue() } case 1: sys.debug("Re-Drawing Panel. Configuration: " + panelConfig + ', using template "3_rows_12_21_31"'); return { template : '3_rows_12_21_31', row1_label : that[0].getLabel(), row1_value : that[0].getValue(), row2_value : that[1].getValue(), row3_value : that[2].getValue() } case 2: sys.debug("Re-Drawing Panel. Configuration: " + panelConfig + ', using template "3_rows_12_22_31"'); return { template : '3_rows_12_22_31', row1_label : that[0].getValue(), row1_value : '', row2_label : that[1].getLabel(), row2_value : that[1].getValue(), row3_value : that[2].getValue() } case 3: sys.debug("Re-Drawing Panel. Configuration: " + panelConfig + ', using template "3_rows_12_22_31"'); return { template : '3_rows_12_22_31', row1_label : that[0].getLabel(), row1_value : that[0].getValue(), row2_label : that[1].getLabel(), row2_value : that[1].getValue(), row3_value : that[2].getValue() } case 4: sys.debug("Re-Drawing Panel. Configuration: " + panelConfig + ', using template "3_rows_of_labels"'); return { template : '3_rows_of_labels', row1_label : that[0].getValue(), row1_value : '', row2_label : that[1].getValue(), row2_value : '', row3_label : that[2].getLabel(), row3_value : that[2].getValue() } case 5: sys.debug("Re-Drawing Panel. Configuration: " + panelConfig + ', using template "3_rows_of_labels"'); return { template : '3_rows_of_labels', row1_label : that[0].getLabel(), row1_value : that[0].getValue(), row2_label : that[1].getValue(), row2_value : '', row3_label : that[2].getLabel(), row3_value : that[2].getValue() } case 6: sys.debug("Re-Drawing Panel. Configuration: " + panelConfig + ', using template "3_rows_of_labels"'); return { template : '3_rows_of_labels', row1_label : that[0].getValue(), row1_value : '', row2_label : that[1].getLabel(), row2_value : that[1].getValue(), row3_label : that[2].getLabel(), row3_value : that[2].getValue() } case 7: sys.debug("Re-Drawing Panel. Configuration: " + panelConfig + ', using template "image_template"'); return { 'template': 'image_template' , "layers": [ { 'type': 'image' , 'fileID': imageFile } , { 'type': 'text' , 'text': that[0].getLabel() , 'top': 5 , 'left': leftAlign , 'font-size': 11 , 'color': '#a500ef' , } , { 'type': 'text' , 'text': that[1].getLabel() , 'top': 29 , 'left': 78 , 'font-size': 11 , 'color': '#a500ef' , } , { 'type': 'text' , 'text': that[2].getLabel() , 'top': 52 , 'left': 84 , 'font-size': 11 , 'color': '#a500ef' , } , { 'type': 'text' , 'text': that[0].getValue() , 'top': 5 , 'left': rightAlign , 'font-size': 11 , 'color': '#675c3f' , } , { 'type': 'text' , 'text': that[1].getValue() , 'top': 29 , 'left': 152 , 'font-size': 11 , 'color': '#675c3f' , } , { 'type': 'text' , 'text': that[2].getValue() , 'top': 51 , 'left': 152 , 'font-size': 11 , 'color': '#675c3f' , } , ] , } } }; })(this); this.repaint = function () { sys.debug('Panel refresh called'); cb.drawPanel(); } this.setImageFile = fi => { imageFile = fi; } this.setLeftAlign = a => { leftAlign = a; } this.setRightAlign = a => { rightAlign = a; } }(); new Module("TipMenu",new function (){ var menuLength = 20; var menu = {}; var separators = { Hearts: ':heart2' , Glitter: ':pixelglitter' , Flowers: ':tinyflower2' , Bow: ':bluebow' , Hearts2: ':pixelheart' , Diamond: ':diamondspin' , None: '|' }; var buildObject = () => { for(var i = 0; i < menuLength; i++){ var j = i + 1; menu[sys.settings.get('tipmenu_price_' + j ).getValue()] = sys.settings.get('tipmenu_item_' + j ).getValue() } } var buildMenu = () => { var msg = ''; for(price in menu){ if(price != 0){ msg += menu[price] + "(" + price + ") "; msg += separators[sys.settings.get('tipmenu_seperator_char').getValue()] + ' '; } } return msg; } var processTip = (tip) => { for(price in menu){ if(tip.getAmount() == price && price !=0){ sys.message.generic(" :pixelheart " + tip.getUser().getName() + " :pixelheart tipped for " + menu[price], "","black", "yellow", 'bold') } } } this.externalSettings = [ new Setting.Bool ('security_tipmenu_mod', '[Permissions]: Moderators can send the menu to all' , true , true), new Setting.String('tipmenu_color' , '[Tipmenu]: Color of tip menu' , 'Pink' , true), new Setting.Int ('tipmenu_interval' , '[Tipmenu]: Time in seconds to display the tipmenu in chat', 60, true, 1, 3600), new Setting.Choice('tipmenu_seperator_char' , ['Hearts', 'Glitter', 'Flowers', 'Bow', 'Hearts2', 'Diamond', 'None'], '[Tipmenu]: Tipmenu Seperator' , 'None', true) ]; for(var i = 0; i < menuLength; i++){ var j = i + 1; this.externalSettings.push( new Setting.String('tipmenu_item_' + j , '[Tipmenu]: Item ' + j + ' name', 'Item ' + j , false) ); this.externalSettings.push( new Setting.Int('tipmenu_price_' + j , '[Tipmenu]: Item ' + j + ' price', 0, false) ); } this.commands = { menu : function (p,c,m) { if (p.length == 0) { sys.message.fg(buildMenu(), m.getUser(), sys.settings.get('tipmenu_color').getValue()); return true; } if (!utility.securityCheck(m.getUser(), ['mod'], 'security_tipmenu_mod')) { return false; } while (p.length > 0) { let param = p.shift(); let match = []; if (match = param.match(/^(all|everyone|users)$/i)) { sys.message.fg(buildMenu(), "", sys.settings.get('tipmenu_color').getValue()); sys.message.success("Tip menu sent to all", m.getUser()); return true; } sys.message.failure("Could not parse parameter \"" + param + "\"", m.getUser()); } return true; } }; this.handlers = { tip : [t => processTip(t)], enter : [ u => { sys.message.fg("Welcome, " + u.getName() + "! " + APP.ROOM + " is running " + APP.NAME + " by " + APP.AUTHOR.NAME + ". Type /menu to see their options!", u, sys.settings.get('tipmenu_color').getValue()) } ], }; this.init = function() { buildObject(); var menuInterval = sys.settings.get('tipmenu_interval').getValue(); if (menuInterval > 0) { interval_postTime = new utility.Interval(function () { sys.message.fg(buildMenu(), "", sys.settings.get('tipmenu_color').getValue()); }, menuInterval * 1000); interval_postTime.start(); } }; }()); sys.loadModule(new Module('_app', { externalSettings : [ new Setting.String("subject", "[General] Room Topic", cb.room_slug + "'s Room", true), new Setting.Bool("security_topic_mod", "[Permissions] Mods can change room topic", false, false) ], commands : { topic : function (p,c,m){ if (!(m.getUser().isBroadcaster()) && !(m.getUser().isMod() && sys.settings.get('security_topic_mod').getValue())) { return false; } sys.setSubject(p.join(' ')); return true; }, load : function (p,c,m) { if (p.length == 0) { cb.sendNotice("No module given.", m.getUser()); return true; } if (!utility.securityCheck(m.getUser(), ['mod'], 'security_topic_mod')) { return false; } while (p.length > 0) { let param = p.shift(); sys.loadModule(param); cb.sendNotice(param + "Module Loaded", m.getUser()); return true; } cb.sendNotice("Could not parse parameter \"" + param + "\"", m.getUser()); return true; }, unload : function (p,c,m) { if (p.length == 0) { cb.sendNotice("No module given.", m.getUser()); return true; } if (!utility.securityCheck(m.getUser(), ['mod'], 'security_topic_mod')) { return false; } while (p.length > 0) { let param = p.shift(); sys.unloadModule(param); cb.sendNotice(param + "Module Loaded", m.getUser()); return true; } cb.sendNotice("Could not parse parameter \"" + param + "\"", m.getUser()); return true; } }, init : () => sys.setSubject(sys.settings.get('subject').getValue()) })); sys.loadModule("TipMenu"); sys.init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.