From 5925da8117f896a2ab0b75ccde8ced3d5675476e Mon Sep 17 00:00:00 2001 From: Enigma Date: Sun, 21 Aug 2022 15:42:38 -0400 Subject: [PATCH 01/17] Add missing rule_trigger_type attribute to AutoModActionExecutionEvent Add missing mention_spam value to AutoModTriggerType enum --- discord/enums.py | 1 + discord/raw_models.py | 4 +++- discord/types/automod.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/discord/enums.py b/discord/enums.py index 322a408489..29256012c2 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -880,6 +880,7 @@ class AutoModTriggerType(Enum): harmful_link = 2 spam = 3 keyword_preset = 4 + mention_spam = 5 class AutoModEventType(Enum): diff --git a/discord/raw_models.py b/discord/raw_models.py index 65f9d8f151..ba7550c7e8 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -28,7 +28,7 @@ import datetime from typing import TYPE_CHECKING -from .automod import AutoModAction +from .automod import AutoModAction, AutoModTriggerType from .enums import ChannelType, try_enum if TYPE_CHECKING: @@ -443,6 +443,7 @@ class AutoModActionExecutionEvent: __slots__ = ( "action", "rule_id", + "rule_trigger_type", "guild_id", "guild", "user_id", @@ -461,6 +462,7 @@ class AutoModActionExecutionEvent: def __init__(self, state: ConnectionState, data: AutoModActionExecution) -> None: self.action: AutoModAction = AutoModAction.from_dict(data["action"]) self.rule_id: int = int(data["rule_id"]) + self.rule_trigger_type: AutoModTriggerType = try_enum(AutoModTriggerType, int(data["rule_trigger_type"])) self.guild_id: int = int(data["guild_id"]) self.guild: Guild | None = state._get_guild(self.guild_id) self.user_id: int = int(data["user_id"]) diff --git a/discord/types/automod.py b/discord/types/automod.py index 1a1542c06e..5252528a1f 100644 --- a/discord/types/automod.py +++ b/discord/types/automod.py @@ -27,7 +27,7 @@ from .._typed_dict import NotRequired, TypedDict from .snowflake import Snowflake -AutoModTriggerType = Literal[1, 2, 3, 4] +AutoModTriggerType = Literal[1, 2, 3, 4, 5] AutoModEventType = Literal[1] From a6e47c61cbb9e64a82c585b61c0bb18428474f9b Mon Sep 17 00:00:00 2001 From: Enigma Date: Sun, 21 Aug 2022 15:51:19 -0400 Subject: [PATCH 02/17] Update documentation for rule_trigger_type in AutoModActionExecutionEvent --- discord/raw_models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discord/raw_models.py b/discord/raw_models.py index ba7550c7e8..4ba8a10da3 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -409,6 +409,8 @@ class AutoModActionExecutionEvent: The action that was executed. rule_id: :class:`int` The ID of the rule that the action belongs to. + rule_trigger_type: :class:`AutoModTriggerType` + The category of trigger the rule belongs to. guild_id: :class:`int` The ID of the guild that the action was executed in. guild: Optional[:class:`Guild`] From 9049a642af6fb67f8312466d6f9fb3e9cea15467 Mon Sep 17 00:00:00 2001 From: Enigma Date: Mon, 28 Nov 2022 21:24:36 -0500 Subject: [PATCH 03/17] Add missing trigger metadata values --- discord/automod.py | 30 ++++++++++++++++++++++++++++++ discord/enums.py | 1 - discord/types/automod.py | 5 ++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/discord/automod.py b/discord/automod.py index 6c786cbf36..ea9dae8488 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -186,25 +186,43 @@ class AutoModTriggerMetadata: __slots__ = ( "keyword_filter", + "regex_patterns", "presets", + "allow_list", + "mention_total_limit" ) def __init__( self, keyword_filter: list[str] = MISSING, + regex_patterns: list[str] = MISSING, presets: list[AutoModKeywordPresetType] = MISSING, + allow_list: list[str] = MISSING, + mention_total_limit: int = MISSING ): self.keyword_filter = keyword_filter + self.regex_patterns = regex_patterns self.presets = presets + self.allow_list = allow_list + self.mention_total_limit = mention_total_limit def to_dict(self) -> dict: data = {} if self.keyword_filter is not MISSING: data["keyword_filter"] = self.keyword_filter + + if self.regex_patterns is not MISSING: + data["regex_patterns"] = self.regex_patterns if self.presets is not MISSING: data["presets"] = [wordset.value for wordset in self.presets] + + if self.allow_list is not MISSING: + data["allow_list"] = self.allow_list + + if self.mention_total_limit is not MISSING: + data["mention_total_limit"] = self.mention_total_limit return data @@ -214,18 +232,30 @@ def from_dict(cls, data: AutoModTriggerMetadataPayload): if (keyword_filter := data.get("keyword_filter")) is not None: kwargs["keyword_filter"] = keyword_filter + + if (regex_patterns := data.get("regex_patterns")) is not None: + kwargs["regex_patterns"] = regex_patterns if (presets := data.get("presets")) is not None: kwargs["presets"] = [ try_enum(AutoModKeywordPresetType, wordset) for wordset in presets ] + + if (allow_list := data.get("allow_list")) is not None: + kwargs["allow_list"] = allow_list + + if (mention_total_limit := data.get("mention_total_limit")) is not None: + kwargs["mention_total_limit"] = mention_total_limit return cls(**kwargs) def __repr__(self) -> str: repr_attrs = ( "keyword_filter", + "regex_patterns", "presets", + "allow_list", + "mention_total_limit" ) inner = [] diff --git a/discord/enums.py b/discord/enums.py index 29256012c2..145c0d8687 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -877,7 +877,6 @@ class AutoModTriggerType(Enum): """Automod trigger type""" keyword = 1 - harmful_link = 2 spam = 3 keyword_preset = 4 mention_spam = 5 diff --git a/discord/types/automod.py b/discord/types/automod.py index 5252528a1f..655ab4b478 100644 --- a/discord/types/automod.py +++ b/discord/types/automod.py @@ -27,7 +27,7 @@ from .._typed_dict import NotRequired, TypedDict from .snowflake import Snowflake -AutoModTriggerType = Literal[1, 2, 3, 4, 5] +AutoModTriggerType = Literal[1, 3, 4, 5] AutoModEventType = Literal[1] @@ -38,7 +38,10 @@ class AutoModTriggerMetadata(TypedDict, total=False): keyword_filter: list[str] + regex_patterns: list[str] presets: list[AutoModKeywordPresetType] + allow_list: list[str] + mention_total_limit: int class AutoModActionMetadata(TypedDict, total=False): From 69a6e476a872934ec61428d35d0bf57e3ee5cf34 Mon Sep 17 00:00:00 2001 From: Enigma Date: Tue, 29 Nov 2022 00:25:01 -0500 Subject: [PATCH 04/17] docs: Add missing AutoMod information --- discord/automod.py | 6 ++++ docs/api/enums.rst | 87 +++++++++++++++++++++++++++++++++++++++++++++ docs/api/models.rst | 8 +++++ 3 files changed, 101 insertions(+) diff --git a/discord/automod.py b/discord/automod.py index ea9dae8488..e9291afc68 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -177,8 +177,14 @@ class AutoModTriggerMetadata: ---------- keyword_filter: List[:class:`str`] A list of substrings to filter. Only for triggers of type :attr:`AutoModTriggerType.keyword`. + regex_patterns: List[:class:`str`] + A list of regex patterns to filter. Only for triggeres of type :attr:`AutoModTriggerType.keyword`. presets: List[:class:`AutoModKeywordPresetType`] A list of keyword presets to filter. Only for triggers of type :attr:`AutoModTriggerType.keyword_preset`. + allow_list: List[:class:`str`] + A list of substrings to allow, overriding keyword and regex matches. Only for triggeres of type :attr:`AutoModTriggerType.keyword` and :attr:`AutoModTriggerType.keyword_preset`. + mention_total_limit: :class:`int` + The total number of unique role and user mentions allowed. """ # maybe add a table of action types and attributes? diff --git a/docs/api/enums.rst b/docs/api/enums.rst index 9f7a42aef3..b415098879 100644 --- a/docs/api/enums.rst +++ b/docs/api/enums.rst @@ -1867,3 +1867,90 @@ of :class:`enum.Enum`. .. attribute:: guild_only Represents a scheduled event that is only available to members inside the guild. + +.. class:: AutoModTriggerType + + Represents an AutoMod trigger type. + + .. versionadded:: 2.0 + + .. attribute:: keyword + + Represents a keyword rule trigger, which are customizable by a guild. + + Possible attributes for :class:`AutoModTriggerMetadata`: + + - :attr:`~AutoModTriggerMetadata.keyword_filter` + - :attr:`~AutoModTriggerMetadata.regex_patterns` + - :attr:`~AutoModTriggerMetadata.allow_list` + + .. attribute:: keyword_preset + + Represents a preset keyword rule trigger. + + Possible attributes for :class:`AutoModTriggerMetadata`: + + - :attr:`~AutoModTriggerMetadata.presets` + - :attr:`~AutoModTriggerMetadata.allow_list` + + .. attribute:: spam + + Represents the spam rule trigger. + + There are no possible attributes for :class:`AutoModTriggerMetadata`. + + .. attribute:: mention_spam + + Represents a mention spam keyword rule trigger. + + Possible attributes for :class:`AutoModTriggerMetadata`: + + - :attr:`~AutoModTriggerMetadata.mention_total_limit` + + .. versionadded:: 2.3 + +.. class:: AutoModEventType + + Represents an AutoMod event type. + + .. versionadded:: 2.0 + + .. attribute:: message_send + + Represents a message send AutoMod event. + +.. class:: AutoModActionType + + Represents the type of action AutoMod is performing. + + .. versionadded:: 2.0 + + .. attribute:: block_message + + Represents a block message action. + + .. attribute:: send_alert_message + + Represents a send alert message action. + + .. attribute:: timeout + + Represents a timeout action. + +.. class:: AutoModKeywordPresetType + + Represents an AutoMod keyword preset type. + + .. versionadded:: 2.0 + + .. attribute:: profanity + + Represents the profanity keyword preset rule. + + .. attribute:: sexual_content + + Represents the sexual content keyword preset rule. + + .. attribute:: slurs + + Represents the slurs keyword preset rule. diff --git a/docs/api/models.rst b/docs/api/models.rst index df13a6c90e..160e4c5d5c 100644 --- a/docs/api/models.rst +++ b/docs/api/models.rst @@ -146,11 +146,19 @@ Guild .. autoclass:: Template() :members: +AutoMod +~~~~~~~ + .. attributetable:: AutoModRule .. autoclass:: AutoModRule() :members: +.. attributetable:: AutoModAction + +.. autoclass:: AutoModAction() + :members: + Invites ~~~~~~~ From 651f277ce0ad92939ce474a3b60c5388c5a40b95 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 29 Nov 2022 05:43:23 +0000 Subject: [PATCH 05/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- discord/automod.py | 18 +++++++++--------- discord/raw_models.py | 4 +++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/discord/automod.py b/discord/automod.py index e9291afc68..91c64d58b6 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -195,7 +195,7 @@ class AutoModTriggerMetadata: "regex_patterns", "presets", "allow_list", - "mention_total_limit" + "mention_total_limit", ) def __init__( @@ -204,7 +204,7 @@ def __init__( regex_patterns: list[str] = MISSING, presets: list[AutoModKeywordPresetType] = MISSING, allow_list: list[str] = MISSING, - mention_total_limit: int = MISSING + mention_total_limit: int = MISSING, ): self.keyword_filter = keyword_filter self.regex_patterns = regex_patterns @@ -217,16 +217,16 @@ def to_dict(self) -> dict: if self.keyword_filter is not MISSING: data["keyword_filter"] = self.keyword_filter - + if self.regex_patterns is not MISSING: data["regex_patterns"] = self.regex_patterns if self.presets is not MISSING: data["presets"] = [wordset.value for wordset in self.presets] - + if self.allow_list is not MISSING: data["allow_list"] = self.allow_list - + if self.mention_total_limit is not MISSING: data["mention_total_limit"] = self.mention_total_limit @@ -238,7 +238,7 @@ def from_dict(cls, data: AutoModTriggerMetadataPayload): if (keyword_filter := data.get("keyword_filter")) is not None: kwargs["keyword_filter"] = keyword_filter - + if (regex_patterns := data.get("regex_patterns")) is not None: kwargs["regex_patterns"] = regex_patterns @@ -246,10 +246,10 @@ def from_dict(cls, data: AutoModTriggerMetadataPayload): kwargs["presets"] = [ try_enum(AutoModKeywordPresetType, wordset) for wordset in presets ] - + if (allow_list := data.get("allow_list")) is not None: kwargs["allow_list"] = allow_list - + if (mention_total_limit := data.get("mention_total_limit")) is not None: kwargs["mention_total_limit"] = mention_total_limit @@ -261,7 +261,7 @@ def __repr__(self) -> str: "regex_patterns", "presets", "allow_list", - "mention_total_limit" + "mention_total_limit", ) inner = [] diff --git a/discord/raw_models.py b/discord/raw_models.py index 4ba8a10da3..6b37bb711c 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -464,7 +464,9 @@ class AutoModActionExecutionEvent: def __init__(self, state: ConnectionState, data: AutoModActionExecution) -> None: self.action: AutoModAction = AutoModAction.from_dict(data["action"]) self.rule_id: int = int(data["rule_id"]) - self.rule_trigger_type: AutoModTriggerType = try_enum(AutoModTriggerType, int(data["rule_trigger_type"])) + self.rule_trigger_type: AutoModTriggerType = try_enum( + AutoModTriggerType, int(data["rule_trigger_type"]) + ) self.guild_id: int = int(data["guild_id"]) self.guild: Guild | None = state._get_guild(self.guild_id) self.user_id: int = int(data["user_id"]) From 4a64e95f757425e0ce5ffa96e2b742933fdc7d85 Mon Sep 17 00:00:00 2001 From: Enigma Date: Tue, 29 Nov 2022 01:08:00 -0500 Subject: [PATCH 06/17] docs: Fix typos in AutoModTriggerMetadata and add warning on regex flavor compatibility. Also expose the AutoModAction class to allow documentation to compile. --- discord/automod.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/discord/automod.py b/discord/automod.py index 91c64d58b6..60d7846fb5 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -39,7 +39,7 @@ from .mixins import Hashable from .object import Object -__all__ = ("AutoModRule",) +__all__ = ("AutoModRule", "AutoModAction",) if TYPE_CHECKING: from .abc import Snowflake @@ -176,13 +176,18 @@ class AutoModTriggerMetadata: Attributes ---------- keyword_filter: List[:class:`str`] - A list of substrings to filter. Only for triggers of type :attr:`AutoModTriggerType.keyword`. + A list of substrings to filter. + Only for triggers of type :attr:`AutoModTriggerType.keyword`. regex_patterns: List[:class:`str`] - A list of regex patterns to filter. Only for triggeres of type :attr:`AutoModTriggerType.keyword`. + A list of regex patterns to filter using Rust-flavored regex, which is not + fully compatible with regex syntax supported by the builtin `re` module. + Only for triggers of type :attr:`AutoModTriggerType.keyword`. presets: List[:class:`AutoModKeywordPresetType`] - A list of keyword presets to filter. Only for triggers of type :attr:`AutoModTriggerType.keyword_preset`. + A list of keyword presets to filter. + Only for triggers of type :attr:`AutoModTriggerType.keyword_preset`. allow_list: List[:class:`str`] - A list of substrings to allow, overriding keyword and regex matches. Only for triggeres of type :attr:`AutoModTriggerType.keyword` and :attr:`AutoModTriggerType.keyword_preset`. + A list of substrings to allow, overriding keyword and regex matches. + Only for triggers of type :attr:`AutoModTriggerType.keyword` and :attr:`AutoModTriggerType.keyword_preset`. mention_total_limit: :class:`int` The total number of unique role and user mentions allowed. """ From 3a15e9ecb876d8afc7c2940dc82ad775a7773ecc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 29 Nov 2022 06:08:33 +0000 Subject: [PATCH 07/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- discord/automod.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/discord/automod.py b/discord/automod.py index 60d7846fb5..f7854c7d3f 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -39,7 +39,10 @@ from .mixins import Hashable from .object import Object -__all__ = ("AutoModRule", "AutoModAction",) +__all__ = ( + "AutoModRule", + "AutoModAction", +) if TYPE_CHECKING: from .abc import Snowflake From ac7a37ee27ec35e25494336f1364900fbae725d8 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Tue, 29 Nov 2022 14:27:34 +0100 Subject: [PATCH 08/17] Apply suggestions from code review --- discord/enums.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/enums.py b/discord/enums.py index 145c0d8687..29256012c2 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -877,6 +877,7 @@ class AutoModTriggerType(Enum): """Automod trigger type""" keyword = 1 + harmful_link = 2 spam = 3 keyword_preset = 4 mention_spam = 5 From ea5bd50bbd328b2eac44a35e82ada2af7319b33a Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Tue, 29 Nov 2022 14:27:57 +0100 Subject: [PATCH 09/17] Update discord/types/automod.py --- discord/types/automod.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/types/automod.py b/discord/types/automod.py index 655ab4b478..4632c8d8c4 100644 --- a/discord/types/automod.py +++ b/discord/types/automod.py @@ -27,7 +27,7 @@ from .._typed_dict import NotRequired, TypedDict from .snowflake import Snowflake -AutoModTriggerType = Literal[1, 3, 4, 5] +AutoModTriggerType = Literal[1, 2, 3, 4, 5] AutoModEventType = Literal[1] From 270a43dfaabb2faa08e8d3eb45461a0cc69f4817 Mon Sep 17 00:00:00 2001 From: Enigma Date: Wed, 30 Nov 2022 00:19:31 -0500 Subject: [PATCH 10/17] docs: Add versionadded to new AutoMod properties, and correct one from 2.3 to 2.4 --- discord/automod.py | 6 ++++++ discord/raw_models.py | 2 ++ docs/api/enums.rst | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/discord/automod.py b/discord/automod.py index f7854c7d3f..71364e435b 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -185,14 +185,20 @@ class AutoModTriggerMetadata: A list of regex patterns to filter using Rust-flavored regex, which is not fully compatible with regex syntax supported by the builtin `re` module. Only for triggers of type :attr:`AutoModTriggerType.keyword`. + + .. versionadded:: 2.4 presets: List[:class:`AutoModKeywordPresetType`] A list of keyword presets to filter. Only for triggers of type :attr:`AutoModTriggerType.keyword_preset`. allow_list: List[:class:`str`] A list of substrings to allow, overriding keyword and regex matches. Only for triggers of type :attr:`AutoModTriggerType.keyword` and :attr:`AutoModTriggerType.keyword_preset`. + + .. versionadded:: 2.4 mention_total_limit: :class:`int` The total number of unique role and user mentions allowed. + + .. versionadded:: 2.4 """ # maybe add a table of action types and attributes? diff --git a/discord/raw_models.py b/discord/raw_models.py index 6b37bb711c..3353c4c17e 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -411,6 +411,8 @@ class AutoModActionExecutionEvent: The ID of the rule that the action belongs to. rule_trigger_type: :class:`AutoModTriggerType` The category of trigger the rule belongs to. + + .. versionadded:: 2.4 guild_id: :class:`int` The ID of the guild that the action was executed in. guild: Optional[:class:`Guild`] diff --git a/docs/api/enums.rst b/docs/api/enums.rst index 7509648686..347086bda9 100644 --- a/docs/api/enums.rst +++ b/docs/api/enums.rst @@ -1907,7 +1907,7 @@ of :class:`enum.Enum`. - :attr:`~AutoModTriggerMetadata.mention_total_limit` - .. versionadded:: 2.3 + .. versionadded:: 2.4 .. class:: AutoModEventType From 524676ab932893e530062aa8d48927bb3dd8627f Mon Sep 17 00:00:00 2001 From: Enigma Date: Wed, 30 Nov 2022 00:33:29 -0500 Subject: [PATCH 11/17] docs(changelog): Update changelog for this pull request --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea8aa61585..683ec654ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,11 @@ possible (see our [Version Guarantees] for more info). These changes are available on the `master` branch, but have not yet been released. -_No changes yet_ +### Added + +- Added new AutoMod trigger metadata properties `regex_patterns`, `allow_list`, + and `mention_total_limit`; and added the `mention_spam` trigger type. + ([#1809](https://github.com/Pycord-Development/pycord/pull/1809)) ## [2.3.1] - 2022-11-27 From c9a057d20390d5b5a8ebacc230afa0544f69dd9f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 30 Nov 2022 05:33:54 +0000 Subject: [PATCH 12/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 683ec654ea..66946afa64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,8 @@ These changes are available on the `master` branch, but have not yet been releas ### Added -- Added new AutoMod trigger metadata properties `regex_patterns`, `allow_list`, - and `mention_total_limit`; and added the `mention_spam` trigger type. +- Added new AutoMod trigger metadata properties `regex_patterns`, `allow_list`, and + `mention_total_limit`; and added the `mention_spam` trigger type. ([#1809](https://github.com/Pycord-Development/pycord/pull/1809)) ## [2.3.1] - 2022-11-27 From feca849b4e06d8a3d4dc50b3ed8890e6d8c0989c Mon Sep 17 00:00:00 2001 From: Enigma Date: Wed, 30 Nov 2022 13:57:58 -0500 Subject: [PATCH 13/17] docs: Mark `harmful_link` trigger type as deprecated, and update `AutoModTriggerMetadata.mention_total_limit` to add supported trigger type. --- discord/automod.py | 1 + docs/api/enums.rst | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/discord/automod.py b/discord/automod.py index 71364e435b..a78bacff76 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -197,6 +197,7 @@ class AutoModTriggerMetadata: .. versionadded:: 2.4 mention_total_limit: :class:`int` The total number of unique role and user mentions allowed. + Only for triggers of type :attr:`AutoModTriggerType.mention_spam`. .. versionadded:: 2.4 """ diff --git a/docs/api/enums.rst b/docs/api/enums.rst index 347086bda9..1b97bab65b 100644 --- a/docs/api/enums.rst +++ b/docs/api/enums.rst @@ -1909,6 +1909,13 @@ of :class:`enum.Enum`. .. versionadded:: 2.4 + .. attribute:: harmful_link + + Represents a harmful link rule trigger. + + .. deprecated:: 2.4 + Removed by Discord and merged into `spam`. + .. class:: AutoModEventType Represents an AutoMod event type. From e25271705eaeb5c070b4ec2af1b5f51fe1da4634 Mon Sep 17 00:00:00 2001 From: Enigma Date: Tue, 6 Dec 2022 20:33:20 -0500 Subject: [PATCH 14/17] docs: Add additional AutoMod documentation for `AutoModTriggerMetadata` and `AutoModActionMetadata`, and converted trigger metadata trigger type limits to a table. --- discord/automod.py | 38 ++++++++++++++++++++++++++------------ docs/api/enums.rst | 2 +- docs/api/models.rst | 12 ++++++++++++ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/discord/automod.py b/discord/automod.py index a78bacff76..48097030b0 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -170,9 +170,27 @@ def __repr__(self) -> str: class AutoModTriggerMetadata: - """Represents a rule's trigger metadata. - - Depending on the trigger type, different attributes will be used. + """Represents a rule's trigger metadata, defining additional data used to determine when a rule triggers. + + Depending on the trigger type, different metadata attributes will be used: + + +-----------------------------+--------------------------------------------------------------------------------+ + | Attribute | Trigger Types | + +=============================+================================================================================+ + | :attr:`keyword_filter` | :attr:`AutoModTriggerType.keyword` | + +-----------------------------+--------------------------------------------------------------------------------+ + | :attr:`regex_patterns` | :attr:`AutoModTriggerType.keyword` | + +-----------------------------+--------------------------------------------------------------------------------+ + | :attr:`presets` | :attr:`AutoModTriggerType.keyword_preset` | + +-----------------------------+--------------------------------------------------------------------------------+ + | :attr:`allow_list` | :attr:`AutoModTriggerType.keyword`\, :attr:`AutoModTriggerType.keyword_preset` | + +-----------------------------+--------------------------------------------------------------------------------+ + | :attr:`mention_total_limit` | :attr:`AutoModTriggerType.mention_spam` | + +-----------------------------+--------------------------------------------------------------------------------+ + + Each attribute has limits that may change based on the trigger type. + See `here `_ + for information on attribute limits. .. versionadded:: 2.0 @@ -180,31 +198,27 @@ class AutoModTriggerMetadata: ---------- keyword_filter: List[:class:`str`] A list of substrings to filter. - Only for triggers of type :attr:`AutoModTriggerType.keyword`. + regex_patterns: List[:class:`str`] A list of regex patterns to filter using Rust-flavored regex, which is not fully compatible with regex syntax supported by the builtin `re` module. - Only for triggers of type :attr:`AutoModTriggerType.keyword`. .. versionadded:: 2.4 + presets: List[:class:`AutoModKeywordPresetType`] - A list of keyword presets to filter. - Only for triggers of type :attr:`AutoModTriggerType.keyword_preset`. + A list of preset keyword sets to filter. + allow_list: List[:class:`str`] A list of substrings to allow, overriding keyword and regex matches. - Only for triggers of type :attr:`AutoModTriggerType.keyword` and :attr:`AutoModTriggerType.keyword_preset`. .. versionadded:: 2.4 + mention_total_limit: :class:`int` The total number of unique role and user mentions allowed. - Only for triggers of type :attr:`AutoModTriggerType.mention_spam`. .. versionadded:: 2.4 """ - # maybe add a table of action types and attributes? - # wording for presets could change - __slots__ = ( "keyword_filter", "regex_patterns", diff --git a/docs/api/enums.rst b/docs/api/enums.rst index 1b97bab65b..8ab182c9d9 100644 --- a/docs/api/enums.rst +++ b/docs/api/enums.rst @@ -1914,7 +1914,7 @@ of :class:`enum.Enum`. Represents a harmful link rule trigger. .. deprecated:: 2.4 - Removed by Discord and merged into `spam`. + Removed by Discord and merged into :attr:`spam`. .. class:: AutoModEventType diff --git a/docs/api/models.rst b/docs/api/models.rst index 160e4c5d5c..1081fbeee2 100644 --- a/docs/api/models.rst +++ b/docs/api/models.rst @@ -159,6 +159,18 @@ AutoMod .. autoclass:: AutoModAction() :members: +.. attributetable:: AutoModTriggerMetadata + +.. autoclass:: AutoModTriggerMetadata() + :members: + +.. attributetable:: AutoModActionMetadata + +.. autoclass:: AutoModActionMetadata() + :members: + + + Invites ~~~~~~~ From 4783f122c860a1d57d631b0690bb8e2aafb84c39 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Dec 2022 01:33:58 +0000 Subject: [PATCH 15/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- discord/automod.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/automod.py b/discord/automod.py index 48097030b0..164458163f 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -170,7 +170,7 @@ def __repr__(self) -> str: class AutoModTriggerMetadata: - """Represents a rule's trigger metadata, defining additional data used to determine when a rule triggers. + r"""Represents a rule's trigger metadata, defining additional data used to determine when a rule triggers. Depending on the trigger type, different metadata attributes will be used: @@ -190,7 +190,7 @@ class AutoModTriggerMetadata: Each attribute has limits that may change based on the trigger type. See `here `_ - for information on attribute limits. + for information on attribute limits. .. versionadded:: 2.0 From 0667595bf5a46513f3e52d0563c16748ddd82a82 Mon Sep 17 00:00:00 2001 From: Enigma Date: Tue, 6 Dec 2022 20:39:22 -0500 Subject: [PATCH 16/17] docs: Make `AutoModActionMetadata` visible for docs compilation `AutoModTriggerMetadata` --- discord/automod.py | 2 ++ docs/api/models.rst | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/discord/automod.py b/discord/automod.py index 164458163f..568538da73 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -42,6 +42,8 @@ __all__ = ( "AutoModRule", "AutoModAction", + "AutoModActionMetadata", + "AutoModTriggerMetadata" ) if TYPE_CHECKING: diff --git a/docs/api/models.rst b/docs/api/models.rst index 1081fbeee2..d4520da8b2 100644 --- a/docs/api/models.rst +++ b/docs/api/models.rst @@ -159,17 +159,15 @@ AutoMod .. autoclass:: AutoModAction() :members: -.. attributetable:: AutoModTriggerMetadata - -.. autoclass:: AutoModTriggerMetadata() - :members: - .. attributetable:: AutoModActionMetadata .. autoclass:: AutoModActionMetadata() :members: +.. attributetable:: AutoModTriggerMetadata +.. autoclass:: AutoModTriggerMetadata() + :members: Invites ~~~~~~~ From 38f4ffd814acb36cc2ca48bc99c3fefdbb498edc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Dec 2022 01:41:22 +0000 Subject: [PATCH 17/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- discord/automod.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/automod.py b/discord/automod.py index 568538da73..96ce4f12e5 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -43,7 +43,7 @@ "AutoModRule", "AutoModAction", "AutoModActionMetadata", - "AutoModTriggerMetadata" + "AutoModTriggerMetadata", ) if TYPE_CHECKING: