From 8c531608122dc4f061789b10c20997b74ddf2154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Prie=C3=9Fnitz?= Date: Thu, 4 Dec 2025 21:47:36 +0100 Subject: [PATCH] [deploy] Automod Filter greifen wieder (Links/Badwords) --- src/services/automodService.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/services/automodService.ts b/src/services/automodService.ts index 36e9911..9aa2879 100644 --- a/src/services/automodService.ts +++ b/src/services/automodService.ts @@ -1,4 +1,4 @@ -import { Collection, Message, PermissionFlagsBits } from 'discord.js'; +import { Collection, Message } from 'discord.js'; import { logger } from '../utils/logger'; import { GuildSettings } from '../config/state'; import { LoggingService } from './loggingService'; @@ -54,7 +54,6 @@ export class AutoModService { } if (this.linkFilterEnabled && config.deleteLinks !== false && this.containsLink(message.content, config.linkWhitelist)) { - if (message.member?.permissions.has(PermissionFlagsBits.ManageGuild)) return false; await this.deleteMessageWithReason(message, `${message.author}, Links sind hier nicht erlaubt.`); const reason = `Link gefunden (nicht freigegeben)${config.linkWhitelist?.length ? ` | Whitelist: ${config.linkWhitelist.join(', ')}` : ''}`; logger.info(`Deleted link from ${message.author.tag}`); @@ -63,7 +62,6 @@ export class AutoModService { } if (config.badWordFilter !== false && this.containsBadword(message.content, config.customBadwords)) { - if (message.member?.permissions.has(PermissionFlagsBits.ManageGuild)) return false; await this.deleteMessageWithReason(message, `${message.author}, bitte auf deine Wortwahl achten.`); await this.logAutomodAction(message, config, 'badword', 'Badword erkannt', message.content); return true; @@ -107,15 +105,23 @@ export class AutoModService { } private containsBadword(content: string, custom: string[] = []) { - const combined = [...this.defaultBadwords, ...(custom || [])].filter(Boolean).map((w) => w.toLowerCase()); + const combined = [...this.defaultBadwords, ...(custom || [])] + .map((w) => w?.toString().trim().toLowerCase()) + .filter(Boolean); if (!combined.length) return false; const lower = content.toLowerCase(); - return combined.some((w) => lower.includes(w)); + return combined.some((w) => { + // Try to match word boundaries first, fall back to substring to remain permissive + const escaped = w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + const regex = new RegExp(`\\b${escaped}\\b`, 'i'); + return regex.test(lower) || lower.includes(w); + }); } private containsLink(content: string, whitelist: string[] = []) { const normalized = whitelist.map((w) => w.toLowerCase()).filter(Boolean); - const match = /(https?:\/\/[^\s]+|discord\.gg\/[^\s]+|www\.[^\s]+)/i.exec(content); + // Match common link formats, even without protocol + const match = /(https?:\/\/[^\s]+|discord\.gg\/[^\s]+|www\.[^\s]+|[a-z0-9.-]+\.[a-z]{2,}\/?[^\s]*)/i.exec(content); if (!match) return false; const url = match[0].toLowerCase(); return !normalized.some((w) => url.includes(w));