aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/exts/filtering/_filter_lists/antispam.py2
-rw-r--r--bot/exts/filtering/filtering.py20
2 files changed, 20 insertions, 2 deletions
diff --git a/bot/exts/filtering/_filter_lists/antispam.py b/bot/exts/filtering/_filter_lists/antispam.py
index cf5875723..41eda9878 100644
--- a/bot/exts/filtering/_filter_lists/antispam.py
+++ b/bot/exts/filtering/_filter_lists/antispam.py
@@ -59,7 +59,7 @@ class AntispamList(UniquesListBase):
self, ctx: FilterContext
) -> tuple[ActionSettings | None, list[str], dict[ListType, list[Filter]]]:
"""Dispatch the given event to the list's filters, and return actions to take and messages to relay to mods."""
- if not ctx.message:
+ if not ctx.message or not ctx.message_cache:
return None, [], {}
sublist: SubscribingAtomicList = self[ListType.DENY]
diff --git a/bot/exts/filtering/filtering.py b/bot/exts/filtering/filtering.py
index 65089a6d5..81348ca1e 100644
--- a/bot/exts/filtering/filtering.py
+++ b/bot/exts/filtering/filtering.py
@@ -196,7 +196,7 @@ class Filtering(Cog):
return await has_any_role(*MODERATION_ROLES).predicate(ctx)
# endregion
- # region: listeners
+ # region: listeners and event handlers
@Cog.listener()
async def on_message(self, msg: Message) -> None:
@@ -247,6 +247,24 @@ class Filtering(Cog):
ctx = FilterContext(Event.NICKNAME, member, None, member.display_name, None)
await self._check_bad_name(ctx)
+ async def filter_snekbox_output(self, snekbox_result: str, msg: Message) -> bool:
+ """
+ Filter the result of a snekbox command to see if it violates any of our rules, and then respond accordingly.
+
+ Also requires the original message, to check whether to filter and for alerting.
+ Any action (deletion, infraction) will be applied in the context of the original message.
+
+ Returns whether a filter was triggered or not.
+ """
+ ctx = FilterContext.from_message(Event.MESSAGE, msg).replace(content=snekbox_result)
+ result_actions, list_messages, triggers = await self._resolve_action(ctx)
+ if result_actions:
+ await result_actions.action(ctx)
+ if ctx.send_alert:
+ await self._send_alert(ctx, list_messages)
+
+ return result_actions is not None
+
# endregion
# region: blacklist commands