aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Boris Muratov <[email protected]>2023-04-06 14:23:06 +0300
committerGravatar Boris Muratov <[email protected]>2023-04-06 14:23:06 +0300
commitc0f1eb07843c514bd68a9e07d920b822aee5a5fd (patch)
treeca670b9bdedaf86ece80ab11942adbaf8fa0443a
parentDon't notify the user for filters triggered in DMs. (diff)
Add in_guild attribute to FilterContext
-rw-r--r--bot/exts/filtering/_filter_context.py8
-rw-r--r--bot/exts/filtering/_settings_types/actions/infraction_and_notification.py2
-rw-r--r--bot/exts/filtering/_settings_types/validations/channel_scope.py2
3 files changed, 8 insertions, 4 deletions
diff --git a/bot/exts/filtering/_filter_context.py b/bot/exts/filtering/_filter_context.py
index 483706e2a..05cc23160 100644
--- a/bot/exts/filtering/_filter_context.py
+++ b/bot/exts/filtering/_filter_context.py
@@ -6,7 +6,7 @@ from dataclasses import dataclass, field, replace
from enum import Enum, auto
import discord
-from discord import DMChannel, Embed, Member, Message, TextChannel, Thread, User
+from discord import DMChannel, Embed, Member, Message, StageChannel, TextChannel, Thread, User, VoiceChannel
from bot.utils.message_cache import MessageCache
@@ -31,7 +31,7 @@ class FilterContext:
# Input context
event: Event # The type of event
author: User | Member | None # Who triggered the event
- channel: TextChannel | Thread | DMChannel | None # The channel involved
+ channel: TextChannel | VoiceChannel | StageChannel | Thread | DMChannel | None # The channel involved
content: str | Iterable # What actually needs filtering. The Iterable type depends on the filter list.
message: Message | None # The message involved
embeds: list[Embed] = field(default_factory=list) # Any embeds involved
@@ -57,6 +57,10 @@ class FilterContext:
uploaded_attachments: dict[int, list[str]] = field(default_factory=dict) # Message ID to attachment URLs.
upload_deletion_logs: bool = True # Whether it's allowed to upload deletion logs.
+ def __post_init__(self):
+ # If it were in the context of a DM there would be a channel.
+ self.in_guild = self.channel is None or self.channel.guild is not None
+
@classmethod
def from_message(
cls, event: Event, message: Message, before: Message | None = None, cache: MessageCache | None = None
diff --git a/bot/exts/filtering/_settings_types/actions/infraction_and_notification.py b/bot/exts/filtering/_settings_types/actions/infraction_and_notification.py
index 818ba3f23..508c09c2a 100644
--- a/bot/exts/filtering/_settings_types/actions/infraction_and_notification.py
+++ b/bot/exts/filtering/_settings_types/actions/infraction_and_notification.py
@@ -186,7 +186,7 @@ class InfractionAndNotification(ActionEntry):
async def action(self, ctx: FilterContext) -> None:
"""Send the notification to the user, and apply any specified infractions."""
- if hasattr(ctx.channel, "category"): # Don't DM the user for filters invoked in DMs.
+ if ctx.in_guild: # Don't DM the user for filters invoked in DMs.
await self.send_message(ctx)
if self.infraction_type != Infraction.NONE:
diff --git a/bot/exts/filtering/_settings_types/validations/channel_scope.py b/bot/exts/filtering/_settings_types/validations/channel_scope.py
index 737465137..45b769d29 100644
--- a/bot/exts/filtering/_settings_types/validations/channel_scope.py
+++ b/bot/exts/filtering/_settings_types/validations/channel_scope.py
@@ -55,7 +55,7 @@ class ChannelScope(ValidationEntry):
if not channel:
return True
- if not hasattr(channel, "category"): # This is not a guild channel, outside the scope of this setting.
+ if not ctx.in_guild: # This is not a guild channel, outside the scope of this setting.
return True
if hasattr(channel, "parent"):
channel = channel.parent