forked from Galactic/galactic-bot
Improved remove markdown utility
This commit is contained in:
parent
d9476e43b7
commit
07a4fe0a11
@ -47,6 +47,7 @@
|
||||
"nightbird",
|
||||
"slurs",
|
||||
"an alt",
|
||||
"nyquil",
|
||||
"lol!",
|
||||
"coco",
|
||||
"slur",
|
||||
|
@ -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}`;
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user