Apply bad word filter also to account and display names

This commit is contained in:
Marcel Hellkamp 2024-02-10 14:02:59 +01:00
parent aaa4f8d4ae
commit 52c588e834

View File

@ -94,8 +94,8 @@ export async function fetchPosts(cfg: Config): Promise<Post[]> {
for (const task of tasks) { for (const task of tasks) {
try { try {
(await task()) (await task())
.filter(status => filterStatus(cfg, status))
.map(status => fixLocalAcct(domain, status)) .map(status => fixLocalAcct(domain, status))
.filter(status => filterStatus(cfg, status))
.map(status => statusToWallPost(cfg, status)) .map(status => statusToWallPost(cfg, status))
.forEach(addOrRepacePost) .forEach(addOrRepacePost)
} catch (err) { } catch (err) {
@ -200,6 +200,8 @@ const filterStatus = (cfg: Config, status: MastodonStatus) => {
if (cfg.badWords.length) { if (cfg.badWords.length) {
const pattern = new RegExp(`\\b(${cfg.badWords.map(regexEscape).join("|")})\\b`, 'i'); const pattern = new RegExp(`\\b(${cfg.badWords.map(regexEscape).join("|")})\\b`, 'i');
if (status.tags?.find((tag: any) => cfg.badWords.includes(tag.name)) if (status.tags?.find((tag: any) => cfg.badWords.includes(tag.name))
|| status.account.display_name.match(pattern)
|| status.account.acct.match(pattern)
|| status.content.match(pattern) || status.content.match(pattern)
|| status.spoiler_text?.match(pattern) || status.spoiler_text?.match(pattern)
|| status.media_attachments?.find(media => media.description?.match(pattern))) || status.media_attachments?.find(media => media.description?.match(pattern)))