From e4dbd34639512dbd5e4aea521bdecf4c503ea00e Mon Sep 17 00:00:00 2001 From: Marcel Hellkamp Date: Sat, 10 Feb 2024 14:10:47 +0100 Subject: [PATCH] More robust badword filter --- src/sources.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sources.ts b/src/sources.ts index 868ca61..c2c9061 100644 --- a/src/sources.ts +++ b/src/sources.ts @@ -1,6 +1,7 @@ import type { Config, MastodonAccount, MastodonStatus, Post, PostMedia } from "@/types"; import { regexEscape } from "@/utils"; import { replaceInText } from '@/utils' +import type { faTags } from "@fortawesome/free-solid-svg-icons"; import DOMPurify from 'dompurify' /** @@ -199,12 +200,12 @@ const filterStatus = (cfg: Config, status: MastodonStatus) => { if (cfg.hideBots && status.account?.bot) return false; if (cfg.badWords.length) { const pattern = new RegExp(`\\b(${cfg.badWords.map(regexEscape).join("|")})\\b`, 'i'); - if (status.tags?.find((tag: any) => cfg.badWords.includes(tag.name)) - || status.account.display_name.match(pattern) - || status.account.acct.match(pattern) + if (status.account?.display_name?.match(pattern) + || status.account?.acct?.match(pattern) || status.content.match(pattern) || status.spoiler_text?.match(pattern) - || status.media_attachments?.find(media => media.description?.match(pattern))) + || status.tags?.some(tag => tag.name?.match(pattern)) + || status.media_attachments?.some(media => media.description?.match(pattern))) return false; }