add functionality to remove discord formatting
This commit is contained in:
parent
4620816cd0
commit
99e5cde911
@ -99,7 +99,7 @@ module.exports = class AutoModeration extends Observer {
|
||||
const msg = edited || message;
|
||||
let log = `Message filter debug:`;
|
||||
log += `\nPre norm: ${msg.cleanContent}`;
|
||||
const content = FilterUtil.normalise(msg.cleanContent);
|
||||
const content = FilterUtil.normalise(FilterUtil.removeDiscordFormatting(msg.cleanContent));
|
||||
log += `\nNormalised: ${content}`;
|
||||
|
||||
// match: what was matched |
|
||||
|
@ -176,6 +176,23 @@ module.exports = class FilterUtility {
|
||||
};
|
||||
}
|
||||
|
||||
static get formattingPatterns() {
|
||||
return [
|
||||
['\\*{1,3}([^*]*)\\*{1,3}', '$1'],
|
||||
['_{1,3}([^_]*)_{1,3}', '$1'],
|
||||
['`{1,3}([^`]*)`{1,3}', '$1'],
|
||||
['~~([^~])~~', '$1']
|
||||
];
|
||||
}
|
||||
|
||||
static removeDiscordFormatting(content) {
|
||||
if (!content) throw new Error('Missing content');
|
||||
this.formattingPatterns.forEach(([pattern, replacer]) => {
|
||||
content = content.replace(new RegExp(pattern, 'gu'), replacer);
|
||||
});
|
||||
return content;
|
||||
}
|
||||
|
||||
static normalise(content) {
|
||||
|
||||
if (typeof content !== 'string') throw new Error('Invalid input type, must be of type string');
|
||||
|
Loading…
Reference in New Issue
Block a user