From 7380224fa46ee986d08716a7538e58722156c706 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sat, 24 Aug 2019 12:03:21 +0200 Subject: [PATCH] Remove non latin character --- commands/admin/banword.js | 1 + event/listeners/message.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/commands/admin/banword.js b/commands/admin/banword.js index 2f505b9..2c45d61 100644 --- a/commands/admin/banword.js +++ b/commands/admin/banword.js @@ -33,6 +33,7 @@ class BannedWordsCommand extends Command { } async exec(message, args) { + args.word = args.word.replace(/[\u0250-\ue007]/g, ''); const bannedWords = await BannedWords.findOne({where: {word: args.word.toLowerCase(), serverID: message.guild.id}}); if (!bannedWords) { diff --git a/event/listeners/message.js b/event/listeners/message.js index 6ea8065..8495ed4 100644 --- a/event/listeners/message.js +++ b/event/listeners/message.js @@ -21,11 +21,15 @@ class messageListener extends Listener { // Banned words - const bannedWords = await BannedWords.findAll({where: {word: Sequelize.where(Sequelize.fn('LOCATE', Sequelize.col('word'), message.content.replace(/\u200B/g, '')), Sequelize.Op.ne, 0), serverID: message.guild.id}}); + const bannedWords = await BannedWords.findAll({where: {word: Sequelize.where(Sequelize.fn('LOCATE', Sequelize.col('word'), message.content.replace(/\u200B/g, '').replace(/[\u0250-\ue007]/g, '')), Sequelize.Op.ne, 0), serverID: message.guild.id}}); if (bannedWords[0].get('word')) { + // Remove accent let censoredMessage = message.content.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, ''); // Remove zero width space character censoredMessage = censoredMessage.replace(/\u200B/g, ''); + // Remove non latin character + censoredMessage = censoredMessage.replace(/[\u0250-\ue007]/g, ''); + for (let i = 0; i < bannedWords.length; i++) { let regex = new RegExp(bannedWords[i].get('word'), 'g'); censoredMessage = censoredMessage.replace(regex, '█'.repeat(bannedWords[i].get('word').length));