ignore-channels: fnmatch patterns + silent before classifier gate (beh-09) — no emoji leak into ignored channels

This commit is contained in:
Oleksandr Kozachuk
2026-07-15 18:58:37 +02:00
parent da50395dc7
commit 7fa23068a4
3 changed files with 73 additions and 2 deletions
+12 -2
View File
@@ -1,5 +1,6 @@
import argparse
import asyncio
import fnmatch
import logging
import random
import re
@@ -481,7 +482,7 @@ class FjerkroaBot(commands.Bot):
return fallback_channel
if channel_name.startswith("#"):
channel_name = channel_name[1:]
if not no_ignore and channel_name in self.config.get("ignore-channels", []):
if not no_ignore and self.channel_ignored(channel_name):
return fallback_channel
for guild in self.guilds:
channel = discord.utils.get(guild.channels, name=channel_name)
@@ -494,8 +495,12 @@ class FjerkroaBot(commands.Bot):
return str(channel.recipient.name)
return str(channel.id) if isinstance(channel, DMChannel) else str(channel.name)
def channel_ignored(self, channel_name) -> bool:
"""fnmatch patterns; plain names match exactly as before (BEH-09)."""
return any(fnmatch.fnmatchcase(str(channel_name), pattern) for pattern in self.config.get("ignore-channels", []))
def ignore_message(self, channel_name, message):
return channel_name in self.config.get("ignore-channels", []) and not message.direct
return self.channel_ignored(channel_name) and not message.direct
def log_message_action(self, action, message, channel_name):
logging.info(f"{action} message {repr(message)} for channel {channel_name}")
@@ -521,6 +526,11 @@ class FjerkroaBot(commands.Bot):
async def handle_message_through_responder(self, message):
"""Handle a message through the AI responder"""
# Ignored channels are fully silent — before the classifier gate,
# so no emoji reaction leaks either (BEH-09). DMs are never ignored.
if not isinstance(message.channel, DMChannel) and self.channel_ignored(self.get_channel_name(message.channel)):
self.log_message_action("ignore", message, self.get_channel_name(message.channel))
return
message_content = str(message.content).strip()
if message.reference and message.reference.resolved and isinstance(message.reference.resolved.content, str):
reference_content = str(message.reference.resolved.content).replace("\n", "> \n")