@@ -83,21 +83,38 @@ class AutoModAction:
83
83
timeout_duration: Optional[Union[:class:`int`, :class:`datetime.timedelta`]]
84
84
Duration in seconds (:class:`int`) or a timerange (:class:`~datetime.timedelta`) for wich the user should be timeouted.
85
85
86
- **The maximum value is ``2419200`` seconds (4 weeks)**
86
+ **The maximum value is** ``2419200`` ** seconds (4 weeks)**
87
87
88
88
.. note::
89
89
This field is only required if :attr:`type` is :attr:`AutoModActionType.timeout_user`
90
-
90
+
91
+ custom_message: Optional[:class:`str`]
92
+ Additional explanation that will be shown to members whenever their message is blocked. **Max 150 characters**
93
+
94
+ .. note::
95
+ This field is only allowed if :attr:`type` is :attr:`AutoModActionType.block_message`
91
96
"""
92
97
def __init__ (self , type : AutoModActionType , ** metadata ):
93
98
self .type : AutoModActionType = try_enum (AutoModActionType , type )
94
99
self .metadata = metadata # maybe we need this later... idk
100
+
95
101
action_type = self .type # speedup attribute access
96
- if action_type .send_alert_message :
102
+
103
+ if action_type .block_message :
104
+ try :
105
+ self .custom_message : Optional [str ] = metadata ['custom_message' ]
106
+ except KeyError :
107
+ pass
108
+ else :
109
+ if len (self .custom_message ) > 150 :
110
+ raise ValueError ('The maximum length of the custom message is 150 characters.' )
111
+
112
+ elif action_type .send_alert_message :
97
113
try :
98
114
self .channel_id : Optional [int ] = metadata ['channel_id' ]
99
115
except KeyError :
100
116
raise TypeError ('If the type is send_alert_message you must specify a channel_id' )
117
+
101
118
elif action_type .timeout_user :
102
119
try :
103
120
timeout_duration : Optional [Union [int , datetime .timedelta ]] = metadata ['timeout_duration' ]
@@ -115,6 +132,10 @@ def to_dict(self) -> Dict[str, Any]:
115
132
'type' : int (self .type )
116
133
}
117
134
metadata = {}
135
+ if self .type .block_message :
136
+ custom_message = getattr (self , 'custom_message' , None )
137
+ if custom_message :
138
+ metadata ['custom_message' ] = self .custom_message
118
139
if self .type .send_alert_message :
119
140
metadata ['channel_id' ] = self .channel_id
120
141
elif self .type .timeout_user :
@@ -126,7 +147,9 @@ def to_dict(self) -> Dict[str, Any]:
126
147
def from_dict (cls , data : Dict [str , Any ]) -> Self :
127
148
action_type = try_enum (AutoModActionType , data ['type' ])
128
149
metadata = data ['metadata' ]
129
- if action_type .timeout_user :
150
+ if action_type .block_message :
151
+ metadata ['custom_message' ] = metadata .pop ('custom_message' , None )
152
+ elif action_type .timeout_user :
130
153
metadata ['timeout_duration' ] = metadata .pop ('duration_seconds' )
131
154
elif action_type .send_alert_message :
132
155
metadata ['channel_id' ] = int (metadata ['channel_id' ])
0 commit comments