From db08b78a99d2bc97f8cb0bc5bbb30f198a9ecc81 Mon Sep 17 00:00:00 2001 From: iyad-f <128908811+iyad-f@users.noreply.github.com> Date: Sun, 29 Dec 2024 20:06:14 +0530 Subject: [PATCH 1/7] fix message_pin target id being None --- discord/audit_logs.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/discord/audit_logs.py b/discord/audit_logs.py index 59d563829257..cbd88527e1a8 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -874,7 +874,13 @@ def _convert_target_invite(self, target_id: None) -> Invite: def _convert_target_emoji(self, target_id: int) -> Union[Emoji, Object]: return self._state.get_emoji(target_id) or Object(id=target_id, type=Emoji) - def _convert_target_message(self, target_id: int) -> Union[Member, User, Object]: + def _convert_target_message(self, target_id: Optional[int]) -> Optional[Union[Member, User, Object]]: + # The message_pin and message_unpin action types do not have a + # non-null target_id so safeguard against that + + if target_id is None: + return None + return self._get_member(target_id) or Object(id=target_id, type=Member) def _convert_target_stage_instance(self, target_id: int) -> Union[StageInstance, Object]: From fb3a6147634ee61eddf0820ab103bb260dc77107 Mon Sep 17 00:00:00 2001 From: iyad-f <128908811+iyad-f@users.noreply.github.com> Date: Sun, 29 Dec 2024 23:27:03 +0530 Subject: [PATCH 2/7] Update discord/audit_logs.py Co-authored-by: Michael H --- discord/audit_logs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/audit_logs.py b/discord/audit_logs.py index cbd88527e1a8..9c301ad3b701 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -874,7 +874,7 @@ def _convert_target_invite(self, target_id: None) -> Invite: def _convert_target_emoji(self, target_id: int) -> Union[Emoji, Object]: return self._state.get_emoji(target_id) or Object(id=target_id, type=Emoji) - def _convert_target_message(self, target_id: Optional[int]) -> Optional[Union[Member, User, Object]]: + def _convert_target_message(self, target_id: Optional[int]) -> Union[Member, User, Object, None]: # The message_pin and message_unpin action types do not have a # non-null target_id so safeguard against that From 502c18c354268a951db9817a382450c19761b874 Mon Sep 17 00:00:00 2001 From: iyad-f <128908811+iyad-f@users.noreply.github.com> Date: Sun, 29 Dec 2024 23:27:11 +0530 Subject: [PATCH 3/7] Update discord/audit_logs.py Co-authored-by: Michael H --- discord/audit_logs.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/discord/audit_logs.py b/discord/audit_logs.py index 9c301ad3b701..59a1471082c7 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -878,10 +878,7 @@ def _convert_target_message(self, target_id: Optional[int]) -> Union[Member, Use # The message_pin and message_unpin action types do not have a # non-null target_id so safeguard against that - if target_id is None: - return None - - return self._get_member(target_id) or Object(id=target_id, type=Member) + return target_id and self._get_member(target_id) or Object(id=target_id, type=Member) def _convert_target_stage_instance(self, target_id: int) -> Union[StageInstance, Object]: return self.guild.get_stage_instance(target_id) or Object(id=target_id, type=StageInstance) From 37d5c54449f58bd53cd98669a3fddc6749eb738a Mon Sep 17 00:00:00 2001 From: iyad-f <128908811+iyad-f@users.noreply.github.com> Date: Sun, 26 Jan 2025 00:42:42 +0530 Subject: [PATCH 4/7] Update discord/audit_logs.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alex Nørgaard --- discord/audit_logs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/audit_logs.py b/discord/audit_logs.py index 59a1471082c7..cb56163fbabd 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -878,7 +878,7 @@ def _convert_target_message(self, target_id: Optional[int]) -> Union[Member, Use # The message_pin and message_unpin action types do not have a # non-null target_id so safeguard against that - return target_id and self._get_member(target_id) or Object(id=target_id, type=Member) + return target_id and (self._get_member(target_id) or Object(id=target_id, type=Member)) def _convert_target_stage_instance(self, target_id: int) -> Union[StageInstance, Object]: return self.guild.get_stage_instance(target_id) or Object(id=target_id, type=StageInstance) From 94840675372c162c3ea6ecd5dab784a6cb0c7676 Mon Sep 17 00:00:00 2001 From: iyad-f <128908811+iyad-f@users.noreply.github.com> Date: Sun, 26 Jan 2025 00:53:21 +0530 Subject: [PATCH 5/7] run black --- discord/audit_logs.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/discord/audit_logs.py b/discord/audit_logs.py index cbd88527e1a8..c3497821af03 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -285,11 +285,9 @@ def __repr__(self) -> str: if TYPE_CHECKING: - def __getattr__(self, item: str) -> Any: - ... + def __getattr__(self, item: str) -> Any: ... - def __setattr__(self, key: str, value: Any) -> Any: - ... + def __setattr__(self, key: str, value: Any) -> Any: ... Transformer = Callable[["AuditLogEntry", Any], Any] @@ -875,7 +873,7 @@ def _convert_target_emoji(self, target_id: int) -> Union[Emoji, Object]: return self._state.get_emoji(target_id) or Object(id=target_id, type=Emoji) def _convert_target_message(self, target_id: Optional[int]) -> Optional[Union[Member, User, Object]]: - # The message_pin and message_unpin action types do not have a + # The message_pin and message_unpin action types do not have a # non-null target_id so safeguard against that if target_id is None: From 4c62e651019e9e92c55dad816190a6fa088e6182 Mon Sep 17 00:00:00 2001 From: iyad-f <128908811+iyad-f@users.noreply.github.com> Date: Sun, 26 Jan 2025 01:04:27 +0530 Subject: [PATCH 6/7] run black --- discord/audit_logs.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/discord/audit_logs.py b/discord/audit_logs.py index cbd88527e1a8..c3497821af03 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -285,11 +285,9 @@ def __repr__(self) -> str: if TYPE_CHECKING: - def __getattr__(self, item: str) -> Any: - ... + def __getattr__(self, item: str) -> Any: ... - def __setattr__(self, key: str, value: Any) -> Any: - ... + def __setattr__(self, key: str, value: Any) -> Any: ... Transformer = Callable[["AuditLogEntry", Any], Any] @@ -875,7 +873,7 @@ def _convert_target_emoji(self, target_id: int) -> Union[Emoji, Object]: return self._state.get_emoji(target_id) or Object(id=target_id, type=Emoji) def _convert_target_message(self, target_id: Optional[int]) -> Optional[Union[Member, User, Object]]: - # The message_pin and message_unpin action types do not have a + # The message_pin and message_unpin action types do not have a # non-null target_id so safeguard against that if target_id is None: From 1a9cbce6982ced22e178df9a76ed911c602fe752 Mon Sep 17 00:00:00 2001 From: iyad-f <128908811+iyad-f@users.noreply.github.com> Date: Sun, 26 Jan 2025 01:11:12 +0530 Subject: [PATCH 7/7] run black --- discord/audit_logs.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/discord/audit_logs.py b/discord/audit_logs.py index c3497821af03..af67855d4584 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -285,9 +285,11 @@ def __repr__(self) -> str: if TYPE_CHECKING: - def __getattr__(self, item: str) -> Any: ... + def __getattr__(self, item: str) -> Any: + ... - def __setattr__(self, key: str, value: Any) -> Any: ... + def __setattr__(self, key: str, value: Any) -> Any: + ... Transformer = Callable[["AuditLogEntry", Any], Any]