Bots Home
|
Create an App
switcharoo
Author:
loriimeyerzz
Description
Source Code
Launch Bot
Current Users
Created by:
Loriimeyerzz
cb.settings_choices = [ {name: 'mods', label: 'Users who can add/remove replacements on the fly', type: 'str', required: 'false', defaultValue: 'loriimeyers'}, {name: 'type', label: 'Applies to', type: 'choice', choice1: 'ModsToo', choice2: 'Everyone', defaultValue: 'Everyone'}, {name: 'rep1', label: 'Replacement 1', type: 'str', defaultValue: 'bitch, whore, slut: lovely lady', required: false} ]; for (var i = 2; i < 31; i++) cb.settings_choices.push({name: 'rep' + i, label: 'Replacement ' + i, type: 'str', required: false}); var mods = cb.settings.mods ? cb.settings.mods.toLowerCase().split(/\s*,\s*/) : []; var say = (message, user, color, wt) => cb.sendNotice(newLines(message), user, '', color || '#000099', wt || 'bold'); var newLines = (input) => '\u25CF ' + input.replace(/\n/g, '\n\u25CF '); var words = {}; for (var i = 1; i < 31; i++) { var line = cb.settings['rep' + i]; if (line) makeReplacement(line); } function makeReplacement(input) { if (!input) return; var arr = line.split(/\s*:\s*/); if (arr.length > 1) { var triggers = arr[0].split(/\s*,\s*/); var result = arr.slice(1).join(':'); triggers.forEach((item) => words[item] = result); } } function shouldBeCensored(msg) { return cb.settings.type === 'ModsToo' || (cb.settings.type === 'Everyone' && !hasImmunity(msg)); } function hasImmunity(msg) { return (msg['user'] === cb.room_slug || msg['is_mod']); } cb.onMessage(function (msg) { if (/^\//.test(msg.m) && (msg.user === cb.room_slug || mods.includes(msg.user))) { command(msg.m, msg.user); } else if (shouldBeCensored(msg)) { for (var word in words) msg.m = msg.m.replace(new RegExp('\\b' + word + 's?\\b', 'ig'), words[word]); } return msg; }); function command(input, user) { var cmd = input.split(/\s+/); switch (cmd[0]) { case '/cw#': evaluate(cmd.slice(1).join(' '), user); break; case '/cw_add': makeReplacement(cmd.slice(1).join(' ')); say('Replacement(s) added.', user); break; case '/cw_rem': cmd.slice(1).join(' ').split(/\s*,\s*/).forEach((word) => delete words[word]); say('Replacement(s) removed.', user); break; } } function evaluate(str, user) { try { var result = eval(str); var notice = 'INPUT: ' + str + '\nTYPE: ' + typeof result + '\nVALUE: '; result === void 0 ? notice += 'undefined' : notice += JSON.stringify(result, null, '\u2007\u2007\u2007\u2007'); cb.setTimeout(() => {cb.sendNotice(newLines(notice), user, '', '#00CC00', '', '')}, 100); } catch (e) { cb.setTimeout(() => {cb.sendNotice(newLines(e.name + ': ' + e.message), user, '', '#FF0000', '', '')}, 100); } }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.