39
39
from .mixins import Hashable
40
40
from .object import Object
41
41
42
- __all__ = ("AutoModRule" ,)
42
+ __all__ = (
43
+ "AutoModRule" ,
44
+ "AutoModAction" ,
45
+ "AutoModActionMetadata" ,
46
+ "AutoModTriggerMetadata" ,
47
+ )
43
48
44
49
if TYPE_CHECKING :
45
50
from .abc import Snowflake
@@ -152,7 +157,7 @@ def __init__(self, action_type: AutoModActionType, metadata: AutoModActionMetada
152
157
def to_dict (self ) -> dict :
153
158
return {
154
159
"type" : self .type .value ,
155
- "metadata" : self .metadata ,
160
+ "metadata" : self .metadata . to_dict () ,
156
161
}
157
162
158
163
@classmethod
@@ -167,45 +172,95 @@ def __repr__(self) -> str:
167
172
168
173
169
174
class AutoModTriggerMetadata :
170
- """Represents a rule's trigger metadata.
171
-
172
- Depending on the trigger type, different attributes will be used.
175
+ r"""Represents a rule's trigger metadata, defining additional data used to determine when a rule triggers.
176
+
177
+ Depending on the trigger type, different metadata attributes will be used:
178
+
179
+ +-----------------------------+--------------------------------------------------------------------------------+
180
+ | Attribute | Trigger Types |
181
+ +=============================+================================================================================+
182
+ | :attr:`keyword_filter` | :attr:`AutoModTriggerType.keyword` |
183
+ +-----------------------------+--------------------------------------------------------------------------------+
184
+ | :attr:`regex_patterns` | :attr:`AutoModTriggerType.keyword` |
185
+ +-----------------------------+--------------------------------------------------------------------------------+
186
+ | :attr:`presets` | :attr:`AutoModTriggerType.keyword_preset` |
187
+ +-----------------------------+--------------------------------------------------------------------------------+
188
+ | :attr:`allow_list` | :attr:`AutoModTriggerType.keyword`\, :attr:`AutoModTriggerType.keyword_preset` |
189
+ +-----------------------------+--------------------------------------------------------------------------------+
190
+ | :attr:`mention_total_limit` | :attr:`AutoModTriggerType.mention_spam` |
191
+ +-----------------------------+--------------------------------------------------------------------------------+
192
+
193
+ Each attribute has limits that may change based on the trigger type.
194
+ See `here <https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata-field-limits>`_
195
+ for information on attribute limits.
173
196
174
197
.. versionadded:: 2.0
175
198
176
199
Attributes
177
200
----------
178
201
keyword_filter: List[:class:`str`]
179
- A list of substrings to filter. Only for triggers of type :attr:`AutoModTriggerType.keyword`.
202
+ A list of substrings to filter.
203
+
204
+ regex_patterns: List[:class:`str`]
205
+ A list of regex patterns to filter using Rust-flavored regex, which is not
206
+ fully compatible with regex syntax supported by the builtin `re` module.
207
+
208
+ .. versionadded:: 2.4
209
+
180
210
presets: List[:class:`AutoModKeywordPresetType`]
181
- A list of keyword presets to filter. Only for triggers of type :attr:`AutoModTriggerType.keyword_preset`.
182
- """
211
+ A list of preset keyword sets to filter.
183
212
184
- # maybe add a table of action types and attributes?
185
- # wording for presets could change
213
+ allow_list: List[:class:`str`]
214
+ A list of substrings to allow, overriding keyword and regex matches.
215
+
216
+ .. versionadded:: 2.4
217
+
218
+ mention_total_limit: :class:`int`
219
+ The total number of unique role and user mentions allowed.
220
+
221
+ .. versionadded:: 2.4
222
+ """
186
223
187
224
__slots__ = (
188
225
"keyword_filter" ,
226
+ "regex_patterns" ,
189
227
"presets" ,
228
+ "allow_list" ,
229
+ "mention_total_limit" ,
190
230
)
191
231
192
232
def __init__ (
193
233
self ,
194
234
keyword_filter : list [str ] = MISSING ,
235
+ regex_patterns : list [str ] = MISSING ,
195
236
presets : list [AutoModKeywordPresetType ] = MISSING ,
237
+ allow_list : list [str ] = MISSING ,
238
+ mention_total_limit : int = MISSING ,
196
239
):
197
240
self .keyword_filter = keyword_filter
241
+ self .regex_patterns = regex_patterns
198
242
self .presets = presets
243
+ self .allow_list = allow_list
244
+ self .mention_total_limit = mention_total_limit
199
245
200
246
def to_dict (self ) -> dict :
201
247
data = {}
202
248
203
249
if self .keyword_filter is not MISSING :
204
250
data ["keyword_filter" ] = self .keyword_filter
205
251
252
+ if self .regex_patterns is not MISSING :
253
+ data ["regex_patterns" ] = self .regex_patterns
254
+
206
255
if self .presets is not MISSING :
207
256
data ["presets" ] = [wordset .value for wordset in self .presets ]
208
257
258
+ if self .allow_list is not MISSING :
259
+ data ["allow_list" ] = self .allow_list
260
+
261
+ if self .mention_total_limit is not MISSING :
262
+ data ["mention_total_limit" ] = self .mention_total_limit
263
+
209
264
return data
210
265
211
266
@classmethod
@@ -215,17 +270,29 @@ def from_dict(cls, data: AutoModTriggerMetadataPayload):
215
270
if (keyword_filter := data .get ("keyword_filter" )) is not None :
216
271
kwargs ["keyword_filter" ] = keyword_filter
217
272
273
+ if (regex_patterns := data .get ("regex_patterns" )) is not None :
274
+ kwargs ["regex_patterns" ] = regex_patterns
275
+
218
276
if (presets := data .get ("presets" )) is not None :
219
277
kwargs ["presets" ] = [
220
278
try_enum (AutoModKeywordPresetType , wordset ) for wordset in presets
221
279
]
222
280
281
+ if (allow_list := data .get ("allow_list" )) is not None :
282
+ kwargs ["allow_list" ] = allow_list
283
+
284
+ if (mention_total_limit := data .get ("mention_total_limit" )) is not None :
285
+ kwargs ["mention_total_limit" ] = mention_total_limit
286
+
223
287
return cls (** kwargs )
224
288
225
289
def __repr__ (self ) -> str :
226
290
repr_attrs = (
227
291
"keyword_filter" ,
292
+ "regex_patterns" ,
228
293
"presets" ,
294
+ "allow_list" ,
295
+ "mention_total_limit" ,
229
296
)
230
297
inner = []
231
298
@@ -424,9 +491,9 @@ async def edit(
424
491
The new actions to perform when the rule is triggered.
425
492
enabled: :class:`bool`
426
493
Whether this rule is enabled.
427
- exempt_roles: List[:class:`Snowflake`]
494
+ exempt_roles: List[:class:`abc. Snowflake`]
428
495
The roles that will be exempt from this rule.
429
- exempt_channels: List[:class:`Snowflake`]
496
+ exempt_channels: List[:class:`abc. Snowflake`]
430
497
The channels that will be exempt from this rule.
431
498
reason: Optional[:class:`str`]
432
499
The reason for editing this rule. Shows up in the audit log.
0 commit comments