Bots Home
|
Create an App
g-bot
Author:
codeanon2
Description
Source Code
Launch Bot
Current Users
Created by:
Codeanon2
cb.settings_choices = [ {name: 'mods', label: 'Mods who can access bot commands', type: 'str', defaultValue: 'codeanon', required: false}, {name: 'roomfgcolor', label: '[GENERAL] -------------------------------- Room notice font color', type: 'str', defaultValue: '#000000', required: false}, {name: 'roombgcolor', label: 'Room notice background color', type: 'str', defaultValue: '#FFFFFF', required: false}, {name: 'tipMenu_interval', label: '[TIP MENU] ---------------------- Seconds between displays of the tip menu (0 = off)', type: 'int', defaultValue: 60, minvalue: 0}, {name: 'tipMenu_color', label: 'Color', type: 'str', required: false, defaultValue: '#880000'}, {name: 'tipMenu_obj', label: 'Values', type: 'str', required: false, defaultValue: '22: feet, 33: spanks, 44: tits, 55: ass, 66: pussy, 99: lick feet, 111: pussy tease, 222: vibrator tease, 333: dildo tease'}, {name: 'blocked', label: '[WORD BLOCKING] ---------------------- Blocked Words', type: 'str', required: false, defaultValue: 'bb,baby,babe,slut,whore,dick,penis,masturbate'}, {name: 'superblocked', label: 'Superblocked Words', type: 'str', required: false}, {name: 'block_type', label: 'Type', type: 'choice', choice1: 'Censor word', choice2: 'Hide entire message', defaultValue: 'Hide entire message', required: false}, {name: 'block_for', label: 'Applies to', type: 'choice', required: false, choice1: 'Everyone', choice2: 'Greys', choice3: 'Nobody', defaultValue: 'Greys'}, {name: 'block_grey_emotes', label: 'Block grey emotes', type: 'choice', choice1: 'true', choice2: 'false', defaultValue: 'true', required: false}, {name: 'message_0', label: '[ROTATING MESSAGES] -------------------- Message 01', required: false, type: 'str'}, {name: 'message_1', label: 'Message 02', required: false, type: 'str'}, {name: 'message_2', label: 'Message 03', required: false, type: 'str'}, {name: 'message_3', label: 'Message 04', required: false, type: 'str'}, {name: 'message_4', label: 'Message 05', required: false, type: 'str'}, {name: 'message_5', label: 'Message 06', required: false, type: 'str'}, {name: 'message_6', label: 'Message 07', required: false, type: 'str'}, {name: 'message_7', label: 'Message 08', required: false, type: 'str'}, {name: 'message_8', label: 'Message 09', required: false, type: 'str'}, {name: 'message_9', label: 'Message 10', required: false, type: 'str'}, {name: 'message_10', label: 'Message 11', required: false, type: 'str'}, {name: 'message_11', label: 'Message 12', required: false, type: 'str'}, {name: 'message_12', label: 'Message 13', required: false, type: 'str'}, {name: 'message_13', label: 'Message 14', required: false, type: 'str'}, {name: 'message_14', label: 'Message 15', required: false, type: 'str'}, {name: 'messages_interval', label: 'Seconds between displays of the rotating messages (0 = off)', type: 'int', defaultValue: 60, minvalue: 0}, {name: 'messages_delay', label: 'Seconds before messages start rotating', type: 'int', defaultValue: 30, minvalue: 0}, {name: 'messages_color', label: 'Message color (hex code)', type: 'str', defaultValue: '#000000', required: false}, {name: 'lb_interval', label: '[LEADERBOARD] ---------------------- Seconds between displays of the leaderboard', type: 'int', minvalue: 0, defaultValue: 60}, {name: 'lb_delay', label: 'Seconds before leaderboard starts displaying', type: 'int', minvalue: 0, defaultValue: 30}, {name: 'lb_color', label: 'Leaderboard color', type: 'str', defaultValue: '#000000', required: false}, {name: 'lb_emote', label: 'Leaderboard emote', type: 'str', required: false}, {name: 'wordnotice_0', label: '[REACTIVE NOTICES] ---------------------- Notice 01', type: 'str', required: false, defaultValue: 'pm, pms: This model does not send or receive PMs. Please put all such messages in tip notes.'}, {name: 'wordnotice_1', label: 'Notice 02', type: 'str', required: false, defaultValue: 'pvt, pvts, private, privates: This model does not do unscheduled privates. To schedule a private, please send an email to the address in her bio.'}, {name: 'wordnotice_2', label: 'Notice 03', type: 'str', required: false}, {name: 'wordnotice_3', label: 'Notice 04', type: 'str', required: false}, {name: 'wordnotice_4', label: 'Notice 05', type: 'str', required: false}, {name: 'rule0', label: '[ROOM RULES] ---------------------- Rule 1', type: 'str', required: false}, {name: 'rule1', label: 'Rule 2', type: 'str', required: false}, {name: 'rule2', label: 'Rule 3', type: 'str', required: false}, {name: 'rule3', label: 'Rule 4', type: 'str', required: false}, {name: 'rule4', label: 'Rule 5', type: 'str', required: false}, {name: 'rule5', label: 'Rule 6', type: 'str', required: false}, {name: 'rule6', label: 'Rule 7', type: 'str', required: false}, {name: 'rules_interval', label: 'Seconds between displays of the room rules (0 = off)', type: 'int', defaultValue: 180}, {name: 'rules_delay', label: 'Seconds before rules start displaying', type: 'int', defaultValue: 60}, {name: 'rules_color', label: 'Rules color (hex code)', type: 'str', defaultValue: '#000000', required: false} ]; //tips var tipTotal = 0; var tipLedger = {}; var tipMenu_obj; var tipMenuOn = true; //leaderboard var leaderBoard = function () { var arr = []; arr.color = cb.settings.lb_color; return arr; }(); var emote = function () { if (cb.settings.lb_emote && cb.settings.lb_emote.trim().length > 0) { return cb.settings.lb_emote.trim(); } else { return '\u265B'; } }(); //messages var reactives = {}; var blocked = []; blocked.name = 'blocked'; var superBlocked = []; superBlocked.name = 'super-blocked'; var blockType = cb.settings.block_type; //other var modList = []; /********** ------------ EVENT HANDLERS ------------ **********/ //when a new tip comes in, increment everything cb.onTip(function (tip) { var amount = tip['amount']; var user = tip['from_user']; addTip(user, amount); checkLeaderboard(user); checkTips(user, amount); }); //when a new message comes in, either process a command or change the display cb.onMessage(function (msg) { if (msg['m'].charAt(0) === '/') { msg['X-Spam'] = true; var user = msg['user']; if (user === cb.room_slug || cbjs.arrayContains(modList, user)) { cmd(msg['m'].substring(1), user); } } else { censor(msg); displayKing(msg); displayTips(msg); showReactions(msg); } return msg; }); /********** ------------ CENSORING ------------ **********/ //check if the messsage should be processed through the filter function shouldBeCensored(msg) { if (cb.settings.block_for === 'Everyone') { return true; } else if (cb.settings.block_for === 'Greys' && !hasImmunity(msg)) { return true; } return false; } //checks user for immunity to stickyKeys and Emoticons... function hasImmunity(msg) { return (msg['is_mod'] || msg['has_tokens'] || msg['tipped_recently'] || msg['tipped_alot_recently'] || msg['tipped_tons_recently']); } //show automatic reactions to messages function showReactions(msg) { var text = msg['m'].toLowerCase(); for (var key in reactives) { var exp = RegExp('\\b' + key + '\\b'); if (exp.test(text)) tellUser(reactives[key]); } } //censor the message function censor(msg) { var warningMessage; var text = msg['m']; if (shouldBeCensored(msg) && containsBlockedWord(text)) { if (blockType === 'Hide entire message') { warningMessage = 'Your message has been removed due to the use of innapropriate word(s).' msg = processCensor(msg, warningMessage); } else { msg['m'] = censorBlockedWords(text); } } else if (!hasImmunity(msg)) { if (hasStickyKeys(text)) { warningMessage = 'Your message has been removed due to constant repitition of the same letter (Sticky Keys).' msg = processCensor(msg, warningMessage); } else if (cb.settings.block_grey_emotes === 'true' && hasEmoticon(text)) { warningMessage = 'I\'m sorry. grey users are not allowed to post emoticons.' msg = processCensor(msg, warningMessage); } else if (hasCapslock(text)) { warningMessage = 'We\'ve detected that you\'re using too many capital letters. Here, let me fix that for you.'; tellUser(warningMessage, msg['user']); msg['m'] = String(msg['m']).toLowerCase(); } else if (containsSuperBlockedWord(text)) { msg['X-Spam'] = true; } } } //added new method rather than duplicate code. function processCensor(msg, warningMessage) { tellUser(warningMessage, msg['user']); msg['X-Spam'] = true; msg['m'] = '*******'; } //check if text contains sticky keys function hasStickyKeys(input) { str = input.replace(/\s+/g, '_'); return /(\S)(\1{2,})/g.test(str); } //check if text contains an emoticon function hasEmoticon(input) { var exp = /(^|\s):\w{3,}($|\s)/; if (exp.test(input)) return true; return false; } //check if text contains capslock function hasCapslock(input) { str = input.replace(/\s+/g, '_'); return /([A-Z]{3,})/g.test(str); } //censor only blocked words function censorBlockedWords(text) { var sanitized = text.replace(/\s+/g, ' '); var words = sanitized.split(' '); var censored = sanitized; for (var i = 0; i < blocked.length; i++) { for (var j = 0; j < words.length; j++) { var x = remPunk(words[j].toLowerCase()); if (x === blocked[i]) { words[j] = '*******'; } } } return words.join(' '); } //remove punctuation from a string function remPunk(text) { return text.replace(/[^A-Za-z0-9]/g, ''); } //see if a string contains a blocked word function containsBlockedWord(input) { var text = input.replace(/\s+/g, ' ').toLowerCase(); for (var i = 0; i < blocked.length; i++) { var exp = RegExp('\\b' + blocked[i] + '\\b'); if (exp.test(text)) return true; } return false; } //CANDEHMAN - Checks if the string contains any instances of the super blocked word. function containsSuperBlockedWord(text) { cb.log('Checking...'); var sanitized = text.replace(/[^a-zA-Z\d]/g, '').toLowerCase(); for (var i = 0; i < superBlocked.length; i++) { if (sanitized.indexOf(superBlocked[i]) > -1) { return true; } } return false; } /********** ------------ TIP DISPLAY ------------ **********/ //add the number of tips to the beginning of a user's message function displayTips(msg) { var user = msg['user']; if (tipLedger[user]) msg['m'] = '|' + tipLedger[user] + '| ' + msg['m']; return msg; } //increment the user's entry in tipLedger function addTip(user, number) { tipTotal += number; acct_notice(money(number) + ' received (' + money(tipTotal) + ' total this broadcast)'); tipLedger[user] ? tipLedger[user] += number : tipLedger[user] = number; } function money(num) { if (!isNaN(num)) { var dollars = Math.ceil(num * 5) / 100; return '$' + parseFloat(Math.round(dollars * 100) / 100).toFixed(2); } return NaN; } //display a message if a user has tipped for something on the menu function checkTips(user, amount) { if (tipMenuOn && tipMenu_obj[amount]) { tellUser(user + ' tipped for ' + tipMenu_obj[amount] + '!', '', cb.settings.tipMenu_color); } } //start a rotating tip menu function tipRotator() { if (cb.settings.tipMenu_interval > 0 && tipMenuOn) { displayTipMenu(); cb.setTimeout(tipRotator, cb.settings.tipMenu_interval * 1000); } } /********** ------------ LEADERBOARD ------------ **********/ function checkLeaderboard(user) { if (leaderBoard.length === 0) { leaderBoard.push(user); } else { for (var i = 0; i < 5; i++) { var pos = leaderBoard[i]; if (!pos) { if (leaderBoard.indexOf(user) === -1) leaderBoard.push(user); break; } else if (tipLedger[user] > tipLedger[pos]) { if (leaderBoard.indexOf(user) === -1) leaderBoard.push(user); leaderBoard.sort(function (a,b) {return tipLedger[b] - tipLedger[a];}); while (leaderBoard.length > 5) leaderBoard.pop(); break; } } } } function showLeaderboard() { var title = '\u25CF \u25CF LEADERBOARD \u25CF \u25CF \u25CF '; var output = ''; for (var i = 0; i < leaderBoard.length && i < 5; i++) { output += '\n' + (i + 1) + '. ' + leaderBoard[i] + ' |' + tipLedger[leaderBoard[i]] + '|'; if (i === 0) output += ' \u265B'; } output = output.trim(); cb.sendNotice(newLines(title), '', cb.settings.lb_color, '#FFFFFF', 'bold', ''); cb.sendNotice(newLines(output), '', '#FFFFFF', cb.settings.lb_color, 'bold', ''); } function displayKing(msg) { if (leaderBoard[0] && msg.user === leaderBoard[0]) msg.m = emote + ' ' + msg.m; } /********** ------------ ROTATORS ------------ **********/ var rotatingMessages = []; //rotate displays of messages function messageRotator() { var message = rotatingMessages[0]; cb.sendNotice(newLines(message), '', '', cb.settings.messages_color, 'bold', ''); rotatingMessages.push(rotatingMessages.shift()); cb.setTimeout(messageRotator, cb.settings.messages_interval * 1000); } function lbRotator() { showLeaderboard(); cb.setTimeout(lbRotator, cb.settings.lb_interval * 1000); } function rulesRotator() { showRules(); cb.setTimeout(rulesRotator, cb.settings.rules_interval * 1000); } //populate messages to be rotated from the settings page function parseRotatingMessages() { for (var i = 0; i < 15; i++) { var message = cb.settings['message_' + i]; if (message && message.length > 0) rotatingMessages.push(message); } } function startRotators() { if (cb.settings.messages_interval && cb.settings.messages_interval > 0 && rotatingMessages.length > 0) cb.setTimeout(messageRotator, cb.settings.messages_delay * 1000); if (cb.settings.rules_interval && cb.settings.rules_interval > 0 && rules && rules.length > 0) cb.setTimeout(rulesRotator, cb.settings.rules_delay * 1000); if (cb.settings.lb_interval && cb.settings.lb_interval > 0) cb.setTimeout(lbRotator, cb.settings.lb_delay * 1000); } /********** ------------ RULES ------------ **********/ var rules = function () { var output = '====== ROOM RULES ======'; for (var i = 0; i < 7; i++) { var setting = cb.settings['rule' + i]; if (setting && setting.trim().length > 0) { output += '\n' + setting.trim(); } } output += '\n====================='; return newLines(output); }(); function showRules(user) { cb.sendNotice(rules, user, '', cb.settings.rules_color, 'bold', ''); } /********** ------------ GENERAL ------------ **********/ //process superuser commands function cmd(input, user) { var s_msg = sanitize(input).split(' '); var msg = input.split(' '); switch (msg[0]) { case 'gb_total': var text = money(tipTotal) + ' (' + tipTotal + ' tokens) received during this broadcast.'; cb.sendNotice(text, user, '#FFFF00', '#000000', 'bold', ''); break; case 'gb_savetips': tellBoth('SAVE THE JSON STRING BELOW\n' + JSON.stringify(tipLedger)); break; case 'gb_saveblocked': tellBoth('SAVE THE COMMA-SEPARATED STRING BELOW\n' + blocked.toString()); break; case 'gb_help': showHelp(user); break; case 'gb_block': block(msg[1], blocked); break; case 'gb_superblock': block(msg[1], superBlocked); break; case 'gb_savesuperblocked': //Candehman tellBoth('SAVE THE COMMA-SEPARATED STRING BELOW\n' + superBlocked.toString()); break; case 'gb_allow': allow(msg[1], blocked); break; case 'gb_superallow': allow(msg[1], superBlocked); break; case 'gb_bm': if (msg[1]) broadcasterMessage(user, paramString(input)); break; case 'gb_cn': tellUser(paramString(input)); break; case 'gb_subj': if (msg[1]) cb.changeRoomSubject(paramString(input)); break; case 'gb_tipson': tipMenuOn = true; tellBoth('Tip menu active.'); break; case 'gb_tipsoff': tipMenuOn = false; tellBoth('Tip menu inactive.'); break; case 'gb#': if (msg[1]) evaluate(input, user); break; } } //execute javascript in a try/catch block function evaluate(input, user) { cb.setTimeout(function () { var command = paramString(input); try { eval(command); } catch (e) { tellUser('JS-ERR :: ' + e.message, user, '#CC0000'); } }, 150); } //find all arguments of a command function paramString(input, stringToIndex) { if (input) { if (!stringToIndex) return input.substring(input.indexOf(' ') + 1).trim(); return input.substring(input.indexOf(stringToIndex) + stringToIndex.length + 1).trim(); } return 'ERR'; } //send a message to the broadcaster function broadcasterMessage(user, message) { specialUserNotice('[' + user.toUpperCase() + '] :: "' + message + '"', cb.room_slug); specialUserNotice('Message sent to broadcaster.', user); } //block a word function block(word, array) { if (word && array) { word = word.replace(',', '').toLowerCase(); if (word.length > 0) { array.push(word); tellBoth('The word "' + word + '" has been ' + array.name + '.'); } } } //unblock a word function allow(word, array) { if (word && array) { var index = arrayIndexOf(array, word.toLowerCase()); if (index > -1) { array.splice(index, 1); tellBoth('The word "' + word + '" is no longer ' + array.name + '.'); } } } //sanitize a string for consistency function sanitize(input) { if (input) { var s = input.replace(/\s/g, ''); s = s.replace('}{', '} {'); s = s.replace('\s+', ' '); s = s.replace(':', ': '); return s; } return void 0; } /********** ------------ COMMUNICATION ------------ **********/ //send a message to the user with special formatting function specialUserNotice(msg, username) { if (msg && username) cb.sendNotice(newLines(msg), username, '#000000', '#FFFFFF', 'bold', ''); } function acct_notice(text) { cb.sendNotice(text, cb.room_slug, '#FFFF00', '#000000', 'bold', ''); for (var i = 0; i < modList.length; i++) { cb.sendNotice(text, modList[i], '#FFFF00', '#000000', 'bold', ''); } } //send a message to the user function tellUser(msg, user, color) { cb.sendNotice(newLines(msg), user, '', color, 'bold', ''); } //send a message to the broadcaster function tellMe(msg) { cb.sendNotice(newLines(msg), cb.room_slug, cb.settings.roombgcolor, cb.settings.roomfgcolor, 'bold', ''); } //send a message to mods function tellMods(msg) { cb.sendNotice(newLines(msg), '', cb.settings.roombgcolor, cb.settings.roomfgcolor, 'bold', 'red'); } //send a message to broadcaster and mods function tellBoth(msg) { tellMe(msg); tellMods(msg); } //show the help menu to mods and broadcaster function showHelp(user) { var output = '---- COMMANDS FOR G-BOT ---- \ \n/gb_help :: show this menu again \ \n/gb_total :: show total tips received \ \n/gb_savetips :: prints a JSON string of the current tips \ \n/gb_block [word] :: adds a word to the list of blocked words \ \n/gb_superblock [word] :: adds a word to the list of super blocked words \ \n/gb_superallow [word] :: removes a word from the list of super blocked words \ \n/gb_allow [word] :: removes a word from the list of blocked words \ \n/gb_cn [message] :: sends a notice to the entire room \ \n/gb_bm [message] :: sends a notice to the broadcaster \ \n/gb_subj [subject] :: changes the room subject \ \n/gb_tipsoff :: deactivates the tip menu \ \n/gb_tipson :: reactivates the tip menu \ \n/gb# [JavaScript] :: runs a JS expression (only use in emergencies)'; tellUser(output, user); } //show the tip menu function displayTipMenu(user) { var output = '====== TIP MENU ======'; for (var key in tipMenu_obj) { output += '\n' + key + ' tokens [' + tipMenu_obj[key] + ']'; } output += '\n==================='; tellUser(output, user, cb.settings.tipMenu_color); } /********** ------------ MISCELLANEOUS ------------ **********/ //add to all newline characters in a string for readability function newLines(input) { return '\u25A0 ' + input.replace(new RegExp('\n', 'g'), '\n\u25A0 '); } //check if an array contains an instane of the object function arrayIndexOf(array, obj) { for (var i = 0; i < array.length; i++) { if (array[i] === obj) return i; } return -1; } /********** ------------ INITIALIZATION ------------ **********/ //run all initialization functions function init() { populateModList(); populateTipMenus(); parseTips(cb.settings.prevtips); parseBlocked(false, cb.settings.blocked); parseBlocked(true, cb.settings.superblocked); parseRotatingMessages(); //sets the rotating messges parseReactive(); showHelp(cb.room_slug); startRotators(); } //populates the mod list with the pre-defined users function populateModList() { var mods = String(cb.settings.mods).split(','); mods.forEach(function (entry) { entry = entry.trim(); modList.push(String(entry)); }); } //creates a data-based tip menu from the settings function parseTipMenu(menu) { var obj = {}; if (menu) { var menuArray = menu.split(','); menuArray.forEach(function (item) { var itemArray = item.split(':'); var key = itemArray[0]; var value = itemArray[1]; if (key && value) obj[key.trim()] = value.trim(); }); } return obj; } //populates all data for tip menus function populateTipMenus() { tipMenu_obj = parseTipMenu(cb.settings.tipMenu_obj); } //import the previous data to tipLedger function parseTips(input) { input = sanitize(input); if (input) tipLedger = JSON.parse(input); else cb.log('No tips to parse.'); } //parse the blocked words function parseBlocked(isSuperBlocked, input) { if (input) { var s = input.replace(/\s/g, '').replace(/,{2,}/g, ',').toLowerCase(); var arr = s.split(','); if (isSuperBlocked) { superBlocked = arr; superBlocked.name = 'super-blocked'; } else { blocked = arr; blocked.name = 'blocked'; } } } //parse reactive notices function parseReactive() { for (var key in cb.settings) { var valid = key.slice(0, 11) === 'wordnotice_' && cb.settings[key].trim().length > 0 && cb.settings[key].indexOf(':') > 0; if (valid) { var item = cb.settings[key]; var index = item.indexOf(':'); var wordStr = item.substring(0, index).trim(); var words = wordStr.replace(/\s/g, '').split(','); var notice = item.substring(index + 1).trim(); for (var i = 0; i < words.length; i++) { var word = words[i].toLowerCase(); reactives[word] = notice; } } } } /********** ------------ EXECUTE ------------ **********/ init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.