use regex to remove every instance of the banned words

This commit is contained in:
loicbersier 2019-08-23 12:45:41 +02:00
parent 88c31d9433
commit 4e52a04320

View file

@ -26,9 +26,9 @@ class messageListener extends Listener {
let censoredMessage = message.content.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, ''); let censoredMessage = message.content.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '');
// Remove zero width space character // Remove zero width space character
censoredMessage = censoredMessage.replace(/\u200B/g, ''); censoredMessage = censoredMessage.replace(/\u200B/g, '');
for (let i = 0; i < bannedWords.length; i++) { for (let i = 0; i < bannedWords.length; i++) {
censoredMessage = censoredMessage.replace(bannedWords[i].get('word'), '█'.repeat(bannedWords[i].get('word').length)); let regex = new RegExp(bannedWords[i].get('word'), 'g');
censoredMessage = censoredMessage.replace(regex, '█'.repeat(bannedWords[i].get('word').length));
} }
let Embed = new MessageEmbed() let Embed = new MessageEmbed()
.setColor('#FF0000') .setColor('#FF0000')