Fix regex hard mutes
This commit is contained in:
parent
9bb79161af
commit
59a53d8f64
1 changed files with 16 additions and 10 deletions
|
@ -21,29 +21,35 @@ function checkWordMute(
|
||||||
const text = ((note.cw ?? "") + " " + (note.text ?? "")).trim();
|
const text = ((note.cw ?? "") + " " + (note.text ?? "")).trim();
|
||||||
if (text === "") return false;
|
if (text === "") return false;
|
||||||
|
|
||||||
const matched = mutedWords.some((filter) => {
|
for (const mutePattern of mutedWords) {
|
||||||
if (Array.isArray(filter)) {
|
if (Array.isArray(mutePattern)) {
|
||||||
return filter.every((keyword) => text.includes(keyword));
|
// Clean up
|
||||||
|
const keywords = mutePattern.filter((keyword) => keyword !== "");
|
||||||
|
|
||||||
|
if (
|
||||||
|
keywords.length > 0 &&
|
||||||
|
keywords.every((keyword) => text.includes(keyword))
|
||||||
|
)
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// represents RegExp
|
// represents RegExp
|
||||||
const regexp = filter.match(/^\/(.+)\/(.*)$/);
|
const regexp = mutePattern.match(/^\/(.+)\/(.*)$/);
|
||||||
|
|
||||||
// This should never happen due to input sanitisation.
|
// This should never happen due to input sanitisation.
|
||||||
if (!regexp) {
|
if (!regexp) {
|
||||||
console.warn(`Found invalid regex in word mutes: ${filter}`);
|
console.warn(`Found invalid regex in word mutes: ${mutePattern}`);
|
||||||
return false;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new RE2(regexp[1], regexp[2]).test(text);
|
if (new RegExp(regexp[1], regexp[2]).test(text)) return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// This should never happen due to input sanitisation.
|
// This should never happen due to input sanitisation.
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return matched;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getWordHardMute(
|
export async function getWordHardMute(
|
||||||
|
|
Loading…
Reference in a new issue