Apps Home
|
Create an App
BadWordReplacer
Author:
rickblast
Description
Source Code
Launch App
Current Users
Created by:
Rickblast
/** Name: TinglesBadWordReplacer Author: Blastfuhler aka RickBlast Created: 2021-01-16 Version: 0.1 credits: chelsea2950 and the Dorothy's Ultra Fembot - i've learned a lot from you and took some snippets, thank you **/ cb.settings_choices = [ { name: 'badWords', type: 'str', label: 'Bad Words' }, { name: 'niceUserList', type: 'str', label: 'A list of nice users - may be short ;-)' }, { name: 'badWordWarning', type: 'str', label: 'Warning to an user for using bad words', reqiured: false, defaultValue: 'you typed a bad word, please stay nice or leave my room' }, { name: 'showWelcomeMessage', label: 'Show greetings and bad word list when a registered user enters the room', type: 'choice', choice1: 'yes', choice2: 'no', defaultValue: 'yes' }, { name: 'welcomeMessage', label: 'Welcome Message to new registred users', type: 'str', defaultValue: 'Welcome {username}! Please be kind - don\'t use the following words:' } ]; var niceListArray = []; let badWordsArray = [ 'sau', 'geil', 'badehose' ]; var BC = cb.room_slug; var checkSpecial = /[!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?]+/; function validateUserID(validateuser,validatetype,validateby,validatestartup) { if (validateuser.length < 3 || validateuser.includes(' ')) { if (validatestartup) { botLoadErrors.push('Cannot load ' + validatetype + ' entry "' + validateuser + '", it is improperly formatted (either contains a blank or is less than 3 characters).'); } else { cb.sendNotice(botName + 'Cannot load ' + validatetype + ' entry "' + validateuser + '", it is improperly formatted (either contains a blank or is less than 3 characters).', validateby, appWarningColor); } return false; } else if (checkSpecial.test(validateuser)) { if (validatestartup) { botLoadErrors.push('Cannot load ' + validatetype + ' entry "' + validateuser + '", it contains a special character.'); } else { cb.sendNotice(botName + 'Cannot load ' + validatetype + ' entry "' + validateuser + '", it contains a special character.', validateby, appWarningColor); } return false; } else { return true; } } if (cb.settings.niceUserList) { let niceary = cb.settings.niceUserList.toLowerCase(); let tempnicearray = niceary.split(','); let initnicetoadd = ''; for (let niceloadidx = 0; niceloadidx < tempnicearray.length; niceloadidx++) { initnicetoadd = tempnicearray[niceloadidx].trim(); if (validateUserID(initnicetoadd,'Nice List',BC,true)) { if (cbjs.arrayContains(niceListArray, initnicetoadd)) { botLoadErrors.push('Skipping duplicate entry for user "' + initnicetoadd + '" in the Nice List.'); } else { niceListArray.push(initnicetoadd); } } } } if(cb.settings.badWords) { const badWordsLower = cb.settings.badWords.toLowerCase(); const tempBadWordsArray = badWordsLower.split(','); for(let i=0; i < tempBadWordsArray.length; i++) { let candidate = tempBadWordsArray[i].trim(); if(!cbjs.arrayContains(badWordsArray, candidate)) { badWordsArray.push(candidate); } } } if('yes' === cb.settings.showWelcomeMessage) { cb.onEnter(function(user) { let message = cb.settings.welcomeMessage.replace('{username}', user['user']); cb.chatNotice(message + ' ' + cb.settings.badWords); }); } cb.onMessage(function (message) { let m = message['m']; const user = message['user']; let matchBadWord = false; if(!cbjs.arrayContains(niceListArray, user)) { const replacer = 'boeses Wort! Pfui!'; for(let i=0; i < badWordsArray.length; i++) { let test = new RegExp('\\b' + badWordsArray[i] + '\\b', 'ig'); if(matchBadWord === false && m.match(test)) { matchBadWord = true; } m = m.replace(test, replacer); } message['m'] = m; if(matchBadWord === true && cb.settings.badWordWarning !== '') { cb.chatNotice(cb.settings.badWordWarning, user); } } return message; });
© Copyright Chaturbate 2011- 2024. All Rights Reserved.