From 829f1463a61e99f7c8ad2cfcde5da90d46a4946f Mon Sep 17 00:00:00 2001 From: Marc13 Date: Tue, 27 Jun 2023 14:38:10 +0200 Subject: [PATCH 01/12] Update guild.py --- discord/guild.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/discord/guild.py b/discord/guild.py index 9f1aae0c2b..4c00865fee 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3820,3 +3820,63 @@ async def create_auto_moderation_rule( self.id, payload, reason=reason ) return AutoModRule(state=self._state, data=data) + + async def delete_auto_moderation_rule( + self, + *, + id: Optional[float] = None, + name: Optional[str] = None, + reason: Optional[str] = None, + ) -> AutoModRule: + """ + Deletes an auto moderation rule. + + Parameters + ---------- + id: Optional[float] + The ID of the auto moderation rule. + name: Optional[str] + The name of the auto moderation rule. + reason: Optional[str] + The reason for deleting the rule. Shows up in the audit log. + + Returns + ------- + AutoModRule + The deleted auto moderation rule. + + Raises + ------ + ValueError + If neither 'id' nor 'name' is provided. + ValueError + If both 'id' and 'name' are provided. + ValueError + If no auto moderation rule is found with the given name. + HTTPException + Deleting the auto moderation rule failed. + Forbidden + You do not have the Manage Guild permission. + """ + + if not id and not name: + raise ValueError("Either 'id' or 'name' must be provided.") + + if id and name: + raise ValueError("Only one of 'id' or 'name' can be provided.") + + if name: + # Get all auto moderation rules + rules_response = await self._state.http.get_auto_moderation_rules(self.id) + rules = rules_response + + # Find the rule by name + matching_rules = [rule for rule in rules if rule['name'] == name] + if not matching_rules: + raise ValueError(f"No auto moderation rule found with name '{name}'.") + id = matching_rules[0]['id'] + + data = await self._state.http.delete_auto_moderation_rule( + self.id, id, reason=reason + ) + return From 12cd10fe0e26a89d67f782f764519830ef42561d Mon Sep 17 00:00:00 2001 From: Marc13 Date: Tue, 27 Jun 2023 14:50:19 +0200 Subject: [PATCH 02/12] Update guild.py --- discord/guild.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/guild.py b/discord/guild.py index 4c00865fee..5c89db4827 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3824,7 +3824,7 @@ async def create_auto_moderation_rule( async def delete_auto_moderation_rule( self, *, - id: Optional[float] = None, + id: Optional[int] = None, name: Optional[str] = None, reason: Optional[str] = None, ) -> AutoModRule: From 927fb23c424db3c997a82a265911bb161808be12 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 27 Jun 2023 12:52:24 +0000 Subject: [PATCH 03/12] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/guild.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 59200ae342..ba4f52e191 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3816,13 +3816,13 @@ async def create_auto_moderation_rule( self.id, payload, reason=reason ) return AutoModRule(state=self._state, data=data) - + async def delete_auto_moderation_rule( self, *, - id: Optional[int] = None, - name: Optional[str] = None, - reason: Optional[str] = None, + id: int | None = None, + name: str | None = None, + reason: str | None = None, ) -> AutoModRule: """ Deletes an auto moderation rule. @@ -3867,10 +3867,10 @@ async def delete_auto_moderation_rule( rules = rules_response # Find the rule by name - matching_rules = [rule for rule in rules if rule['name'] == name] + matching_rules = [rule for rule in rules if rule["name"] == name] if not matching_rules: raise ValueError(f"No auto moderation rule found with name '{name}'.") - id = matching_rules[0]['id'] + id = matching_rules[0]["id"] data = await self._state.http.delete_auto_moderation_rule( self.id, id, reason=reason From c759a95f498f185fddb972b24c6dd2fb385d9439 Mon Sep 17 00:00:00 2001 From: Marc13 Date: Tue, 27 Jun 2023 14:53:01 +0200 Subject: [PATCH 04/12] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e32c819f21..735854aa77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ These changes are available on the `master` branch, but have not yet been releas ### Added +- Added function `delete_auto_moderation_rule`. + ([#2153]https://github.com/Pycord-Development/pycord/pull/2153) - Added possibility to start bot via async context manager. ([#1801](https://github.com/Pycord-Development/pycord/pull/1801)) - Change default for all `name_localizations` & `description_localizations` attributes From 568cf41bce8ddc2fbad9d85cc89f327289ad72a1 Mon Sep 17 00:00:00 2001 From: Marc13 <83296140+llamaair@users.noreply.github.com> Date: Tue, 27 Jun 2023 15:06:30 +0200 Subject: [PATCH 05/12] Update discord/guild.py Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: Marc13 <83296140+llamaair@users.noreply.github.com> --- discord/guild.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/guild.py b/discord/guild.py index ba4f52e191..5ab81e30d4 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3829,7 +3829,7 @@ async def delete_auto_moderation_rule( Parameters ---------- - id: Optional[float] + id: Optional[int] The ID of the auto moderation rule. name: Optional[str] The name of the auto moderation rule. From 2b2d1f94c518b0f120e3c39218fc52ccbd18aaf5 Mon Sep 17 00:00:00 2001 From: Marc13 Date: Tue, 27 Jun 2023 15:32:12 +0200 Subject: [PATCH 06/12] Update guild.py --- discord/guild.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 5ab81e30d4..8c777f623f 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3836,11 +3836,6 @@ async def delete_auto_moderation_rule( reason: Optional[str] The reason for deleting the rule. Shows up in the audit log. - Returns - ------- - AutoModRule - The deleted auto moderation rule. - Raises ------ ValueError From 3b948893957b154840b2e1319b7eb8e4f88cd282 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 5 Jul 2023 05:26:20 +0200 Subject: [PATCH 07/12] Apply suggestions from code review Signed-off-by: Lala Sabathil --- discord/guild.py | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 8c777f623f..8cc319f59e 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3820,8 +3820,7 @@ async def create_auto_moderation_rule( async def delete_auto_moderation_rule( self, *, - id: int | None = None, - name: str | None = None, + id: int, reason: str | None = None, ) -> AutoModRule: """ @@ -3831,42 +3830,17 @@ async def delete_auto_moderation_rule( ---------- id: Optional[int] The ID of the auto moderation rule. - name: Optional[str] - The name of the auto moderation rule. reason: Optional[str] The reason for deleting the rule. Shows up in the audit log. Raises ------ - ValueError - If neither 'id' nor 'name' is provided. - ValueError - If both 'id' and 'name' are provided. - ValueError - If no auto moderation rule is found with the given name. HTTPException Deleting the auto moderation rule failed. Forbidden You do not have the Manage Guild permission. """ - if not id and not name: - raise ValueError("Either 'id' or 'name' must be provided.") - - if id and name: - raise ValueError("Only one of 'id' or 'name' can be provided.") - - if name: - # Get all auto moderation rules - rules_response = await self._state.http.get_auto_moderation_rules(self.id) - rules = rules_response - - # Find the rule by name - matching_rules = [rule for rule in rules if rule["name"] == name] - if not matching_rules: - raise ValueError(f"No auto moderation rule found with name '{name}'.") - id = matching_rules[0]["id"] - data = await self._state.http.delete_auto_moderation_rule( self.id, id, reason=reason ) From 9c35b87a992a2cdd7b5db1e732eff3735de1baeb Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 5 Jul 2023 05:27:41 +0200 Subject: [PATCH 08/12] Update discord/guild.py Signed-off-by: Lala Sabathil --- discord/guild.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/guild.py b/discord/guild.py index 8cc319f59e..c5520614d1 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3844,4 +3844,4 @@ async def delete_auto_moderation_rule( data = await self._state.http.delete_auto_moderation_rule( self.id, id, reason=reason ) - return + return AutoModRule(state=self._state, data=data) From 6fdf4819f8c4ec18082be593a26e8ebf7ef10672 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 5 Jul 2023 05:28:26 +0200 Subject: [PATCH 09/12] Apply suggestions from code review Signed-off-by: Lala Sabathil --- discord/guild.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/guild.py b/discord/guild.py index c5520614d1..b3febae842 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3828,7 +3828,7 @@ async def delete_auto_moderation_rule( Parameters ---------- - id: Optional[int] + id: int The ID of the auto moderation rule. reason: Optional[str] The reason for deleting the rule. Shows up in the audit log. From 0664a5260f389a0ed7077e810744f8a2a2783b0f Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 5 Jul 2023 05:29:45 +0200 Subject: [PATCH 10/12] Apply suggestions from code review Signed-off-by: Lala Sabathil --- discord/guild.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index b3febae842..c89b98e9f7 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3828,9 +3828,9 @@ async def delete_auto_moderation_rule( Parameters ---------- - id: int + id: :class:`int` The ID of the auto moderation rule. - reason: Optional[str] + reason: Optional[:class:`str`] The reason for deleting the rule. Shows up in the audit log. Raises From c860fecd68ac070581502d5c1ad4b6f5b43bf8f5 Mon Sep 17 00:00:00 2001 From: Marc13 Date: Thu, 13 Jul 2023 19:04:29 +0200 Subject: [PATCH 11/12] Apply suggestions from reviews --- CHANGELOG.md | 4 ++-- discord/guild.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db5163197d..94892ddda2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,6 @@ These changes are available on the `master` branch, but have not yet been releas ### Added -- Added function `delete_auto_moderation_rule`. - ([#2153]https://github.com/Pycord-Development/pycord/pull/2153) - Added possibility to start bot via async context manager. ([#1801](https://github.com/Pycord-Development/pycord/pull/1801)) - Change default for all `name_localizations` & `description_localizations` attributes @@ -73,6 +71,8 @@ These changes are available on the `master` branch, but have not yet been releas - Added `suppress` and `allowed_mentions` parameters to `Webhook` and `InteractionResponse` edit methods. ([#2138](https://github.com/Pycord-Development/pycord/pull/2138)) +- Added function `Guild.delete_auto_moderation_rule`. + ([#2153](https://github.com/Pycord-Development/pycord/pull/2153)) ### Changed diff --git a/discord/guild.py b/discord/guild.py index c89b98e9f7..a107f74f1c 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3819,8 +3819,8 @@ async def create_auto_moderation_rule( async def delete_auto_moderation_rule( self, - *, id: int, + *, reason: str | None = None, ) -> AutoModRule: """ From 0076382773371513b4baa858c0386259b5ee4a9c Mon Sep 17 00:00:00 2001 From: Marc13 Date: Thu, 27 Jul 2023 16:42:21 +0200 Subject: [PATCH 12/12] Apply suggestions from code review --- discord/guild.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index a107f74f1c..5d74590dca 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3822,7 +3822,7 @@ async def delete_auto_moderation_rule( id: int, *, reason: str | None = None, - ) -> AutoModRule: + ) -> None: """ Deletes an auto moderation rule. @@ -3841,7 +3841,4 @@ async def delete_auto_moderation_rule( You do not have the Manage Guild permission. """ - data = await self._state.http.delete_auto_moderation_rule( - self.id, id, reason=reason - ) - return AutoModRule(state=self._state, data=data) + await self._state.http.delete_auto_moderation_rule(self.id, id, reason=reason)