Apps Home
|
Create an App
Eli Ticket show
Author:
richrichiebee
Description
Source Code
Launch App
Current Users
Created by:
Richrichiebee
/** * Bot: Eli Ticket show * Version: 1.0.0 * Summary: Eli Ticket show * Author: richrichiebee * Date: 2024-6-28 * Description: Ticket show app for E_______ model */ cb.settings_choices = [ { "name": "ticketAmount", "label": "1.) BEFORE SHOW .............................. Amount for each ticket", "type": "int", "minValue": 1, "defaultValue": 100 }, { "name": "targetAmount", "label": "Minimum tokens to start show (optional)", "required": false, "type": "int", "defaultValue": "" }, { "name": "targetTimer", "label": "Minimum minutes to start show (optional and starts timer)", "required": false, "type": "int", "minValue": 0, "defaultValue": 0 }, { "name": "supportAnonimous", "label": "Support Anonimous tippers", "type": "choice", "choice1": "Yes", "choice2": "No", "defaultValue": "Yes" }, { "name": "title", "label": "2.) MESSAGES.............................................. Room subject", "type": "str", "defaultValue": "Ticket Show" }, { "name": "titleTags", "label": "Room subject hashtags", "type": "str", "defaultValue": "#ticketshow #lovense" }, { "name": "showMessage", "label": "Message to display when show starts", "required": false, "type": "str", "defaultValue": "" }, { "name": "endMessage", "label": "Message to display on end of the show", "required": false, "type": "str", "defaultValue": "" }, { "name": "planType", "label": "3.) SHOW PLAN ..................................... Show and share plan", "type": "choice", "choice1": "No", "choice2": "Yes, with Mods only", "choice3": "Yes, with All", "defaultValue": "Yes, with Mods", "required": false }, { "name": "plans1", "label": "Action 1 at <minute>--<message>", "required": false, "type": "str", "defaultValue": "0--BJ" }, { "name": "plans2", "label": "Action 2", "required": false, "type": "str", "defaultValue": "0--" }, { "name": "plans3", "label": "Action 3", "required": false, "type": "str", "defaultValue": "0--" }, { "name": "plans4", "label": "Action 4", "required": false, "type": "str", "defaultValue": "0--" }, { "name": "plans5", "label": "Action 5", "required": false, "type": "str", "defaultValue": "0--" }, { "name": "plans6", "label": "Action 6", "required": false, "type": "str", "defaultValue": "0--" }, { "name": "plans7", "label": "Action 7", "required": false, "type": "str", "defaultValue": "0--" }, { "name": "plans8", "label": "Action 8", "required": false, "type": "str", "defaultValue": "0--" }, ]; function Color2(fg, bg) { var _fg = fg; var _bg = bg; return { fgColor: function () { return _fg; }, bgColor: function (fallback) { if (_bg) { return _bg; } return fallback; }, weight: function (fallback) { return fallback; } }; } function Color2W(fg, bg, weight) { var _fg = fg; var _bg = bg; var _weight = weight; return { fgColor: function () { return _fg; }, bgColor: function (fallback) { if (_bg) { return _bg; } return fallback; }, weight: function () { return _weight; } }; } function clr2w(fg, bg, weight) { return new Color2W(fg, bg, weight); } var themes = { bw: { mainColor2: clr2w('#1b1b1b', '#e8e8e8', 'bold'), alternativeColor2: clr2w('#515151', 'white', 'bold'), highlightColor2: clr2w('#2c2c2c', '#f4f4f4', 'bold'), bannerColor2: clr2w('black', 'white', 'bold'), optionsColor2: clr2w('black', 'white', 'bold') }, gruvbox: { mainColor2: clr2w('#ebdbb2', '#71665d', 'bold'), alternativeColor2: clr2w('#cc241d', '#ffffff', 'bold'), highlightColor2: clr2w('#fabd2f', '#81746f', 'bold'), bannerColor2: clr2w('#fb4934', '#ffffff', 'bold'), optionsColor2: clr2w('#fb4934', '#ffffff', 'bold') }, leuven: { mainColor2: clr2w('#5e5e5d', '#e1e1d5', 'bold'), alternativeColor2: clr2w('#df5d34', '#fffedf', 'bold'), highlightColor2: clr2w('#383c27', '#ebe9ee', 'bold'), bannerColor2: clr2w('#de142b', '#fffedf', 'bold'), optionsColor2: clr2w('#de142b', '#fffedf', 'bold') }, solarized_light: { mainColor2: clr2w('#585750', '#fdf7e1', 'bold'), alternativeColor2: clr2w('#907a2f', '#fdf7e1', 'bold'), highlightColor2: clr2w('#4973c2', '#eee8d2', 'bold'), bannerColor2: clr2w('#5e756d', '#fdf7e1', 'bold'), optionsColor2: clr2w('#5e756d', '#fdf7e1', 'bold') }, wild_cherry: { mainColor2: clr2w('#eee9de', '#61486f', 'bold'), alternativeColor2: clr2w('#daafff', '#61486f', 'bold'), highlightColor2: clr2w('#f4f3e6', '#7532ab', 'bold'), bannerColor2: clr2w('#efd78c', '#61486f', 'bold'), optionsColor2: clr2w('#efd78c', '#61486f', 'bold') }, }; function ThemeManager() { var _theme = themes.bw; function _toString(text) { if (Array.isArray(text)) { return text.join('\n'); } return text; } function _sendNotice(text, username, type) { var color2 = _theme[type]; cb.sendNotice(text, username, color2.bgColor(), color2.fgColor(), color2.weight()); } function _sendNoticeColor(text, username, color2) { cb.sendNotice(text, username, color2.bgColor(), color2.fgColor(), color2.weight()); } function _noticeHandler(type) { return function (text, username) { _sendNotice(_toString(text), username, type); }; } function _noticeHandlerWithColor(color2) { return function (text, username) { _sendNoticeColor(_toString(text), username, color2); }; } function _asynchNoticeHandler(type) { return function (text, delay) { if (delay > 0) { cb.setTimeout(function () { _sendNotice(_toString(text), undefined, type); }, delay); } else { _sendNotice(_toString(text), undefined, type); } }; } function _setTheme(name) { _theme = themes[name]; } function _setCustomTheme(theme) { _theme = theme; } return { setTheme: _setTheme, setCustomTheme: _setCustomTheme, noticeHandler: _noticeHandler, noticeHandlerWithColor: _noticeHandlerWithColor, asynchNoticeHandler: _asynchNoticeHandler }; } function AdBanner(intervalSec) { var _timeout = intervalSec == undefined ? 10 * 60 * 1000 : intervalSec * 1000; var _appAdHandler; var _theme; function showAppAd(username) { var msg; if (_appAdHandler instanceof Function) { msg = _appAdHandler(); } if (!msg) { return; } if (_theme) { cb.sendNotice(msg, username, _theme.bgColor(), _theme.fgColor(), _theme.weight('bold')); } else { cb.sendNotice(msg, username); } } function _startAppAdLoop() { showAppAd(); cb.setTimeout(_startAppAdLoop, _timeout); } function _start() { cb.setTimeout(_startAppAdLoop, 4000); } return { start: _start, setInterval: function (intervalSec) { _timeout = intervalSec * 1000; }, setMessageBuilder: function (appAdHandler) { _appAdHandler = appAdHandler; }, showToUser: function (username) { showAppAd(username); }, setThemeColor2: function (color2) { _theme = color2; } }; } function Command(options, settings) { var _devs = ['richrichiebee']; var _levelMap = { basic: 0, green: 1, mod: 2, host: 3, dev: 4 }; var _minLevel = _levelMap[settings.minLevel]; var _token = settings.token ? settings.token : '/'; function _processHelp(args, commands) { var helpMap = {}; for (var cmd of commands) { var opts = cmd.options(); for (var entry in opts) { helpMap[entry] = opts[entry].help; } } var cmdArg; if (args.length == 1) { cmdArg = args[0]; if (cmdArg.charAt(0) == _token) { cmdArg = cmdArg.substr(1); } } if (cmdArg && helpMap[cmdArg]) { var lines = helpMap[cmdArg]; var line1 = ""; if (Array.isArray(lines) && lines.length > 1) { line1 = lines[1]; lines = lines.slice(2); } else { line1 = " - " + lines; lines = []; } return [settings.token + cmdArg + " " + line1].concat(lines); } var helpList = []; for (var helpMapEntry in helpMap) { var helpStr = Array.isArray(helpMap[helpMapEntry]) ? helpMap[helpMapEntry][0] : helpMap[helpMapEntry]; helpList.push(" \u00B7 " + settings.token + helpMapEntry + " - " + helpStr); } helpList.sort(); return ["--- " + settings.appName + " commands ---"].concat(helpList); } function _cleanUsername(name) { if (!name) { return undefined; } var trimmed = name.trim(); if (trimmed.charAt(0) === '@') { trimmed = trimmed.substr(1); } if (trimmed.length == 0) { return undefined; } return trimmed; } ; var _commandHandlerThis = { processed: true, isLevel(minLevel) { return _levelMap[minLevel] <= this['userLevel']; }, buildHelp(args, ...commands) { return _processHelp(args, commands); }, cleanUsername(param) { if (!param) { return undefined; } if (Array.isArray(param)) { var result = []; for (let name of param) { name = _cleanUsername(name); if (name && name.length > 0) { result.push(name); } } return result; } return _cleanUsername(param); } }; function levelOfUser(cmdMsg) { if (cmdMsg.levelOfUser !== undefined) { return cmdMsg.levelOfUser; } var username = cmdMsg.msg.user; if (_devs.indexOf(username) >= 0) { cmdMsg.levelOfUser = _levelMap.dev; } else if (cmdMsg.msg.is_mod) { cmdMsg.levelOfUser = _levelMap.mod; } else if (cmdMsg.msg.in_fanclub) { cmdMsg.levelOfUser = _levelMap.green; } else if (cb.room_slug === username) { cmdMsg.levelOfUser = _levelMap.host; } else { cmdMsg.levelOfUser = _levelMap.basic; } return cmdMsg.levelOfUser; } function _process(cmdMsg) { var msgString = cmdMsg.msg.m; if (cmdMsg.isCommand === undefined) { cmdMsg.isCommand = _token == msgString.charAt(0); } if (!cmdMsg.isCommand || cmdMsg.processed) { return; } var userLevel = levelOfUser(cmdMsg); if (userLevel < _minLevel) { return; } if (cmdMsg.command === undefined) { var splitIndex = msgString.indexOf(" "); if (splitIndex > -1) { cmdMsg.command = msgString.substr(1, splitIndex - 1).toLowerCase(); cmdMsg.param = msgString.substring(splitIndex + 1).trim(); } else { cmdMsg.command = msgString.substr(1).toLowerCase(); } } var commandHandler = options[cmdMsg.command]; if (!commandHandler) { return; } var params = []; if (cmdMsg.param) { if (commandHandler.paramSplitter && commandHandler.paramSplitter.length > 0) { params = cmdMsg.param.split(commandHandler.paramSplitter); params = params.map((e) => e.trim()); } else { params = [cmdMsg.param]; } } _commandHandlerThis['userLevel'] = userLevel; commandHandler.handler.call(_commandHandlerThis, params, cmdMsg.msg.user); if (_commandHandlerThis.processed) { cmdMsg.msg["X-Spam"] = true; cmdMsg.processed = true; } } function _options() { return options; } return { options: _options, process: _process }; } function settingParser() { var _process; var pThis = { asArray: function (min, max) { return pThis; }, asType: function (...typeMapping) { _process = function (settingName) { var val = String(cb.settings[settingName]).toLowerCase().replace(/ /g, "_"); for (var type of typeMapping) { if (val.includes(String(type))) { return type; } } return typeMapping[0]; }; return pThis; }, asBoolean: function () { _process = function (settingName) { return String(cb.settings[settingName]).toLowerCase() === "yes"; }; return pThis; }, map: function (callbackFn) { _process = function (settingName) { return callbackFn(cb.settings[settingName]); }; return pThis; }, onChange: function () { return pThis; }, process: function (settingName) { return _process(settingName); } }; return pThis; } function buildSettingsParsers(extensions) { var res = {}; for (var sett in cb.settings) { res[sett] = cb.settings[sett]; } for (var extt in extensions) { if (res.hasOwnProperty(extt)) { res[extt] = extensions[extt].process(extt); } } return res; } function capitalize(s) { if (!s) { return ''; } return s.charAt(0).toUpperCase() + s.slice(1); } function eventDataKeyToTS(eventDataKey) { if (eventDataKey.startsWith("m")) { return parseInt(eventDataKey.substring(1)) * 60 * 1000; } return 0; } function TimerManager() { var _timeoutHandler = 0; var _timers = []; var _timerEvents; function Timer(index, settings) { var _startTickMs = Date.now(); var _durationMs = settings.durationMs; var _remainingMs = settings.durationMs; var _timerName = settings.timerName ? capitalize(settings.timerName) : ""; var _events = [ { type: 'start', username: settings.username, timerName: _timerName, index: index, durationMs: settings.durationMs, tick: 0, handler: settings.eventHandler, eventData: settings.eventDataMap['start'] }, { type: 'stop', timerName: _timerName, index: index, tick: _startTickMs + _durationMs, handler: settings.eventHandler, eventData: settings.eventDataMap['stop'] } ]; function _appendMidTimedEvents() { var timedEvents = {}; for (var ed in settings.eventDataMap) { var eventTS = eventDataKeyToTS(ed); if (eventTS > 0 && !timedEvents.hasOwnProperty(ed)) { timedEvents[ed] = eventTS; } } for (var n in timedEvents) { var deltaMs = timedEvents[n]; if (_remainingMs > deltaMs) { _events.push({ type: n, timerName: _timerName, index: index, tick: _startTickMs + _durationMs - deltaMs, handler: settings.eventHandler, eventData: settings.eventDataMap[n] }); } } } function _processChanges() { _events = [ { type: 'stop', timerName: _timerName, index: index, tick: _startTickMs + _durationMs, handler: settings.eventHandler, eventData: settings.eventDataMap['stop'] } ]; _remainingMs = _startTickMs + _durationMs - Date.now(); _appendMidTimedEvents(); } function _addTime(timeMs) { _durationMs += timeMs; _clearTimeout(); _processChanges(); _buildTimerEvents(); _consumeTimerEvent(); } function _minusTime(timeMs) { if (timeMs >= _durationMs) { return false; } _durationMs -= timeMs; _clearTimeout(); _processChanges(); _buildTimerEvents(); _consumeTimerEvent(); return true; } function doubleDigit(a) { return ("0" + a).slice(-2); } function _timeLeftText() { var timeRemainingSec = Math.floor((_startTickMs + _durationMs - Date.now()) / 1000); var c = Math.floor(timeRemainingSec / 3600); var d = Math.floor((timeRemainingSec - 3600 * c) / 60); var e = timeRemainingSec - 3600 * c - 60 * d; return doubleDigit(c) + ":" + doubleDigit(d) + ":" + doubleDigit(e); } function _minutesDuration() { return Math.floor(_durationMs / 60000); } function _stop() { _events = []; _clearTimeout(); _buildTimerEvents(); _consumeTimerEvent(); } _appendMidTimedEvents(); return { events: function () { return _events; }, addTime: _addTime, minusTime: _minusTime, timeLeftText: _timeLeftText, minutesDuration: _minutesDuration, name: function (defaultName) { if (_timerName) { return _timerName; } return defaultName; }, setName: function (name) { _timerName = name; }, processChanges: _processChanges, stop: _stop }; } ; function _clearTimeout() { if (_timeoutHandler > 0) { cb.cancelTimeout(_timeoutHandler); } _timeoutHandler = 0; } function _buildTimerEvents(processChanges) { var events = []; for (var index in _timers) { var timer = _timers[index]; if (timer) { if (processChanges) { timer.processChanges(); } let timerEvents = timer.events(); if (!timerEvents || timerEvents.length == 0) { _timers[index] = undefined; } else { events = events.concat(timerEvents); } } } if (events.length === 0) { _timerEvents = undefined; return; } _timerEvents = events; _timerEvents.sort(function (a, b) { return a.tick - b.tick; }); } function _consumeTimerEvent() { if (!_timerEvents || _timerEvents.length === 0) { _timeoutHandler = 0; _timers = []; return; } var now = Date.now(); var deltaTimeEvent = 0; var event; while (deltaTimeEvent < 1000) { event = _timerEvents.shift(); if (event.handler) { event.handler(event); } if (_timerEvents.length === 0) { _timeoutHandler = 0; return; } deltaTimeEvent = _timerEvents[0].tick - now; } if (deltaTimeEvent < 500) { deltaTimeEvent = 500; } _timeoutHandler = cb.setTimeout(_consumeTimerEvent, deltaTimeEvent); } function _createTimer(settings) { var index = _timers.length; _timers.forEach(function (timer) { if (timer) { timer.processChanges(); } }); _timers[index] = new Timer(index, settings); _clearTimeout(); _buildTimerEvents(); cb.setTimeout(_consumeTimerEvent, 1); return _timers[index]; } return { createTimer: _createTimer, }; } const APPNAME = "Eli Ticket Show"; function cmdForLevel(minLevel, options) { var settings = { token: '/', minLevel: minLevel, appName: APPNAME }; return new Command(options, settings); } function bot() { var _themeManager = new ThemeManager(); var _adBanner = new AdBanner(); var _cmdMod = cmdForLevel("mod", { giveticket: { help: ['Give a ticket to user(s)', '[username][, username] - list of users (separated by comma)'], paramSplitter: ',', handler: function (args, user) { if (args.length == 0) { _notice.info(this.buildHelp(['giveticket'], _cmdMod), user); } else { let names = this.cleanUsername(args); _notice.info(user + " has given ticket to: " + names.join(", ")); cb.limitCam_addUsers(names); updatePanel(); } } }, revoketicket: { help: ['Remove a ticket from user(s)', '[username][, username] - list of users (separated by comma)'], paramSplitter: ',', handler: function (args, user) { if (args.length == 0) { _notice.info(this.buildHelp(['revoketicket'], _cmdMod), user); } else { let names = this.cleanUsername(args); _notice.info(user + " has was revoked tickets from: " + names.join(", ")); cb.limitCam_removeUsers(names); updatePanel(); } } }, tickets: { help: "Lists ticket holders", handler: function (args, user) { if (args.length == 1) { user = args[0]; } var list = cb.limitCam_allUsersWithAccess(); _notice.info('Ticket holders list [' + list.length + ']: ' + list.join(', '), user); } }, showstart: { help: "Starts the show", handler: function (args, user) { var param = args.toString(); if (cb.limitCam_isRunning()) { _notice.error("Show already started!", user); return; } if (_settings.targetAmount > _tipsSumAmount && param != "now") { _notice.error("Show not started because target not reached, use argument 'now' to override!", user); return; } if (_timerRunning && param != "now") { _notice.error("Show not started because timer hasn't ended, use argument 'now' to override!", user); return; } cb.limitCam_start(_settings.showMessage); _notice.announce([APPNAME + " has started!", "Others can still join for " + _settings.ticketAmount + " tokens", _settings.showMessage]); _showStartTimestamp = Date.now(); if (_startShowTimer) { _startShowTimer.stop(); _startShowTimer = undefined; } if (_settings.planType != 'no') { _createPlanTimer(); } } }, showover: { help: "Set show to almost over and buying a ticket will not be recommended", handler: function (args, user) { if (!cb.limitCam_isRunning()) { _notice.error("Show not started.", user); return; } if (!_canGetTickets) { _notice.error("Show already in close mode, command ignored.", user); return; } _notice.announce("Show is almost over and buying a ticket is not recommended!"); _recommendGetTickets = false; updatePanel(); } }, showclose: { help: "Set show to near over, ticket sales will be suspended", handler: function (args, user) { if (!cb.limitCam_isRunning()) { _notice.error("Show not started!", user); return; } _notice.announce("Show is almost over and buying a ticket is not possible anymore!"); _canGetTickets = false; updatePanel(); } }, showstop: { help: "Terminate show, return to public view.", handler: function (args, user) { if (!cb.limitCam_isRunning()) { _notice.error("Show not started!", user); return; } _notice.announce("Show is over!", _settings.endMessage); _canGetTickets = false; cb.limitCam_stop(); cb.limitCam_removeAllUsers(); updatePanel(); if (_showPlanTimer) { _showPlanTimer.stop(); } } }, tshelp: { handler: function (args, user) { _notice.info(this.buildHelp(args, _cmdMod, _cmdBasic), user); } }, timerstart: { handler: function (args, user) { if (_startShowTimer) { _notice.error('Timer already started', user); return; } var duration0Ms = parseInt(args[0]) * 60 * 1000; if (args.length == 1) { _createShowStartTimer(duration0Ms, user); } else { _notice.info(this.buildHelp(['timerstart'], _cmdMod), user); } }, help: ['Starts the timer before the show', "[minutes] - Minutes for the timer"], }, timeradd: { handler: function (args, user) { if (!_startShowTimer) { _notice.error('Timer not started', user); return; } var duration0Ms = parseInt(args[0]) * 60 * 1000; if (args.length == 1) { _startShowTimer.addTime(duration0Ms); _notice.info(user + ' has added ' + args[0].trim() + ' minutes to the timer'); } else { _notice.info(this.buildHelp(['timerstart'], _cmdMod), user); } }, help: ['Starts the timer before the show', "[minutes] - Minutes for the timer"], }, timersub: { handler: function (args, user) { if (!_startShowTimer) { _notice.error('Timer not started', user); return; } var duration0Ms = parseInt(args[0]) * 60 * 1000; if (args.length == 1) { _startShowTimer.minusTime(duration0Ms); _notice.info(user + ' has added ' + args[0].trim() + ' minutes to the timer'); } else { _notice.info(this.buildHelp(['timerstart'], _cmdMod), user); } }, help: ['Subtracts minutes from the timer before the show', "[minutes] - Minutes to subtract from the timer"], } }); var _cmdBasic = cmdForLevel("basic", { giftto: { help: ["Gift your ticket to another user", "[username] - Name of user to gift your ticket"], handler: function (args, user) { if (this.isLevel('mod')) { _notice.error("Mods can give tickets directly to users, check /giveticket", user); return; } ; if (args.length != 1) { _notice.info(this.buildHelp(['giftto'], _cmdBasic), user); return; } if (cb.limitCam_isRunning()) { _notice.error("Show has started, ticket gifting is no longer possible!", user); return; } if (!cb.limitCam_userHasAccess(user)) { _notice.error("You don't have ticket to gift!", user); return; } var giftUser = this.cleanUsername(args[0]); if (_modList.indexOf(giftUser) >= 0) { _notice.error(giftUser + " is a Mod.", user); return; } if (cb.limitCam_userHasAccess(giftUser)) { _notice.error(giftUser + " already has a ticket.", user); return; } cb.limitCam_removeUsers([user]); cb.limitCam_addUsers([giftUser]); if (_anonList.indexOf(user) >= 0) { _notice.info("Anonimous has gifted a ticket to " + giftUser); } else { _notice.info(user + " has gifted a ticket to " + giftUser); } _notice.info("Remember that now to join show you need to buy a ticket.", user); } }, showinfo: { handler: function (args, user) { _notice.info("TODO showinfo do user " + user); } }, tshelp: { help: "Shows this screen, use /tshelp <command> for details", handler: function (args, user) { if (args.length == 1 && args[0] == 'tshelp') { args = []; } _notice.info(this.buildHelp(args, _cmdBasic), user); } } }); var _timers = new TimerManager(); var _startShowTimer = undefined; var _showPlanTimer = undefined; function _announce(text, user) { if (!this.n) { this.n = _themeManager.noticeHandler('optionsColor2'); } var lines = Array.isArray(text) ? text : [text]; var len = 0; var replaces = false; var filters = false; for (var line of lines) { if (line === undefined || line === '') { filters = true; continue; } len = Math.max(len, line.length); replaces = replaces || (line === '-'); } if (filters) { lines = lines.filter(function (ln) { return !!ln; }); } var splitter = '-'.repeat(len); if (replaces) { for (var idx in lines) { if (lines[idx] === '-') { lines[idx] = splitter; } } } this.n([splitter].concat(lines).concat(splitter), user); } ; function _ticketInfo() { if (_canGetTickets) { return _recommendGetTickets ? ("You can stil buy a ticket for " + _settings.ticketAmount + " tokens") : "Not recommended to buy tickets"; } return 'No more tickets avaiable.'; } function _startShowTimerHandler(event) { if (event.eventData) { _notice.announce("Show should be ready to start in " + event.eventData + "-"); } else if (event.type == 'start') { _notice.announce("Show timer started, it will take " + _startShowTimer.minutesDuration() + " minutes."); } else if (event.type == 'stop') { _notice.announce("Show timer ended! Show can start at anytime..."); _startShowTimer = undefined; } } function _createShowStartTimer(durationMs, user) { var timerSettings = { durationMs: durationMs, timerName: 'StartShowTimer', username: user, eventHandler: _startShowTimerHandler, eventDataMap: { 'm5': "5 minutes", 'm2': "2 minutes", 'm1': "1 minute" } }; _startShowTimer = _timers.createTimer(timerSettings); } function _plantTimerHandler(event) { if (event.eventData) { _notice.announce("Time for - " + event.eventData); } } function _createPlanTimer() { var durationMs = 0; var eventDataMap = {}; for (var entry of _settings.plans) { var entryArgs = entry.split('--'); if (entryArgs.length != 2) { continue; } var entryDurationMs = parseInt(entryArgs[0]) * 60 * 1000; if (entryDurationMs > 0) { var key = 'm' + parseInt(entryArgs[0]); if (!eventDataMap.hasOwnProperty(key)) { eventDataMap[key] = entryArgs[2].trim(); } if (entryDurationMs > durationMs) { durationMs = entryDurationMs; } } } var timerSettings = { durationMs: durationMs, timerName: 'PlanTimer', username: cb.room_slug, eventHandler: _plantTimerHandler, eventDataMap: eventDataMap }; if (durationMs > 0) { _showPlanTimer = _timers.createTimer(timerSettings); } } var _notice = { info: _themeManager.noticeHandler('optionsColor2'), announce: _announce, error: _themeManager.noticeHandlerWithColor(clr2w('white', 'red', 'bold')) }; var _settings; var _tipsSumAmount = 0; var _ticketsCount = 0; var _timerRunning = false; var _canGetTickets = true; var _recommendGetTickets = true; var _showStartTimestamp = 0; var _modList = []; var _anonList = []; function updatePanel() { _ticketsCount = cb.limitCam_allUsersWithAccess().length; cb.drawPanel(); } function _adMessage() { return "TODO: ad"; } function _onStart(user) { _settings = buildSettingsParsers({ targetTimer: settingParser().map((value) => value * 60 * 1000), titleTags: settingParser().map((value) => value.trim().length == 0 ? "" : " " + value.trim().replace(/ /g, " ")), planType: settingParser().asType('no', 'with_all', 'with_mods'), supportAnonimous: settingParser().asBoolean() }); if (_settings.titleTags || _settings.title) { cb.changeRoomSubject(_settings.title + ' ' + _settings.titleTags); } var customTheme = { mainColor2: clr2w('#1b1b1b', '#e8e8e8', 'bold'), alternativeColor2: clr2w('#515151', 'white', 'bold'), highlightColor2: clr2w('#2c2c2c', '#f4f4f4', 'bold'), bannerColor2: clr2w('black', 'white', 'bold'), optionsColor2: clr2w('black', 'white', 'bold') }; _themeManager.setCustomTheme(customTheme); _adBanner.setThemeColor2(customTheme.bannerColor2); _adBanner.setMessageBuilder(_adMessage); _notice.announce(APPNAME + " bot has started."); if (_settings.targetTimer > 0) { _createShowStartTimer(_settings.targetTimer, cb.room_slug); } } function _showTime() { var dt = new Date(0); var msecs = Date.now() - _showStartTimestamp; dt.setMilliseconds(msecs); if (msecs < 60 * 60 * 1000) { return dt.toUTCString().substring(20, 25); } return dt.toUTCString().substring(16, 25); } function _onEnter(user) { if (!user.has_tokens) { return; } if (user.is_mod && _canGetTickets && !cb.limitCam_userHasAccess(user.user)) { cb.limitCam_addUsers([user.user]); _modList.push(user.user); _notice.info("A ticket has been given to you because your a Mod.", user.user); updatePanel(); return; } if (cb.limitCam_userHasAccess(user.user)) { return; } var title = APPNAME; if (cb.limitCam_isRunning()) { var timeText = "Show already started for " + _showTime(); if (_canGetTickets) { _notice.announce([title, '-', timeText, _ticketInfo()], user.user); } else { _notice.announce([title, '-', timeText, 'Show is about to end!', _ticketInfo()], user.user); } } else if (_canGetTickets) { var text = "Buy a ticket for " + _settings.ticketAmount + " tokens"; var tshelpText = "Use /tshelp to show a list of general commands"; _notice.announce([title, '-', text, tshelpText], user.user); } } function _onDrawPanel(user) { if (_canGetTickets) { var tokensLabel = 'Tokens Received', tokensValue = String(_tipsSumAmount); if (_settings.targetAmount > 0) { tokensLabel = 'Tokens Received / Goal'; tokensValue = _tipsSumAmount + " / " + _settings.targetAmount; } return { "template": "3_rows_of_labels", 'row1_label': 'Ticket price', 'row1_value': _settings.ticketAmount, 'row2_label': 'Ticket holders', 'row2_value': _ticketsCount, 'row3_label': tokensLabel, 'row3_value': tokensValue }; } return { "template": "3_rows_of_labels", 'row1_label': 'Ticket price', 'row1_value': '-Closed-', 'row2_label': 'Ticket holders', 'row2_value': _ticketsCount, 'row3_label': '', 'row3_value': '' }; } function _onTip(tip) { if (_canGetTickets && _settings.ticketAmount <= tip.amount && !cb.limitCam_userHasAccess(tip.from_user)) { if (_settings.supportAnonimous && tip.is_anon_tip) { _notice.info("Ticket was bought by an anonimous."); _anonList.push(tip.from_user); } else { _notice.info("Ticket was bought by: " + tip.from_user); } cb.limitCam_addUsers([tip.from_user]); updatePanel(); } _tipsSumAmount += tip.amount; } function _onMessage(msg) { var cmdMsg = { msg }; _cmdMod.process(cmdMsg); _cmdBasic.process(cmdMsg); return msg; } return { init: function () { cb.onStart(_onStart); cb.onEnter(_onEnter); cb.onDrawPanel(_onDrawPanel); cb.onTip(_onTip); cb.onMessage(_onMessage); } }; } bot().init();
© Copyright Freesexcam 2011- 2024. All Rights Reserved.