Skip to content

Commit

Permalink
More robust badword filter
Browse files Browse the repository at this point in the history
  • Loading branch information
defnull committed Feb 10, 2024
1 parent 52c588e commit e4dbd34
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/sources.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit e4dbd34

Please sign in to comment.