From a8ce1257ab72905f994647943f001cd0476695cd Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Tue, 25 Apr 2023 15:39:55 +0100 Subject: [PATCH] feat: Add custom_message to AutoModActionMetadata and fix TypeError on AutoModRule (#2029) * Automod fixes and additions * style(pre-commit): auto fixes from pre-commit.com hooks --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- discord/automod.py | 19 ++++++++++++++++++- discord/types/automod.py | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/discord/automod.py b/discord/automod.py index 5f091d0f65..2d6b5244da 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -76,6 +76,10 @@ class AutoModActionMetadata: timeout_duration: :class:`datetime.timedelta` How long the member that triggered the action should be timed out for. Only for actions of type :attr:`AutoModActionType.timeout`. + custom_message: :class:`str` + An additional message shown to members when their message is blocked. + Maximum 150 characters. + Only for actions of type :attr:`AutoModActionType.block_message`. """ # maybe add a table of action types and attributes? @@ -83,13 +87,18 @@ class AutoModActionMetadata: __slots__ = ( "channel_id", "timeout_duration", + "custom_message", ) def __init__( - self, channel_id: int = MISSING, timeout_duration: timedelta = MISSING + self, + channel_id: int = MISSING, + timeout_duration: timedelta = MISSING, + custom_message: str = MISSING, ): self.channel_id: int = channel_id self.timeout_duration: timedelta = timeout_duration + self.custom_message: str = custom_message def to_dict(self) -> dict: data = {} @@ -100,6 +109,9 @@ def to_dict(self) -> dict: if self.timeout_duration is not MISSING: data["duration_seconds"] = self.timeout_duration.total_seconds() + if self.custom_message is not MISSING: + data["custom_message"] = self.custom_message + return data @classmethod @@ -113,12 +125,16 @@ def from_dict(cls, data: AutoModActionMetadataPayload): # might need an explicit int cast kwargs["timeout_duration"] = timedelta(seconds=duration_seconds) + if (custom_message := data.get("custom_message")) is not None: + kwargs["custom_message"] = custom_message + return cls(**kwargs) def __repr__(self) -> str: repr_attrs = ( "channel_id", "timeout_duration", + "custom_message", ) inner = [] @@ -352,6 +368,7 @@ class AutoModRule(Hashable): """ __slots__ = ( + "__dict__", "_state", "id", "guild_id", diff --git a/discord/types/automod.py b/discord/types/automod.py index 4632c8d8c4..4f13b46ae0 100644 --- a/discord/types/automod.py +++ b/discord/types/automod.py @@ -47,6 +47,7 @@ class AutoModTriggerMetadata(TypedDict, total=False): class AutoModActionMetadata(TypedDict, total=False): channel_id: Snowflake duration_seconds: int + custom_message: str class AutoModAction(TypedDict):