Apps Home
|
Create an App
kellyhuman
Author:
testknf
Description
Source Code
Launch App
Current Users
Created by:
Testknf
var _APPNAME = "Mila's Humans Only App"; var htName = ""; var htAmount = 0; var lnName = "peace in the land"; var lnAmount = 0; var rockstars = []; String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() + this.slice(1); } String.prototype.padL = function (length) { // optional param: paddingChar (default=" ") var pad = arguments.length > 1 ? arguments[1] : ' '; return this.length < length ? (pad + this).padL(length, pad) : this.substr(0, length); } String.prototype.padR = function (length) { // optional param: paddingChar (default=" ") var pad = arguments.length > 1 ? arguments[1] : ' '; return this.length < length ? (this + pad).padR(length, pad) : this.substr(0, length); } String.prototype.padC = function (length) { // optional param: paddingChar (default=" ") var pad = arguments.length > 1 ? arguments[1] : ' '; if (this.length >= length) return this.substr(0, length); if (this.length + 1 == length) return this + pad; else return (pad + this + pad).padC(length, pad); } String.prototype.mapReplace = function (map) { // optional param: replaceFullOnly (default="false) var replaceFullOnly = arguments.length > 1 ? arguments[1] : false; var regexp = []; for (var key in map) { regexp.push(RegExp.escape(key)); } regexp = regexp.join('|'); if (replaceFullOnly) { regexp = '\\b(?:' + regexp + ')\\b'; } regexp = new RegExp(regexp, 'gi'); return this.replace(regexp, function (match) { return map[match.toLowerCase()]; }); } String.isString = function (o) { return (typeof o == 'string' || o instanceof String); } RegExp.escape= function(s) { return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); }; Number.prototype.getOrdinal = function() { switch(this % 100) { case 11: case 12: case 13: return this + "th"; } switch(this % 10) { case 1: return this + "st";; case 2: return this + "nd"; case 3: return this + "rd"; } return this + "th"; } Function.isFunction = function (o) { return !!(o && o.constructor && o.call && o.apply); } var utility = { getPredefinedColor : function (name) { switch (name.toLowerCase()) { case 'black': return '#000'; case 'white': return '#fff'; case 'yellow': return '#fe3'; case 'pink': return '#f0e'; case 'purple': return '#609'; case 'orange': return User.Color.ORANGE.getColor(); case 'red': return User.Color.RED.getColor(); case 'green': return User.Color.GREEN.getColor(); case 'blue': return User.Color.BLUE.getColor(); case 'cyan': return User.Color.CYAN.getColor(); case 'grey': case 'gray': return User.Color.GREY.getColor(); default: return '#000'; } }, securityCheck : function (user, checks, prefix) { if (user.isBroadcaster()) 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.length > 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; } } 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 : [], subject : [], tip : [], setting : {}, panel : [] } 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 ('subject' in rawData.handlers) handlers.subject = rawData.handlers.subject; if ('tip' in rawData.handlers) handlers.tip = rawData.handlers.tip; if ('setting' in rawData.handlers) handlers.setting = rawData.handlers.setting; if ('panel' in rawData.handlers) handlers.panel = rawData.handlers.panel; } 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 = _APPNAME + ' (module "' + name + '"): The command "/' + command + '" is disabled because it is already provided by '; if (consumedBy.name == _APPNAME && 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.handleSubject = function (newS, oldS) { var add = ''; handlers.subject.forEach(function(handler){ add += handler(newS, oldS); }); return add; } this.handlePanel = function (user) { for (handler of handlers.panel) { let panel = handler(user); if (panel) return panel; } } 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 : _APPNAME, 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) { // TODO: check for valid HTML color rawData.c = c; } this.setBackground = function (c) { // TODO: check for valid HTML color rawData.background = c; } this.setFont = function (f) { // TODO: check for valid font rawData.f = f; } this.setMessage = function (m) { rawData.m = m; } this.setHidden = function (h) { rawData['X-Spam'] = !!h; // !! is quick'n'dirty booelan typecast } 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, gender : rawData.from_user_gender, 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 gender = (function (g) { switch (g.toLowerCase()) { case 'm' : return User.Gender.MALE; case 'f' : return User.Gender.FEMALE; case 's' : return User.Gender.SHEMALE; case 'c' : return User.Gender.COUPLE; default: sys.log("Invalid gender code found"); return ''; } })(rawData.gender); 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.getGender = function () { return gender; } 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.is = function (color) { if (!(color instanceof User.Color)) color = User.Color.fromName(color); switch (color) { case User.Color.ORANGE: return this.isBroadcaster(); case User.Color.RED: return this.isMod(); case User.Color.GREEN: return this.isFanclub(); case User.Color.CYAN: return this.hasTokens(); case User.Color.BLUE: return this.isHighTipper(); case User.Color.GREY: return true; default: return false; } } this.isOnly = function (color) { if (!(color instanceof User.Color)) color = User.Color.fromName(color); switch (color) { case User.Color.ORANGE: return this.isBroadcaster(); // no additional checks. Doesn't make any sense to check if a broadcaster // has tokens or is a mod, fanclub member or high tipper. case User.Color.RED: return this.isMod() && !this.isBroadcaster() && !this.isFanclub() && !this.hasToken() && !this.isHighTipper(); case User.Color.GREEN: return this.isFanclub() && !this.isBroadcaster() && !this.isMod() && !this.hasToken() && !this.isHighTipper(); case User.Color.CYAN: return this.hasTokens() && !this.isBroadcaster() && !this.isMod() && !this.isFanclub() && !this.isHighTipper(); case User.Color.BLUE: return this.isHighTipper() && !this.isBroadcaster() && !this.isMod() && !this.isFanclub() && !this.hasTokens(); case User.Color.GREY: return !this.hasTokens() && !this.isHighTipper() && !this.isBroadcaster() && !this.isMod() && !this.isFanclub() default: return false; } } this.getColor = function () { if (this.is(User.Color.ORANGE)) return User.Color.ORANGE; if (this.is(User.Color.RED )) return User.Color.RED; if (this.is(User.Color.GREEN )) return User.Color.GREEN; if (this.is(User.Color.BLUE )) return User.Color.BLUE; if (this.is(User.Color.CYAN )) return User.Color.CYAN; return User.Color.GREY; } 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 } } User.Gender = function (name, code, personal, possessive) { this.getCode = function () { return code; } this.getName = function () { return name; } this.getPersonalPronoun = function () { return personal; } this.getPossessivePronoun = function () { return possessive; } } User.Gender.MALE = new User.Gender('male' , 'm', 'he' , 'his' ); User.Gender.FEMALE = new User.Gender('female' , 'f', 'she' , 'her' ); User.Gender.SHEMALE = new User.Gender('transsexual', 's', '(s)he', 'his/her'); User.Gender.COUPLE = new User.Gender('a couple' , 'c', 'they' , 'their' ); User.Gender.INVALID = new User.Gender('unknown' , '' , 'he' , 'his' ); User.Gender.fromName = function (name) { switch (name.split(/[\s_]/)[0].trim().toLowerCase()) { case 'm' : case 'male' : return User.Gender.MALE; case 'f' : case 'female' : return User.Gender.FEMALE; case 's' : case 'shemale' : case 'trans' : case 'transsexual' : return User.Gender.SHEMALE; case 'a' : case 'c' : case 'couple' : return User.Gender.COUPLE; default : return User.Gender.INVALID; } } User.Color = function (name,code,color) { this.getName = function() {return name }; this.getCode = function() {return code }; this.getColor = function() {return color}; } User.Color.ORANGE = new User.Color('broadcaster' , 'orange', '#DC5500'); User.Color.RED = new User.Color('currentModerator', 'red' , '#DC0000'); User.Color.GREEN = new User.Color('fanclub member' , 'green' , '#090' ); User.Color.BLUE = new User.Color('high tipper' , 'blue' , '#009' ); User.Color.CYAN = new User.Color('token owner' , 'cyan' , '#69A' ); User.Color.GREY = new User.Color('basic user' , 'grey' , '#494949'); User.Color.INVALID = new User.Color('unknown' , '' , '#000' ); User.Color.fromName = function (name) { switch (name.split(/[\s_]/)[0].trim().toLowerCase()) { case 'broadcasters': case 'broadcaster' : case 'oranges' : case 'orange' : return User.Color.ORANGE; case 'currentModerators' : case 'currentModerator' : case 'mods' : case 'mod' : case 'reds' : case 'red' : return User.Color.RED; case 'members' : case 'member' : case 'fanclub' : case 'greens' : case 'green' : return User.Color.GREEN; case 'high' : case 'tippers' : case 'tipper' : case 'darkblues' : case 'darkblue' : case 'bluess' : case 'blues' : case 'blue' : return User.Color.BLUE; case 'tokens' : case 'token' : case 'lightblues' : case 'lightblue' : case 'cyans' : case 'cyan' : return User.Color.CYAN; case 'tokenless' : case 'user' : case 'greys' : case 'grays' : case 'grey' : case 'gray' : case 'all' : return User.Color.GREY; default : return User.Color.INVALID; } } 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 = 999; 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 = ''; 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.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; } //NOTE: messages parsed by parseMessage are not visible in chat or passed to other bots. 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.gender = user.getGender().getCode(); 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.gender = ''; 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 (_APPNAME + ': ' + message); } this.debug = function (message) { if (sys.settings.get('debug_currentMode').getValue()) this.log(message); } this.init = function () { 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) { var tip = new Tip(t); var aT = parseInt(t.amount,0); if (aT > 0) { if (aT > htAmount) { htAmount = aT; htName = t.from_user; } } if (aT >= 1000) { lnAmount = aT; lnName = t.from_user; } if (aT >= 100 && aT <= 199) { if (!cbjs.arrayContains(rockstars, t.from_user)) { if (rockstars.length >= 3) rockstars = rockstars.slice(1); rockstars.push(t.from_user); } } for (var moduleName in modules) { modules[moduleName].handleTip(tip); } cb.drawPanel(); }); 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(function(u){ var user = new User(u); for (var modulName in modules) { let panel = modules[modulName].handlePanel(user); if (panel) return panel; } }); } this.loadModule(new Module('_s', { internalSettings : [ new Setting('security_bg', '#800'), new Setting('security_fg', '#fff'), new Setting.Choice('security_w', ['bold', 'bolder', 'normal']), new Setting('success_bg', '#9e9'), new Setting('success_fg', '#030'), new Setting.Choice('success_w', ['normal', 'bolder', 'bold']), new Setting('warning_bg', '#fc3'), new Setting('warning_fg', '#630'), new Setting.Choice('warning_w', ['normal', 'bolder', 'bold']), new Setting('failure_bg', '#e99'), new Setting('failure_fg', '#300'), new Setting.Choice('failure_w', ['normal', 'bolder', 'bold']) ] })); 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]; } }(); new Module("flexibleGoal", new function () { var sendSuccess = (message, user) => { if (user instanceof User) user = user.getName(); var bg = sys.settings.get ('success_bg').getValue(); var fg = sys.settings.get ('success_fg').getValue(); var w = sys.settings.get ('success_w' ).getValue(); cb.sendNotice(message, user, bg, fg, w); } var sendWarning = (message, user) => { if (user instanceof User) user = user.getName(); var bg = sys.settings.get ('warning_bg').getValue(); var fg = sys.settings.get ('warning_fg').getValue(); var w = sys.settings.get ('warning_w' ).getValue(); cb.sendNotice(message, user, bg, fg, w); } var sendFailure = (message, user) => { if (user instanceof User) user = user.getName(); var bg = sys.settings.get ('failure_bg').getValue(); var fg = sys.settings.get ('failure_fg').getValue(); var w = sys.settings.get ('failure_w' ).getValue(); cb.sendNotice(message, user, bg, fg, w); } var sendNotice = (message, user) => { if (user instanceof User) user = user.getName(); var bg = sys.settings.get ('flexiblegoal_notice_bg').getValue(); var fg = sys.settings.get ('flexiblegoal_notice_fg').getValue(); var w = sys.settings.get ('flexiblegoal_notice_w' ).getValue(); cb.sendNotice(message, user, bg, fg, w); } var onGoalReached = () => { sendNotice("Goal reached! Thank you to all tippers!", ""); resetGoal(); sys.setSubject(); cb.drawPanel(); } var resetGoal = () => { tippers = []; challenges = { tokens : 0, tips : 0, tippers : 0, tipSize : 0 } } var getGoalText = () => { if (!challenges.tips && !challenges.tokens && !challenges.tippers && !challenges.tipSize) { return ""; } let goal = ""; if (challenges.tips) { goal += challenges.tips + " more tips "; if (challenges.tipSize) { goal += "of " + challenges.tipSize + " tokens "; } if (challenges.tokens) { goal += "and a total of " + challenges.tokens + " more tokens "; } if (challenges.tippers) { goal += "by at least " + challenges.tippers + " different tippers "; } } else if (challenges.tokens) { goal += challenges.tokens + " more tokens "; if (challenges.tippers) { goal += "by at least " + challenges.tippers + " different tippers "; } if (challenges.tipSize) { goal += "(only counting tips of " + challenges.tipSize + " tokens) "; } } else if (challenges.tippers) { goal += challenges.tippers + " more people to tip " if (challenges.tipSize) { goal += challenges.tipSize + " tokens "; } } else if (challenges.tipSize) { goal += "A tip of " + challenges.tipSize + " tokens " } goal += "needed to reach the goal." return goal; }; var getGoalTopic = () => { if (!challenges.tips && !challenges.tokens && !challenges.tippers && !challenges.tipSize) { return ""; } let goal = " | Goal: "; if (challenges.tips) { goal += challenges.tips + " tips"; if (challenges.tipSize) { goal += " of " + challenges.tipSize + " tokens"; } if (challenges.tokens) { goal += " & " + challenges.tokens + " more tokens total"; } if (challenges.tippers) { goal += " by " + challenges.tippers + " tippers"; } } else if (challenges.tokens) { goal += challenges.tokens + " more tokens"; if (challenges.tippers) { goal += " by " + challenges.tippers + " tippers"; } if (challenges.tipSize) { goal += " (only counting " + challenges.tipSize + " token tips) "; } } else if (challenges.tippers) { goal += challenges.tippers + " more tippers" if (challenges.tipSize) { goal += " of " + challenges.tipSize + " tokens"; } } else if (challenges.tipSize) { goal += "A tip of " + challenges.tipSize + " tokens" } return goal; } var getGoalPanel = () => { if (!challenges.tips && !challenges.tokens && !challenges.tippers && !challenges.tipSize) { var t = "" for (var i=2; i >=0; i--) { if (rockstars[i] != null) { if (t.length > 0) t += ", "; t += rockstars[i]; } } return { 'template': '3_rows_11_21_31', 'row1_value': 'Today\'s HT: ' + (htName.length == 0 ? "No Tippers Yet": htName + ", " + htAmount.toString()), 'row2_value': 'Last Nuke: ' + (lnAmount == 0 ? lnName : lnName + ", " + lnAmount.toString()), 'row3_value': 'Rockstars: ' + t } } let panel = { template : '3_rows_of_labels', row1_label : 'Needed to reach goal ', row1_value : '(type /goal for info)', row2_label : '', row2_value : '', row3_label : '', row3_value : '' } if (challenges.tips && challenges.tippers && challenges.tokens) { panel.template = '3_rows_12_21_31'; if (challenges.tipSize) { panel.row2_value += "Tips of " + challenges.tipSize + " tokens: "; panel.row2_value += challenges.tips panel.row3_value = "Tokens total: "; panel.row3_value += challenges.tokens; panel.row3_value += " | Tippers: "; panel.row3_value += challenges.tippers; } else { panel.row2_value += "Tokens: "; panel.row2_value += challenges.tokens; panel.row2_value += " | Tips: "; panel.row2_value += challenges.tips panel.row2_value += " | Tippers: "; panel.row2_value += challenges.tippers; } } else if (challenges.tips) { panel.row2_label += "Tips" if (challenges.tipSize) { panel.row2_label += " of " + challenges.tipSize + " tokens"; } panel.row2_label += ":"; panel.row2_value = challenges.tips if (challenges.tokens) { panel.row3_label = "Tokens total:" panel.row3_value = challenges.tokens; } if (challenges.tippers) { panel.row3_label = "Tippers:" panel.row3_value = challenges.tippers; } } else if (challenges.tokens) { panel.row2_label = "Tokens" if (challenges.tipSize) { panel.row2_label += " (in tips of " + challenges.tipSize + ")"; } panel.row2_label += ":" panel.row2_value = challenges.tokens; if (challenges.tippers) { panel.row3_label = "Tippers" if (challenges.tipSize) { panel.row3_label += " of " + challenges.tipSize; } panel.row3_label += ":"; panel.row3_value += challenges.tippers; } } else if (challenges.tippers) { panel.row2_label = "Tippers"; if (challenges.tipSize) { panel.row2_label += " of " + challenges.tipSize + " tokens"; } panel.row2_label += ":"; panel.row2_value += challenges.tippers; } else if (challenges.tipSize) { panel.template = '3_rows_12_21_31'; panel.row2_value = "A single tip of " + challenges.tipSize; } return panel; } var challenges = { tippers : 0, tips : 0, tokens : 0, tipSize : 0 } var tippers = {}; this.internalSettings = [ ]; this.externalSettings = [ new Setting.Bool ('security_flexiblegoal_mod', '[Permissions]: Moderators can change goals', false , true), new Setting.String('flexiblegoal_notice_fg' , '[Flexible Goal]: Color of chat messages' , '#820' , true), new Setting.String('flexiblegoal_notice_bg' , '[Flexible Goal]: Background color of chat messages', '#fdd' , true), new Setting.Choice('flexiblegoal_notice_w' , ['normal', 'bolder', 'bold'], '[Flexible Goal]: Text weight of chat messages' , 'bold', true) ]; this.handlers = { tip : [ t => { if (challenges.tipSize && !challenges.tips && !challenges.tippers && !challenges.tokens) { if (challenges.tipSize == t.getAmount()) { onGoalReached(); } return; } if (!(challenges.tokens || challenges.tippers || challenges.tips || challenges.tipSize)) return; if (challenges.tokens) { if (!challenges.tipSize || challenges.tips || challenges.tipSize == t.getAmount()) { challenges.tokens -= t.getAmount(); if (challenges.tokens < 0) challenges.tokens = 0; } } if (challenges.tips) { if (!challenges.tipSize || challenges.tipSize == t.getAmount()) { challenges.tips -= 1; if (challenges.tips < 0) challenges.tips = 0; } } if (challenges.tippers) { if (!challenges.tipSize || (challenges.tips && challenges.tokens) || challenges.tipSize == t.getAmount()) { let tipper = t.getUser().getName(); if (!(tipper in tippers && tippers[tipper])) { challenges.tippers -=1; if (challenges.tippers < 0) challenges.tippers = 0; tippers[tipper] = true; } } } if (!challenges.tips && !challenges.tippers && !challenges.tokens) { onGoalReached(); } else { sys.setSubject(); cb.drawPanel(); } } ], subject : [ getGoalTopic ], panel : [ u => { if (cb.limitCam_isRunning() && !cb.limitCam_userHasAccess(u.getName()) && !u.isBroadcaster()) return; return getGoalPanel(); } ] } this.commands = { goal : function (p,c,m) { if (p.length == 0) { sendNotice(getGoalText(), m.getUser()); return true; } if (!utility.securityCheck(m.getUser(), ['mod'], 'security_flexiblegoal_')) { return false; } let newChallenges = { tokens : 0, tipSize : 0, tippers : 0, tips : 0 }; while (p.length > 0) { let param = p.shift(); let match = []; if (match = param.match(/^(off|none)$/i)) { sendSuccess("Goal was successfully removed.", m.getUser()); sendNotice ("The goal was removed." , "" ); resetGoal(); sys.setSubject(); cb.drawPanel(); return true; } if (match = param.match(/^(\d+)(?:total)?$/i)) { if (match && match[1]) { newChallenges.tokens = match[1]; } continue; } if (match = param.match(/^(\d+)(?:tokens?|tkns|tk)$/i)) { if (match && match[1]) { newChallenges.tipSize = match[1]; } continue; } if (match = param.match(/^(\d+)(?:tippers?|users?)$/i)) { if (match && match[1]) { newChallenges.tippers = match[1]; } continue; } if (match = param.match(/^(\d+)(?:tips?|times?|x)$/i)) { if (match && match[1]) { newChallenges.tips = match[1]; } continue; } sendFailure("Could not parse parameter \"" + param + "\"", m.getUser()); } if (!(newChallenges.tokens || newChallenges.tipSize || newChallenges.tips || newChallenges.tippers)) { sendFailure("No new goal was set as there were no valid parameters specified.",m .getUser()); return true; } challenges = newChallenges; tippers = []; sendSuccess("Goal successfully set." , m.getUser()); sendNotice ("A new goal was set! " + getGoalText(), "" ); sys.setSubject(); cb.drawPanel(); return true; } }; }()); new Module("noView",new function () { var sendSuccess = (message, user) => { if (user instanceof User) user = user.getName(); var bg = sys.settings.get ('success_bg').getValue(); var fg = sys.settings.get ('success_fg').getValue(); var w = sys.settings.get ('success_w' ).getValue(); cb.sendNotice(message, user, bg, fg, w); } var sendWarning = (message, user) => { if (user instanceof User) user = user.getName(); var bg = sys.settings.get ('warning_bg').getValue(); var fg = sys.settings.get ('warning_fg').getValue(); var w = sys.settings.get ('warning_w' ).getValue(); cb.sendNotice(message, user, bg, fg, w); } var sendFailure = (message, user) => { if (user instanceof User) user = user.getName(); var bg = sys.settings.get ('failure_bg').getValue(); var fg = sys.settings.get ('failure_fg').getValue(); var w = sys.settings.get ('failure_w' ).getValue(); cb.sendNotice(message, user, bg, fg, w); } var sendNotice = (message, user) => { if (user instanceof User) user = user.getName(); var bg = sys.settings.get ('flexiblegoal_notice_bg').getValue(); var fg = sys.settings.get ('flexiblegoal_notice_fg').getValue(); var w = sys.settings.get ('flexiblegoal_notice_w' ).getValue(); cb.sendNotice(message, user, bg, fg, w); } var CamMode = function (screenMessage, chatMessage, checkFunc) { if (!screenMessage) screenMessage = "You are not allowed to watch this cam."; if (!chatMessage ) chatMessage = "Nobody may watch this cam anymore."; if (!checkFunc ) checkFunc = () => false; var internalList = []; this.add = u => { if (checkFunc(u)) { let name = u.getName().toLowerCase(); let pos = internalList.indexOf(name); if (pos < 0) internalList.push(name); return true; } return false; } this.remove = u => { if (checkFunc(u)) { let name = u.getName().toLowerCase(); let pos = internalList.indexOf(name); if (pos >= 0) internalList.splice(pos,1); } } this.contains = u => { if (checkFunc(u)) { let name = u.getName().toLowerCase(); let pos = internalList.indexOf(name); if (pos >= 0) return true; else return false; } } this.getList = () => internalList.slice(); this.getScreenMessage = () => screenMessage; this.getChatMessage = () => chatMessage; } var modes = { anon : new CamMode("Scroll down to my bio and click on the link to create an account and watch my show, it's free!", "Only registered users may watch the cam.", u => true ), grey : new CamMode("Screw the bots! Only humans allowed! Get some tokens to watch the show!", "Only users who have tokens (or tipped) may watch the cam.", u => u.hasTokens() || u.isTipper()), notip : new CamMode("Screw the bots! Only humans allowed! Tip 1 token to prove you are human and watch the show", "Only users who tipped may watch the cam.", u => u.isTipper() ) } var currentMode = "off"; var processUser = u => { for (mode in modes) if (modes[mode] instanceof CamMode){ if(modes[mode].add(u) && currentMode == mode) { cb.limitCam_addUsers([u.getName()]); } } } // cleanup to keep mode lists small var unprocessUser = u => { for (mode in modes) if (modes[mode] instanceof CamMode){ modes[mode].remove(u); } } var addUser = u => { if (cb.limitCam_isRunning()) { cb.limitCam_addUsers([u.getName()]); } } var changeMode = newMode => { if (currentMode == newMode) return true; if (!(newMode in modes && modes[newMode] instanceof CamMode) && newMode != "off") { sys.log("Unknown mode for \"noView\" module: " + newMode + ". Ignoring."); return false; }; cb.limitCam_stop(); if (newMode != "off") { cb.limitCam_removeAllUsers(); cb.limitCam_addUsers(modes[newMode].getList() ); cb.limitCam_start (modes[newMode].getScreenMessage()); sendNotice("The view mode was changed. " + modes[newMode].getChatMessage() + "\nIf you are one but cannot see the cam, type anything in chat or reload the page.", ""); } currentMode = newMode; cb.drawPanel(); return true; } this.externalSettings = [ new Setting.Bool ('security_noview_mod', '[Permissions]: Moderators can change the view mode' , true , true), new Setting.String('noview_notice_fg' , '[Selective Viewers]: Color of chat messages' , '#008' , true), new Setting.String('noview_notice_bg' , '[Selective Viewers]: Background color of chat messages' , '#eef' , true), new Setting.Choice('noview_notice_w' , ['normal', 'bolder', 'bold'], '[Selective Viewers]: Text weight of chat messages' , 'normal', true) ]; this.commands = { noview : (p,c,m) => { if (p.length == 0) { if (currentMode == "off") { sendNotice("Everyone can currently watch this cam", m.getUser()); } else if (!(currentMode in modes && modes[currentMode] instanceof CamMode)) { sendNotice("The current view mode is not known to the app.", m.getUser()); } else { sendNotice(modes[currentMode].getChatMessage(), m.getUser()); } return true; } if (!utility.securityCheck(m.getUser(), ['mod'], 'security_noview_')) { return false; } let newMode = p.join(" "); if (changeMode(newMode)) { sendSuccess("View mode successfully changed.", m.getUser()); } else { sendFailure("The view mode could not be changed to \"" + newMode + "\". Please check if you spelled the" + " command correctly.", m.getUser()); } return true; } }; this.handlers = { enter : [processUser], leave : [unprocessUser], tip : [t => processUser(t.getUser())], message : [m => processUser(m.getUser())], panel : [ u => { if (!cb.limitCam_isRunning() || cb.limitCam_userHasAccess(u.getName()) || u.isBroadcaster()) return; return { template : '3_rows_11_21_31', row2_value : (currentMode in modes && modes[currentMode] instanceof CamMode) ? modes[currentMode].getScreenMessage() : "You are not allowed to watch this cam.", row3_value : '', row1_value : '' } } ] }; }()); new Module("flairs", new function () { var myUsers = []; var myUser = function(u, e){ this.UserName = u; this.Emoji = e; } myUser.prototype.Get = function() { return this.Emoji; } myUser.prototype.Name = function() { return this.UserName; } myUser.prototype.Display = function() { return "U:[" + this.UserName + "] E:[" + this.Emoji +"]";} var sendSuccess = (message, user) => { if (user instanceof User) user = user.getName(); var bg = sys.settings.get ('success_bg').getValue(); var fg = sys.settings.get ('success_fg').getValue(); var w = sys.settings.get ('success_w' ).getValue(); cb.sendNotice(message, user, bg, fg, w); } var sendWarning = (message, user) => { if (user instanceof User) user = user.getName(); var bg = sys.settings.get ('warning_bg').getValue(); var fg = sys.settings.get ('warning_fg').getValue(); var w = sys.settings.get ('warning_w' ).getValue(); cb.sendNotice(message, user, bg, fg, w); } var sendFailure = (message, user) => { if (user instanceof User) user = user.getName(); var bg = sys.settings.get ('failure_bg').getValue(); var fg = sys.settings.get ('failure_fg').getValue(); var w = sys.settings.get ('failure_w' ).getValue(); cb.sendNotice(message, user, bg, fg, w); } var sendNotice = (message, user) => { if (user instanceof User) user = user.getName(); var bg = sys.settings.get ('flexiblegoal_notice_bg').getValue(); var fg = sys.settings.get ('flexiblegoal_notice_fg').getValue(); var w = sys.settings.get ('flexiblegoal_notice_w' ).getValue(); cb.sendNotice(message, user, bg, fg, w); } var processMessage = m => { var flairs = ""; for(var i=0; i < myUsers.length; i++) { if (myUsers[i].Name() == m.getUser().getName()) { flairs += myUsers[i].Get() + " "; } } m.setMessage(flairs + m.original); return m; } this.externalSettings = [ new Setting.String('flair_emojis' , '[Flair]: Emoji List: (use | between each flair)' , 'banana|smirus|fapwad|rockstar|nuke|cheer|magic|ht|crown' , true) ]; this.commands = { flair : function (p,c,m) { if (m.getUser().getName() != cb.room_slug) { var usr = m.getUser().getName(); sendFailure("You do not have access to this command", usr); sendFailure("User[" + usr + "] tried to issue Flair command.", cb.room_slug); return true; } if (p.length == 0) { return true; } var emojiList = sys.settings.get ('flair_emojis' ).getValue(); var re = new RegExp(emojiList, 'i'); while (p.length > 0) { let param = p.shift(); let match = []; if (match = param.match(/^(clear)$/i)) { myUsers = []; sendSuccess("Cleared all Flairs", m.getUser()); return true; } if (match = param.match(/^(list)$/i)) { let s =""; for(var i=0; i < myUsers.length; i++) { if (s.length > 0) s += "|"; s += myUsers[i].Display(); } cb.sendNotice(s, cb.room_slug); return true; } if ((match = param.match(/^(add)$/i)) && p.length == 2) { param = p.shift(); if (match = param.match(re)) { let usr = p.shift(); let emoji = ""; if (param === 'banana') emoji = "\u{1F34C}"; else if (param === 'smirus') emoji = "\u{1F47E}"; else if (param === 'fapwad') emoji = "\u{1F910}"; else if (param === 'rockstar') emoji = "\u{1F3B8}"; else if (param === 'nuke') emoji = "\u{1F4A5}"; else if (param === 'cheer') emoji = "\u{1F389}"; else if (param === 'magic') emoji = "\u{1F525}"; else if (param === 'ht') emoji = "\u{1F3A9}"; else if (param === 'crown') emoji = "\u{1F451}"; if (emoji.length > 0) myUsers.push(new myUser(usr, emoji)); return true; } } if ((match = param.match(/^(remove)$/i)) && p.length == 2) { param = p.shift(); if (match = param.match(re)) { let usr = p.shift(); for(var i=0; i < myUsers.length; i++) { if (myUsers[i].Name() == usr) { var tt = myUsers.splice(i,1); break; } } return true; } } sendFailure("Could not parse parameter \"" + param + "\"", cb.room_slug); } return true; } }; this.handlers = { message : [m => processMessage(m)] }; }()); 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; } }, init : () => sys.setSubject(sys.settings.get('subject').getValue()) })); sys.loadModule("flexibleGoal"); sys.loadModule("noView"); sys.loadModule("flairs"); sys.init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.