Skip to content

Commit afa4440

Browse files
committed
feat(implement:AutoMod): Added exempt_list (allow_list) fields to AutoModTriggerMetadata
1 parent 2914d5d commit afa4440

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

discord/automod.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,16 @@ class AutoModTriggerMetadata:
147147
148148
.. note::
149149
This field is only present if :attr:`~AutoModRule.trigger_type` is :attr:`AutoModTriggerType.keyword_preset`
150+
exempt_words: Optional[List[str]]
151+
Substrings which should be excluded from the blacklist.
150152
153+
.. note::
154+
This field is only present if :attr:`~AutoModRule.trigger_type` is :attr:`AutoModTriggerType.keyword_preset`
151155
"""
152156
def __init__(self,
153157
keyword_filter: Optional[List[str]] = None,
154-
presets: Optional[List[AutoModKeywordPresetType]] = None) -> None:
158+
presets: Optional[List[AutoModKeywordPresetType]] = None,
159+
exempt_words: Optional[List[str]] = None) -> None:
155160
"""Additional data used to determine whether a rule should be triggered.
156161
Different fields are relevant based on the value of :attr:`AutoModRule.trigger_type`
157162
@@ -161,13 +166,19 @@ def __init__(self,
161166
Substrings which will be searched for in content
162167
163168
.. note::
164-
This field is only required if :attr:`~AutoModRule.trigger_type` is :attr:`AutoModTriggerType.keyword`
169+
This field is only required if :attr:`~AutoModRule.trigger_type` is :attr:`~AutoModTriggerType.keyword`
165170
166171
presets: Optional[List[:class:`AutoModKeywordPresetType`]]
167172
The internally pre-defined wordsets which will be searched for in content
168173
169174
.. note::
170-
This field is only required if :attr:`~AutoModRule.trigger_type` is :attr:`AutoModTriggerType.keyword_preset`
175+
This field is only required if :attr:`~AutoModRule.trigger_type` is :attr:`~AutoModTriggerType.keyword_preset`
176+
177+
exempt_words: Optional[List[str]]
178+
Substrings which should be excluded from the blacklist.
179+
180+
.. note::
181+
This field is only present if :attr:`~AutoModRule.trigger_type` is :attr:`~AutoModTriggerType.keyword_preset`
171182
172183
Raises
173184
-------
@@ -178,6 +189,9 @@ def __init__(self,
178189
raise TypeError('Only one of keyword_filter or presets are accepted.')
179190
self.keyword_filter: Optional[List[str]] = keyword_filter or []
180191
self.presets: Optional[List[AutoModKeywordPresetType]] = presets or []
192+
if exempt_words and not presets:
193+
raise TypeError('exempt_words can only be used with presets')
194+
self.exempt_words: Optional[List[str]] = exempt_words
181195

182196
@property
183197
def prefix_keywords(self) -> Iterator[str]:
@@ -275,14 +289,18 @@ def to_dict(self) -> Dict[str, Any]:
275289
if self.keyword_filter:
276290
return {'keyword_filter': self.keyword_filter}
277291
else:
278-
return {'presets': [int(p) for p in self.presets]}
292+
base = {'presets': [int(p) for p in self.presets]}
293+
if self.exempt_words:
294+
base['allow_list'] = self.exempt_words
295+
return base
279296

280297
@classmethod
281298
def from_dict(cls, data: Dict[str, Any]) -> AutoModTriggerMetadata:
282299
self = cls.__new__(cls)
283300
presets = data.get('presets', None)
284301
if presets:
285302
self.presets = data['presets']
303+
self.exempt_words = data.get('allow_list', [])
286304
else:
287305
self.keyword_filter = data.get('keyword_filter', None)
288306
return self

0 commit comments

Comments
 (0)