From 07a4fe0a11796a16775b4e637e001af5f781b0f5 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sun, 8 May 2022 14:35:04 +0300 Subject: [PATCH] Improved remove markdown utility --- src/constants/FilterPresets.json | 1 + src/utilities/FilterUtil.js | 2 +- src/utilities/Util.js | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/constants/FilterPresets.json b/src/constants/FilterPresets.json index 6fb31ec..8bc35be 100644 --- a/src/constants/FilterPresets.json +++ b/src/constants/FilterPresets.json @@ -47,6 +47,7 @@ "nightbird", "slurs", "an alt", + "nyquil", "lol!", "coco", "slur", diff --git a/src/utilities/FilterUtil.js b/src/utilities/FilterUtil.js index 6e9ec4b..39e0ae4 100644 --- a/src/utilities/FilterUtil.js +++ b/src/utilities/FilterUtil.js @@ -281,7 +281,7 @@ module.exports = class FilterUtility { const diff = Math.abs(fullWord.length - match[0].length); if (diff > 3) { - this.logger.debug(`Match length diff: ${diff} MATCH: ${match[0]} FULL: ${fullWord}`); + this.logger.debug(`Match length diff: ${diff} MATCH: ${match[0]} FULL: ${fullWord}, CONTENT: ${content}`); continue; } // log += `\nMessage matched with "${reg}" in the regex list.\nMatch: ${match[0]}, Full word: ${fullWord}\nFull content: ${content}`; diff --git a/src/utilities/Util.js b/src/utilities/Util.js index 2a8ea00..a463bfb 100644 --- a/src/utilities/Util.js +++ b/src/utilities/Util.js @@ -123,6 +123,7 @@ class Util { */ static get formattingPatterns() { return [ + ['\\|{2}(.*)\\|{2}', '$1'], ['\\*{1,3}([^*]*)\\*{1,3}', '$1'], ['_{1,3}([^_]*)_{1,3}', '$1'], ['`{1,3}([^`]*)`{1,3}', '$1'], @@ -139,7 +140,8 @@ class Util { static removeMarkdown(content) { if (!content) throw new Error('Missing content'); this.formattingPatterns.forEach(([pattern, replacer]) => { - content = content.replace(new RegExp(pattern, 'gu'), replacer); + const reg = new RegExp(pattern, 'gu'); + while(reg.test(content)) content = content.replace(reg, replacer); }); return content.trim(); }