mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +00:00
return actual muted word from check-word-mute.ts
This commit is contained in:
parent
00cfeca3d7
commit
7cd1d9ad93
1 changed files with 20 additions and 13 deletions
|
@ -13,30 +13,37 @@ export function checkWordMute(note: string | Misskey.entities.Note, me: Misskey.
|
||||||
|
|
||||||
if (text === '') return false;
|
if (text === '') return false;
|
||||||
|
|
||||||
const matched = mutedWords.filter(filter => {
|
const matched = mutedWords.reduce((matchedWords, filter) => {
|
||||||
if (Array.isArray(filter)) {
|
if (Array.isArray(filter)) {
|
||||||
// Clean up
|
// Clean up
|
||||||
const filteredFilter = filter.filter(keyword => keyword !== '');
|
const filteredFilter = filter.filter(keyword => keyword !== '');
|
||||||
if (filteredFilter.length === 0) return false;
|
if (filteredFilter.length > 0 && filteredFilter.every(keyword => text.includes(keyword))) {
|
||||||
|
const fullFilter = filteredFilter.join(' ');
|
||||||
return filteredFilter.every(keyword => text.includes(keyword));
|
matchedWords.add(fullFilter);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// represents RegExp
|
// represents RegExp
|
||||||
const regexp = filter.match(/^\/(.+)\/(.*)$/);
|
const regexp = filter.match(/^\/(.+)\/(.*)$/);
|
||||||
|
|
||||||
// This should never happen due to input sanitisation.
|
// This should never happen due to input sanitisation.
|
||||||
if (!regexp) return false;
|
if (regexp) {
|
||||||
|
try {
|
||||||
try {
|
const flags = regexp[2].includes('g') ? regexp[2] : (regexp[2] + 'g');
|
||||||
return new RegExp(regexp[1], regexp[2]).test(text);
|
const matches = text.matchAll(new RegExp(regexp[1], flags));
|
||||||
} catch (err) {
|
for (const match of matches) {
|
||||||
// This should never happen due to input sanitisation.
|
matchedWords.add(match[0]);
|
||||||
return false;
|
}
|
||||||
|
} catch {
|
||||||
|
// This should never happen due to input sanitisation.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (matched.length > 0) return matched;
|
return matchedWords;
|
||||||
|
}, new Set<string>());
|
||||||
|
|
||||||
|
// Nested arrays are intentional, otherwise the note components will join with space (" ") and it's confusing.
|
||||||
|
if (matched.size > 0) return [[Array.from(matched).join(', ')]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue