Bots Home
|
Create an App
cbq
Author:
codeanon_master
Description
Source Code
Launch Bot
Current Users
Created by:
Codeanon_Master
var $ = function (input) { if (typeof input === 'string') { var user = {}; user.name = input; user.toString = () => input; user.tks = () => $.tipLedger[user.name] || 0; user.tip = (num) => tipLedger[user.name] = user.tks() + num; user.gt = (num) => user.tks() > num; user.gte = (num) => user.tks() >= num; user.lt = (num) => user.tks() < num; user.lte = (num) => user.tks() <= num; user.say = (txt, fg, bg, wt) => $.say(txt, user.name, fg, bg, wt); user.isSilenced = () => $.silenced.indexOf(user.name) > -1; user.mute = () => {if (!user.isSilenced()) $.silenced.push(user.name)}; user.unmute = () => {if (user.isSilenced()) $.silenced.splice($.silenced.indexOf(user.name), 1)}; return user; } }; (function () { /********** ------------ GENERAL ------------ **********/ $.bg = void 0, $.fg = void 0, $.model = cb.room_slug, $.tipTotalTitle = false, $.mvp = null, $.total = 0; $.init = function (bg, fg, nls, pfx, tipTotalTitle) { $.bg = bg; $.fg = fg; $.tipTotalTitle = tipTotalTitle || false; $.nls = nls && nls !== '' ? nls + ' ' : void 0; $.cmd.admin.prefix = pfx || 'cb'; }; /********** ------------ APP/BOT CONFIG ------------ **********/ cb.settings_choices = cb.settings_choices instanceof Array ? cb.settings_choices : []; $.cfg = {}; $.cfg.refresh = () => $.cfg = JSON.parse(JSON.stringify(cb.settings)); $.cfg.str = (name, label, required, defaultValue, min, max) => cb.settings_choices.push({type: 'str', name: name, label: label, minLength: min, maxLength: max, defaultValue: defaultValue, required: required}); $.cfg.int = (name, label, required, defaultValue, min, max) => cb.settings_choices.push({type: 'int', name: name, label: label, minValue: min, maxLength: max, defaultValue: defaultValue, required: required}); $.cfg.choice = (name, label, required, defaultValue, choices) => { var obj = {type: 'choice',name: name, label: label, defaultValue: defaultValue, required: required}; if (choices instanceof Array) { for (var i = 0; i < choices.length; i++) obj['choice' + (i + 1)] = choices[i]; cb.settings_choices.push(obj); } }; /********** ------------ TIPS ------------ **********/ $.tipLedger = {}; $.tipActions = [ (tip) => tip.from_user = $(tip.from_user) ]; $.tipActions.exec = (tip) => {$.tipActions.forEach((func) => func(tip))}; $.onTip = (func) => $.tipActions.push(func); cb.onTip((tip) => $.tipActions.exec(tip)); /********** ------------ MESSAGES ------------ **********/ $.nls = ''; $.setNewLineString = (str) => $.nls = str + ' '; $.msgActions = [ (msg) => { msg.hide = () => msg['X-Spam'] = true; msg.show = () => msg['X-Spam'] = false; msg.react = (trg, rpl) => { if (!trg || !rpl) { $.err('The function "msg.react(trigger, reply)" requires two arguments.'); } else { var func = typeof rpl === 'function' ? rpl : () => $.say(rpl); if (trg instanceof RegExp) { if (trg.test(msg.m)) func(); } else if (typeof trg === 'string') { if (msg.m.indexOf(trg) > -1) func(); } else { $.err('Trigger must be either String or RegExp.'); } } }; }, (msg) => $.cmd.admin.exec(msg), (msg) => $.cmd.public.exec(msg), (msg) => msg.user = $(msg.user), (msg) => msg.m = $.tipTotalTitle === true && msg.user.gt(0) ? '|' + msg.user.tks() + '| ' + msg.m : msg.m, ]; $.silenced = []; $.onMessage = (func) => $.msgActions.push(func); $.msgActions.exec = (msg) => {$.msgActions.forEach((func) => func(msg))}; $.say = (txt, usr, fg, bg, wt, grp) => { if (txt !== void 0) { txt = '' + txt; cb.sendNotice($.nls + txt.replace(/\n/g, '\n' + $.nls), usr, fg, bg, wt, grp); } }; $.err = (txt) => $.say('[cbQuery ERROR] :: ' + txt + '\n' + (new Error).stack.replace('Error\n','').replace(/(^|\n).*Function\.\$\.err.*($|\n)/, ''), $.model, '', '#FF0000', '', ''); cb.onMessage((msg) => {$.msgActions.exec(msg), msg}); /********** ------------ COMMANDS ------------ **********/ $.cmd = {}; $.cmd.admin = {'#': (str, user) => $.cmd.eval(str, user)}; $.cmd.admin.prefix = null; $.cmd.admin.add = (str, func) => $.cmd.admin[str] = func; $.cmd.admin.exec = function (msg) { if ((new RegExp('^/' + $.cmd.admin.prefix)).test(msg.m)) { msg.hide(); var arr = msg.m.split(' '), c = arr[0].substring($.cmd.admin.prefix.length + 1), p = arr.slice(1); if ($.cmd.admin[c]) $.cmd.admin[c](p.join(' '), $.model); } }; $.cmd.public = {}; $.cmd.public.add = (str, func) => $.cmd.public[str] = func; $.cmd.public.exec = function (msg) { if (/\//.test(msg.m)) { msg.hide(); var arr = msg.m.split(' '), c = arr[0].substring(1), p = arr.slice(1); if ($.cmd.public[c]) $.cmd.admin[c](p.join(' '), msg.user); } }; $.cmd.eval = function (str, user) { try { var result = eval(str); var notice = 'INPUT: ' + str + '\nTYPE: ' + typeof result + '\nVALUE: '; result !== void 0 ? notice += JSON.stringify(result, null, '\u2007\u2007\u2007\u2007') : notice += 'undefined'; cb.setTimeout(() => $.say(notice, user, '', '#00CC00', '', ''), 100); } catch (e) { cb.setTimeout(() => $.say(e.name + ': ' + e.message, user, '', '#FF0000', '', ''), 100); } }; })(); //////////////// $.init('', '', '-', 'cb', true); $.cfg.str('commanders', 'Users who can use commands', false, 'codeanon'); $.cfg.int('goal_amt', 'Tokens per goal', true, 25, 1); $.cfg.choice('goal_msg', 'Display message when goal reached', true, 'Yes', ['Yes', 'No']); $.cfg.refresh(); ////////////////
© Copyright Chaturbate 2011- 2024. All Rights Reserved.