aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Steele Farnsworth <[email protected]>2025-01-19 12:17:51 -0500
committerGravatar Steele Farnsworth <[email protected]>2025-01-19 12:17:51 -0500
commitea62c748234fc722756faefb9884976f1af2112b (patch)
tree57d18bc58059cca07c218cdddec57b2ed9b7b222
parentMigrate to py3.12 typing syntax. (diff)
Apply token filters to text attachment content.
Works by appending text attachment content to message content, and then applying the filters normally.
-rw-r--r--bot/exts/filtering/filtering.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/bot/exts/filtering/filtering.py b/bot/exts/filtering/filtering.py
index 929eb064c..a281aff79 100644
--- a/bot/exts/filtering/filtering.py
+++ b/bot/exts/filtering/filtering.py
@@ -81,7 +81,7 @@ class Filtering(Cog):
def __init__(self, bot: Bot):
self.bot = bot
self.filter_lists: dict[str, FilterList] = {}
- self._subscriptions: defaultdict[Event, list[FilterList]] = defaultdict(list)
+ self._subscriptions = defaultdict[Event, list[FilterList]](list)
self.delete_scheduler = scheduling.Scheduler(self.__class__.__name__)
self.webhook: discord.Webhook | None = None
@@ -224,6 +224,15 @@ class Filtering(Cog):
self.message_cache.append(msg)
ctx = FilterContext.from_message(Event.MESSAGE, msg, None, self.message_cache)
+
+ text_contents = [
+ f"{a.filename}: " + (await a.read()).decode()
+ for a in msg.attachments if a.content_type.startswith("text")
+ ]
+ if text_contents:
+ attachment_content = "\n\n".join(text_contents)
+ ctx = ctx.replace(content=f"{ctx.content}\n\n{attachment_content}")
+
result_actions, list_messages, triggers = await self._resolve_action(ctx)
self.message_cache.update(msg, metadata=triggers)
if result_actions: