Bots Home
|
Create an App
Banned Words
Author:
londonrayne
Description
Source Code
Launch Bot
Current Users
Created by:
Londonrayne
// Auto-moderator bot // Author: asdfghjkl28 // Commands the room owner can use var unsilenceCommand = '/unsil'; var statsCommand = '/stats'; var helpCommand = '/help'; // Data structures for silenced and warned lists var silenced = {}; var warned = {}; var maxWarnings = 1; var totalWarnings = 0; var totalSilenced = 0; var totalMessagesBlocked = 0; // Default patterns for single word matches (covers the three cases) var wordPatternStart = /^bb\s+?/i; var wordPatternEnd = /\s+?bb$/i; var wordPatternMiddle = /\s+?bb\s+?/i; // Default pattern for phrase matches (not as rigorous as the word matcher var phrasePattern = /open boobs/i; // Pattern to find phrases in the bad word list var phraseFinder = /\s+/i; var repeatedCharPattern = /([:]*)[a-z0-9]*([a-z0-9])\2{4,}/ig; // CB app settings cb.settings_choices = [ {name: 'silenced', label: 'Users you want permanently silenced (separated by spaces)', type: 'str', minLength: 0, maxLength: 10240, required: false}, {name: 'badwords', label: 'Words or phrases you want to silence users for saying (separated by commas)', type: 'str', minLength: 0, maxLength: 10240, defaultValue: 'bb,baby,babe,show boobs,show feet,:goat'}, {name: 'blockRepeatedChars', type: 'choice', label: 'Also block messages with lots of repeated letters (e.g. mmmmmmmmmmmm)', choice1: 'Yes', choice2: 'No', defaultValue: 'No'}, {name: 'maxWarnings', label: 'Number of times to warn users before permanently silencing them (enter 0 to silence on first offence)', type: 'int', minValue: 0, maxValue: 10, defaultValue: 5}, {name: 'hideOrSilence', type: 'choice', label: 'Just Hide messages with the bad words, or completely Silence users who use the the bad words after being warned', choice1: 'Hide', choice2: 'Silence', defaultValue: 'Hide'}, {name: 'allowTipToUnsilence', type: 'choice', label: 'Allow users to tip to become unsilenced', choice1: 'Yes', choice2: 'No', defaultValue: 'No'}, {name: 'tokensToBeUnsilenced', label: 'Minimum size of tip to become unsilenced', type: 'int', minValue: 0, defaultValue: 50} ]; // Main on message callback function cb.onMessage(function (msg) { // vars for ease of use var m = msg['m']; var u = msg['user']; // check for action if (m[0] == '/') { // don't print commands msg['X-Spam'] = true; // check if user can perform actions if (!canControlBot(msg)) { cb.chatNotice('Only the broadcaster and moderators can use commands!', u); } else { // Find command parameters var commandParts = m.split(' '); var commandName = commandParts[0]; cb.log('commandName: ' + commandName); if (commandName == unsilenceCommand && commandParts.length > 1) // unsilence with username parameter { var commandParam = commandParts[1]; if (unSilenceUser(commandParam)) { cb.chatNotice('User ' + commandParam + ' has been unsilenced by ' + u); cb.chatNotice('You have been unsilenced by ' + u + ' however if you break the rules again, you will be silenced without warning.', commandParam); } else { cb.chatNotice('User ' + commandParam + ' was not on the unsilence list.', u); } } else if (commandName == statsCommand) // stats { cb.chatNotice('Auto-moderator stats', u); cb.chatNotice('Messages blocked: ' + totalMessagesBlocked, u); cb.chatNotice('Warnings issued: ' + totalWarnings, u); cb.chatNotice('Users silenced: ' + totalSilenced, u); } else if (commandParts[0] == helpCommand) // help { usage(u); } else { cb.chatNotice('Command \'' + commandName + '\' not recognised.', u); usage(u); } } } else if (isSilenced(u)) { cb.chatNotice('Your message was rejected because you have been silenced because you ignored the warnings about banned words, your messages won\'t be seen by anyone else', u); msg['X-Spam'] = true; totalMessagesBlocked++; if (cb.settings.allowTipToUnsilence) { cb.chatNotice('You can tip ' + cb.settings.tokensToBeUnsilenced + ' tokens or more in one tip to become unsilenced.',u); } } else { if (!canControlBot(msg)) { cb.log('Checking content of message'); // Not room owner or moderator and not silenced so test message content against patterns if (wordPatternStart.test(m) || wordPatternEnd.test(m) || wordPatternMiddle.test(m) || phrasePattern.test(m)|| hasRepeatedChars(m)) { msg['X-Spam'] = true; totalMessagesBlocked++; // Used a bad word or phrase if (cb.settings.hideOrSilence == 'Silence') { if (u in warned) { warned[u] = {'warnedScore': warned[u].warnedScore + 1}; } else { warned[u] = {'warnedScore': 1}; } cb.log("Warned: " + u + " " + warned[u].warnedScore + " times."); totalWarnings++; // Actually silence users who have been warned more than threshold if (warned[u].warnedScore > cb.settings.maxWarnings) { // Silence the user silenceUser(u); cb.chatNotice('You have been silenced because you ignored the warnings, your messages won\'t be seen by anyone else', u); cb.chatNotice('User ' + u + ' has been silenced by the autosilence bot'); cb.chatNotice('Broadcaster: you can unsilence this user by typing the following:\n' + unsilenceCommand + ' ' + u, cb.room_slug); } else { // Actually warn the user var remainingWarnings = (cb.settings.maxWarnings - warned[u].warnedScore) + 1; if (remainingWarnings > 1) { cb.chatNotice('Your last message was rejected because you used a word or phrase from the banned list. If you do this ' + remainingWarnings + ' more times, you will be permanently silenced and all of you messages will be rejected.', u); printBannedItemsMessage(u); } else { cb.chatNotice('Your last message was rejected because you used a word or phrase from the banned list. If you do this again, you will be permanently silenced and all of you messages will be rejected.', u); printBannedItemsMessage(u); } } } else { // Just hide this message cb.chatNotice('Your last message was rejected because you used a word or phrase from the banned list', u); printBannedItemsMessage(u); } } } else { cb.log('Not checking content of message because user is a controller'); } } msg['m'] = m; return msg; }); cb.onTip(function (tip) { var amountTipped = parseInt(tip['amount']); if (isSilenced(tip['from_user'])) { if (amountTipped >= cb.settings.tokensToBeUnsilenced) { unSilenceUser(tip['from_user']); cb.chatNotice('User ' + tip['from_user'] + ' has been unsilenced because they tipped at least ' + cb.settings.tokensToBeUnsilenced + ' tokens'); } } }); function hasRepeatedChars(text) { if (cb.settings.blockRepeatedChars == 'Yes') { var match; while (match = repeatedCharPattern.exec(text)) { if (!match[1]) { // Only return true if the 'word' isn't an emoticon code return true; } } // None found so ok return false; } // feature turned off so ok return false; } function printBannedItemsMessage(user) { cb.chatNotice('Banned words and phrases: ' + cb.settings.badwords, user); if (cb.settings.blockRepeatedChars == 'Yes') { cb.chatNotice('Messages with lots of repeated characters (e.g. mmmmmmm) are also banned', user); } } function usage(u) { cb.chatNotice('Available commands:', u); cb.chatNotice(unsilenceCommand +' <username>\' - unsilence <username>', u); cb.chatNotice('/stats - show stats on total messages blocked, users silenced etc.', u); cb.chatNotice('/help - show this help message', u); } function silenceUser(username) { silenced[username] = {'u': 1}; totalSilenced++; } function unSilenceUser(username) { if (isSilenced(username)) { delete silenced[username]; return true; } else { return false; } } function isSilenced(username) { return (username in silenced); } function canControlBot(msg) { return (msg['user'] == cb.room_slug || msg.is_mod); } function grabSettings() { if (cb.settings.silenced) { var silencedSettings = cb.settings.silenced.split(' '); for (var ii = 0; ii < silencedSettings.length; ii++) { silenced[silencedSettings[ii]] = {'u': 1}; } } if (cb.settings.badwords) { var badPattern = ''; var badPhrasePattern = ''; var badWordsSettings = cb.settings.badwords.split(','); for (var ii = 0; ii < badWordsSettings.length; ii++) { if (phraseFinder.test(badWordsSettings[ii])) { if (badPhrasePattern.length == 0) { badPhrasePattern += "(" + badWordsSettings[ii]; } else { badPhrasePattern += "|" + badWordsSettings[ii]; } } else { if (badPattern.length == 0) { badPattern += "(" + badWordsSettings[ii]; } else { badPattern += "|" + badWordsSettings[ii]; } } } badPattern += ")"; badPhrasePattern += ")"; cb.log("badwords " + badPattern); cb.log("badphrases " + badPhrasePattern); wordPatternStart = new RegExp('^' + badPattern + '(\\b|\\s)', 'i'); wordPatternEnd = new RegExp('(\\b|\\s)' + badPattern + '$', 'i'); wordPatternMiddle = new RegExp('(\\b|\\s)' + badPattern + '(\\b|\\s)', 'i'); phrasePattern = new RegExp(badPhrasePattern, 'i'); cb.log("patterns " + wordPatternStart + " " + wordPatternEnd + " " + wordPatternMiddle + " " + phrasePattern); } } grabSettings(); cb.chatNotice('The auto-moderator bot hides messages containing words or phrases that the broadcaster has banned. It may also automatically silence all messages from users who repeatedly use these words. \nIf one of your messages is hidden you will be notified to help you avoid it in future.'); printBannedItemsMessage(); cb.chatNotice('To see the available commands, type /help into the chat window', cb.room_slug);
© Copyright Chaturbate 2011- 2026. All Rights Reserved.