From 1f871ff51f9583881b2ad51a6a9aa0d70dafe9dd Mon Sep 17 00:00:00 2001 From: shiftinv <8530778+shiftinv@users.noreply.github.com> Date: Tue, 5 Sep 2023 17:35:27 +0200 Subject: [PATCH] feat(auditlog): support `integration_type` field (#1096) --- changelog/1096.feature.rst | 1 + disnake/audit_logs.py | 18 ++++++++++++++---- disnake/types/audit_log.py | 3 +++ docs/api/audit_logs.rst | 10 ++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 changelog/1096.feature.rst diff --git a/changelog/1096.feature.rst b/changelog/1096.feature.rst new file mode 100644 index 0000000000..5cddd33cc8 --- /dev/null +++ b/changelog/1096.feature.rst @@ -0,0 +1 @@ +Support ``integration_type`` field in :attr:`AuditLogEntry.extra` (for :attr:`~AuditLogAction.kick` and :attr:`~AuditLogAction.member_role_update` actions). diff --git a/disnake/audit_logs.py b/disnake/audit_logs.py index d1e2760bb9..02aad706ee 100644 --- a/disnake/audit_logs.py +++ b/disnake/audit_logs.py @@ -507,6 +507,10 @@ class _AuditLogProxyAutoModAction: rule_trigger_type: enums.AutoModTriggerType +class _AuditLogProxyKickOrMemberRoleAction: + integration_type: Optional[str] + + class AuditLogEntry(Hashable): """Represents an Audit Log entry. @@ -589,7 +593,6 @@ def _from_data(self, data: AuditLogEntryPayload) -> None: if isinstance(self.action, enums.AuditLogAction) and extra: if self.action is enums.AuditLogAction.member_prune: - # member prune has two keys with useful information elems = { "delete_member_days": utils._get_as_snowflake(extra, "delete_member_days"), "members_removed": utils._get_as_snowflake(extra, "members_removed"), @@ -607,13 +610,11 @@ def _from_data(self, data: AuditLogEntryPayload) -> None: } self.extra = type("_AuditLogProxy", (), elems)() elif self.action is enums.AuditLogAction.member_disconnect: - # The member disconnect action has a dict with some information elems = { "count": int(extra["count"]), } self.extra = type("_AuditLogProxy", (), elems)() elif self.action.name.endswith("pin"): - # the pin actions have a dict with some information elems = { "channel": self._get_channel_or_thread( utils._get_as_snowflake(extra, "channel_id") @@ -622,7 +623,6 @@ def _from_data(self, data: AuditLogEntryPayload) -> None: } self.extra = type("_AuditLogProxy", (), elems)() elif self.action.name.startswith("overwrite_"): - # the overwrite_ actions have a dict with some information instance_id = int(extra["id"]) the_type = extra.get("type") if the_type == "1": @@ -662,6 +662,15 @@ def _from_data(self, data: AuditLogEntryPayload) -> None: ), } self.extra = type("_AuditLogProxy", (), elems)() + elif self.action in ( + enums.AuditLogAction.kick, + enums.AuditLogAction.member_role_update, + ): + elems = { + # unlike other extras, this key isn't always provided + "integration_type": extra.get("integration_type"), + } + self.extra = type("_AuditLogProxy", (), elems)() self.extra: Any # actually this but there's no reason to annoy users with this: @@ -672,6 +681,7 @@ def _from_data(self, data: AuditLogEntryPayload) -> None: # _AuditLogProxyPinAction, # _AuditLogProxyStageInstanceAction, # _AuditLogProxyAutoModAction, + # _AuditLogProxyKickOrMemberRoleAction, # Member, User, None, # Role, # ] diff --git a/disnake/types/audit_log.py b/disnake/types/audit_log.py index cca0c0fec0..d3b3a5484f 100644 --- a/disnake/types/audit_log.py +++ b/disnake/types/audit_log.py @@ -300,6 +300,8 @@ class _AuditLogChange_AutoModTriggerMetadata(TypedDict): ] +# All of these are technically only required for matching event types, +# but they're typed as required keys for simplicity class AuditEntryInfo(TypedDict): delete_member_days: str members_removed: str @@ -312,6 +314,7 @@ class AuditEntryInfo(TypedDict): application_id: Snowflake auto_moderation_rule_name: str auto_moderation_rule_trigger_type: str + integration_type: str class AuditLogEntry(TypedDict): diff --git a/docs/api/audit_logs.rst b/docs/api/audit_logs.rst index ba1f735587..8e98685c24 100644 --- a/docs/api/audit_logs.rst +++ b/docs/api/audit_logs.rst @@ -919,6 +919,11 @@ AuditLogAction the :class:`User` who got kicked. If the user is not found then it is a :class:`Object` with the user's ID. + When this is the action, the type of :attr:`~AuditLogEntry.extra` may be + set to an unspecified proxy object with one attribute: + + - ``integration_type``: A string representing the type of the integration which performed the action, if any. + When this is the action, :attr:`~AuditLogEntry.changes` is empty. .. attribute:: member_prune @@ -984,6 +989,11 @@ AuditLogAction the :class:`Member` or :class:`User` who got the role. If the user is not found then it is a :class:`Object` with the user's ID. + When this is the action, the type of :attr:`~AuditLogEntry.extra` may be + set to an unspecified proxy object with one attribute: + + - ``integration_type``: A string representing the type of the integration which performed the action, if any. + Possible attributes for :class:`AuditLogDiff`: - :attr:`~AuditLogDiff.roles`