mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-26 03:47:40 -07:00
Use original (Misskey's) implementation for hard mutes as muted reason isn't needed
This commit is contained in:
parent
7b58910de8
commit
ecc0dd9a9b
1 changed files with 15 additions and 24 deletions
|
@ -25,39 +25,30 @@ function checkWordMute(
|
|||
const text = ((note.cw ?? "") + " " + (note.text ?? "")).trim();
|
||||
if (text === "") return false;
|
||||
|
||||
for (const mutePattern of mutedWords) {
|
||||
let mute: RE2;
|
||||
let matched: string[];
|
||||
if (Array.isArray(mutePattern)) {
|
||||
matched = mutePattern.filter((keyword) => keyword !== "");
|
||||
|
||||
if (matched.length === 0) {
|
||||
continue;
|
||||
}
|
||||
mute = new RE2(
|
||||
`\\b${matched.map(escapeRegExp).join("\\b.*\\b")}\\b`,
|
||||
"g",
|
||||
);
|
||||
const matched = mutedWords.some(filter => {
|
||||
if (Array.isArray(filter)) {
|
||||
return filter.every(keyword => text.includes(keyword));
|
||||
} else {
|
||||
const regexp = mutePattern.match(/^\/(.+)\/(.*)$/);
|
||||
// represents RegExp
|
||||
const regexp = filter.match(/^\/(.+)\/(.*)$/);
|
||||
|
||||
// This should never happen due to input sanitisation.
|
||||
if (!regexp) {
|
||||
console.warn(`Found invalid regex in word mutes: ${mutePattern}`);
|
||||
continue;
|
||||
}
|
||||
mute = new RE2(regexp[1], regexp[2]);
|
||||
matched = [mutePattern];
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (mute.test(text)) return true;
|
||||
return new RE2(regexp[1], regexp[2]).test(text);
|
||||
} catch (err) {
|
||||
// This should never happen due to input sanitisation.
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return matched;
|
||||
}
|
||||
|
||||
export async function getWordHardMute(
|
||||
note: NoteLike,
|
||||
|
|
Loading…
Reference in a new issue