Skip to content

feat: Add custom_message to AutoModActionMetadata and fix TypeError on AutoModRule #2029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion discord/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,29 @@ 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?

__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 = {}
Expand All @@ -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
Expand All @@ -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 = []

Expand Down Expand Up @@ -352,6 +368,7 @@ class AutoModRule(Hashable):
"""

__slots__ = (
"__dict__",
"_state",
"id",
"guild_id",
Expand Down
1 change: 1 addition & 0 deletions discord/types/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down