Skip to content

Commit

Permalink
feat(auditlog): support integration_type field (#1096)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv authored Sep 5, 2023
1 parent 6689bb6 commit 1f871ff
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog/1096.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support ``integration_type`` field in :attr:`AuditLogEntry.extra` (for :attr:`~AuditLogAction.kick` and :attr:`~AuditLogAction.member_role_update` actions).
18 changes: 14 additions & 4 deletions disnake/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"),
Expand All @@ -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")
Expand All @@ -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":
Expand Down Expand Up @@ -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:
Expand All @@ -672,6 +681,7 @@ def _from_data(self, data: AuditLogEntryPayload) -> None:
# _AuditLogProxyPinAction,
# _AuditLogProxyStageInstanceAction,
# _AuditLogProxyAutoModAction,
# _AuditLogProxyKickOrMemberRoleAction,
# Member, User, None,
# Role,
# ]
Expand Down
3 changes: 3 additions & 0 deletions disnake/types/audit_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions docs/api/audit_logs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit 1f871ff

Please sign in to comment.