Add new audit log entry types. Fix issue with unknown entry types
This commit is contained in:
parent
4ef0fb0d95
commit
7df5effbb7
@ -227,17 +227,32 @@ class AuditLogEntry:
|
|||||||
self.reason = data.get('reason')
|
self.reason = data.get('reason')
|
||||||
self.extra = data.get('options')
|
self.extra = data.get('options')
|
||||||
|
|
||||||
if self.extra:
|
if isinstance(self.action, enums.AuditLogAction) and self.extra:
|
||||||
if self.action is enums.AuditLogAction.member_prune:
|
if self.action is enums.AuditLogAction.member_prune:
|
||||||
# member prune has two keys with useful information
|
# member prune has two keys with useful information
|
||||||
self.extra = type('_AuditLogProxy', (), {k: int(v) for k, v in self.extra.items()})()
|
self.extra = type('_AuditLogProxy', (), {k: int(v) for k, v in self.extra.items()})()
|
||||||
elif self.action is enums.AuditLogAction.message_delete:
|
elif self.action is enums.AuditLogAction.member_move or self.action is enums.AuditLogAction.message_delete:
|
||||||
channel_id = int(self.extra['channel_id'])
|
channel_id = int(self.extra['channel_id'])
|
||||||
elems = {
|
elems = {
|
||||||
'count': int(self.extra['count']),
|
'count': int(self.extra['count']),
|
||||||
'channel': self.guild.get_channel(channel_id) or Object(id=channel_id)
|
'channel': self.guild.get_channel(channel_id) or Object(id=channel_id)
|
||||||
}
|
}
|
||||||
self.extra = type('_AuditLogProxy', (), elems)()
|
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(self.extra['count']),
|
||||||
|
}
|
||||||
|
self.extra = type('_AuditLogProxy', (), elems)()
|
||||||
|
elif self.action.name.endswith('pin'):
|
||||||
|
# the pin actions have a dict with some information
|
||||||
|
channel_id = int(self.extra['channel_id'])
|
||||||
|
message_id = int(self.extra['message_id'])
|
||||||
|
elems = {
|
||||||
|
'channel': self.guild.get_channel(channel_id) or Object(id=channel_id),
|
||||||
|
'message_id': message_id
|
||||||
|
}
|
||||||
|
self.extra = type('_AuditLogProxy', (), elems)()
|
||||||
elif self.action.name.startswith('overwrite_'):
|
elif self.action.name.startswith('overwrite_'):
|
||||||
# the overwrite_ actions have a dict with some information
|
# the overwrite_ actions have a dict with some information
|
||||||
instance_id = int(self.extra['id'])
|
instance_id = int(self.extra['id'])
|
||||||
|
@ -298,6 +298,9 @@ class AuditLogAction(Enum):
|
|||||||
unban = 23
|
unban = 23
|
||||||
member_update = 24
|
member_update = 24
|
||||||
member_role_update = 25
|
member_role_update = 25
|
||||||
|
member_move = 26
|
||||||
|
member_disconnect = 27
|
||||||
|
bot_add = 28
|
||||||
role_create = 30
|
role_create = 30
|
||||||
role_update = 31
|
role_update = 31
|
||||||
role_delete = 32
|
role_delete = 32
|
||||||
@ -311,6 +314,12 @@ class AuditLogAction(Enum):
|
|||||||
emoji_update = 61
|
emoji_update = 61
|
||||||
emoji_delete = 62
|
emoji_delete = 62
|
||||||
message_delete = 72
|
message_delete = 72
|
||||||
|
message_bulk_delete = 73
|
||||||
|
message_pin = 74
|
||||||
|
message_unpin = 75
|
||||||
|
integration_create = 80
|
||||||
|
integration_update = 81
|
||||||
|
integration_delete = 82
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def category(self):
|
def category(self):
|
||||||
@ -328,6 +337,9 @@ class AuditLogAction(Enum):
|
|||||||
AuditLogAction.unban: None,
|
AuditLogAction.unban: None,
|
||||||
AuditLogAction.member_update: AuditLogActionCategory.update,
|
AuditLogAction.member_update: AuditLogActionCategory.update,
|
||||||
AuditLogAction.member_role_update: AuditLogActionCategory.update,
|
AuditLogAction.member_role_update: AuditLogActionCategory.update,
|
||||||
|
AuditLogAction.member_move: None,
|
||||||
|
AuditLogAction.member_disconnect: None,
|
||||||
|
AuditLogAction.bot_add: None,
|
||||||
AuditLogAction.role_create: AuditLogActionCategory.create,
|
AuditLogAction.role_create: AuditLogActionCategory.create,
|
||||||
AuditLogAction.role_update: AuditLogActionCategory.update,
|
AuditLogAction.role_update: AuditLogActionCategory.update,
|
||||||
AuditLogAction.role_delete: AuditLogActionCategory.delete,
|
AuditLogAction.role_delete: AuditLogActionCategory.delete,
|
||||||
@ -341,6 +353,12 @@ class AuditLogAction(Enum):
|
|||||||
AuditLogAction.emoji_update: AuditLogActionCategory.update,
|
AuditLogAction.emoji_update: AuditLogActionCategory.update,
|
||||||
AuditLogAction.emoji_delete: AuditLogActionCategory.delete,
|
AuditLogAction.emoji_delete: AuditLogActionCategory.delete,
|
||||||
AuditLogAction.message_delete: AuditLogActionCategory.delete,
|
AuditLogAction.message_delete: AuditLogActionCategory.delete,
|
||||||
|
AuditLogAction.message_bulk_delete: AuditLogActionCategory.delete,
|
||||||
|
AuditLogAction.message_pin: None,
|
||||||
|
AuditLogAction.message_unpin: None,
|
||||||
|
AuditLogAction.integration_create: AuditLogActionCategory.create,
|
||||||
|
AuditLogAction.integration_update: AuditLogActionCategoty.update,
|
||||||
|
AuditLogAction.integration_delete: AuditLogActionCategory.delete,
|
||||||
}
|
}
|
||||||
return lookup[self]
|
return lookup[self]
|
||||||
|
|
||||||
@ -365,6 +383,8 @@ class AuditLogAction(Enum):
|
|||||||
return 'emoji'
|
return 'emoji'
|
||||||
elif v < 80:
|
elif v < 80:
|
||||||
return 'message'
|
return 'message'
|
||||||
|
elif v < 90:
|
||||||
|
return 'integration'
|
||||||
|
|
||||||
class UserFlags(Enum):
|
class UserFlags(Enum):
|
||||||
staff = 1
|
staff = 1
|
||||||
|
89
docs/api.rst
89
docs/api.rst
@ -1254,6 +1254,34 @@ of :class:`enum.Enum`.
|
|||||||
|
|
||||||
- :attr:`~AuditLogDiff.roles`
|
- :attr:`~AuditLogDiff.roles`
|
||||||
|
|
||||||
|
.. attribute:: member_move
|
||||||
|
|
||||||
|
A member's voice channel has been updated. This triggers when a
|
||||||
|
member is moved to a different voice channel.
|
||||||
|
|
||||||
|
When this is the action, the type of :attr:`~AuditLogEntry.extra` is
|
||||||
|
set to an unspecified proxy object with two attributes:
|
||||||
|
|
||||||
|
- ``channel``: A :class:`TextChannel` or :class:`Object` with the channel ID where the members were moved.
|
||||||
|
- ``count``: An integer specifying how many members were moved.
|
||||||
|
|
||||||
|
.. attribute:: member_disconnect
|
||||||
|
|
||||||
|
A member's voice state has changed. This triggers when a
|
||||||
|
member is force disconnected from voice.
|
||||||
|
|
||||||
|
When this is the action, the type of :attr:`~AuditLogEntry.extra` is
|
||||||
|
set to an unspecified proxy object with one attribute:
|
||||||
|
|
||||||
|
- ``count``: An integer specifying how many members were disconnected.
|
||||||
|
|
||||||
|
.. attribute:: bot_add
|
||||||
|
|
||||||
|
A bot was added to the guild.
|
||||||
|
|
||||||
|
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||||
|
the :class:`Member` or :class:`User` which was added to the guild.
|
||||||
|
|
||||||
.. attribute:: role_create
|
.. attribute:: role_create
|
||||||
|
|
||||||
A new role was created.
|
A new role was created.
|
||||||
@ -1422,8 +1450,7 @@ of :class:`enum.Enum`.
|
|||||||
.. attribute:: message_delete
|
.. attribute:: message_delete
|
||||||
|
|
||||||
A message was deleted by a moderator. Note that this
|
A message was deleted by a moderator. Note that this
|
||||||
only triggers if the message was deleted by either bulk delete
|
only triggers if the message was deleted by someone other than the author.
|
||||||
or deletion by someone other than the author.
|
|
||||||
|
|
||||||
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||||
the :class:`Member` or :class:`User` who had their message deleted.
|
the :class:`Member` or :class:`User` who had their message deleted.
|
||||||
@ -1434,6 +1461,64 @@ of :class:`enum.Enum`.
|
|||||||
- ``count``: An integer specifying how many messages were deleted.
|
- ``count``: An integer specifying how many messages were deleted.
|
||||||
- ``channel``: A :class:`TextChannel` or :class:`Object` with the channel ID where the message got deleted.
|
- ``channel``: A :class:`TextChannel` or :class:`Object` with the channel ID where the message got deleted.
|
||||||
|
|
||||||
|
.. attribute:: message_bulk_delete
|
||||||
|
|
||||||
|
Messages were bulk deleted by a moderator.
|
||||||
|
|
||||||
|
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||||
|
the :class:`TextChannel` or :class:`Object` with the ID of the channel that was purged.
|
||||||
|
|
||||||
|
When this is the action, the type of :attr:`~AuditLogEntry.extra` is
|
||||||
|
set to an unspecified proxy object with one attribute:
|
||||||
|
|
||||||
|
- ``count``: An integer specifying how many messages were deleted.
|
||||||
|
|
||||||
|
.. attribute:: message_pin
|
||||||
|
|
||||||
|
A message was pinned in a channel.
|
||||||
|
|
||||||
|
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||||
|
the :class:`Member` or :class:`User` who had their message pinned.
|
||||||
|
|
||||||
|
When this is the action, the type of :attr:`~AuditLogEntry.extra` is
|
||||||
|
set to an unspecified proxy object with two attributes:
|
||||||
|
|
||||||
|
- ``channel``: A :class:`TextChannel` or :class:`Object` with the channel ID where the message was pinned.
|
||||||
|
- ``message_id``: the ID of the message which was pinned.
|
||||||
|
|
||||||
|
.. attribute:: message_unpin
|
||||||
|
|
||||||
|
A message was unpinned in a channel.
|
||||||
|
|
||||||
|
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||||
|
the :class:`Member` or :class:`User` who had their message unpinned.
|
||||||
|
|
||||||
|
When this is the action, the type of :attr:`~AuditLogEntry.extra` is
|
||||||
|
set to an unspecified proxy object with two attributes:
|
||||||
|
|
||||||
|
- ``channel``: A :class:`TextChannel` or :class:`Object` with the channel ID where the message was unpinned.
|
||||||
|
- ``message_id``: the ID of the message which was unpinned.
|
||||||
|
|
||||||
|
.. attribute:: integration_create
|
||||||
|
|
||||||
|
A guild integration was created.
|
||||||
|
|
||||||
|
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||||
|
the :class:`Object` with the integration ID of the integration which was created.
|
||||||
|
|
||||||
|
.. attribute:: integration_update
|
||||||
|
|
||||||
|
A guild integration was updated.
|
||||||
|
|
||||||
|
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||||
|
the :class:`Object` with the integration ID of the integration which was updated.
|
||||||
|
|
||||||
|
.. attribute:: integration_delete
|
||||||
|
|
||||||
|
A guild integration was deleted.
|
||||||
|
|
||||||
|
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||||
|
the :class:`Object` with the integration ID of the integration which was deleted.
|
||||||
|
|
||||||
.. class:: AuditLogActionCategory
|
.. class:: AuditLogActionCategory
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user