Browse Source

Add new audit log entry types. Fix issue with unknown entry types

pull/2471/head
Josh B 5 years ago
committed by Rapptz
parent
commit
7df5effbb7
  1. 19
      discord/audit_logs.py
  2. 72
      discord/enums.py
  3. 89
      docs/api.rst

19
discord/audit_logs.py

@ -227,17 +227,32 @@ class AuditLogEntry:
self.reason = data.get('reason')
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:
# member prune has two keys with useful information
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'])
elems = {
'count': int(self.extra['count']),
'channel': self.guild.get_channel(channel_id) or Object(id=channel_id)
}
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_'):
# the overwrite_ actions have a dict with some information
instance_id = int(self.extra['id'])

72
discord/enums.py

@ -298,6 +298,9 @@ class AuditLogAction(Enum):
unban = 23
member_update = 24
member_role_update = 25
member_move = 26
member_disconnect = 27
bot_add = 28
role_create = 30
role_update = 31
role_delete = 32
@ -311,36 +314,51 @@ class AuditLogAction(Enum):
emoji_update = 61
emoji_delete = 62
message_delete = 72
message_bulk_delete = 73
message_pin = 74
message_unpin = 75
integration_create = 80
integration_update = 81
integration_delete = 82
@property
def category(self):
lookup = {
AuditLogAction.guild_update: AuditLogActionCategory.update,
AuditLogAction.channel_create: AuditLogActionCategory.create,
AuditLogAction.channel_update: AuditLogActionCategory.update,
AuditLogAction.channel_delete: AuditLogActionCategory.delete,
AuditLogAction.overwrite_create: AuditLogActionCategory.create,
AuditLogAction.overwrite_update: AuditLogActionCategory.update,
AuditLogAction.overwrite_delete: AuditLogActionCategory.delete,
AuditLogAction.kick: None,
AuditLogAction.member_prune: None,
AuditLogAction.ban: None,
AuditLogAction.unban: None,
AuditLogAction.member_update: AuditLogActionCategory.update,
AuditLogAction.member_role_update: AuditLogActionCategory.update,
AuditLogAction.role_create: AuditLogActionCategory.create,
AuditLogAction.role_update: AuditLogActionCategory.update,
AuditLogAction.role_delete: AuditLogActionCategory.delete,
AuditLogAction.invite_create: AuditLogActionCategory.create,
AuditLogAction.invite_update: AuditLogActionCategory.update,
AuditLogAction.invite_delete: AuditLogActionCategory.delete,
AuditLogAction.webhook_create: AuditLogActionCategory.create,
AuditLogAction.webhook_update: AuditLogActionCategory.update,
AuditLogAction.webhook_delete: AuditLogActionCategory.delete,
AuditLogAction.emoji_create: AuditLogActionCategory.create,
AuditLogAction.emoji_update: AuditLogActionCategory.update,
AuditLogAction.emoji_delete: AuditLogActionCategory.delete,
AuditLogAction.message_delete: AuditLogActionCategory.delete,
AuditLogAction.guild_update: AuditLogActionCategory.update,
AuditLogAction.channel_create: AuditLogActionCategory.create,
AuditLogAction.channel_update: AuditLogActionCategory.update,
AuditLogAction.channel_delete: AuditLogActionCategory.delete,
AuditLogAction.overwrite_create: AuditLogActionCategory.create,
AuditLogAction.overwrite_update: AuditLogActionCategory.update,
AuditLogAction.overwrite_delete: AuditLogActionCategory.delete,
AuditLogAction.kick: None,
AuditLogAction.member_prune: None,
AuditLogAction.ban: None,
AuditLogAction.unban: None,
AuditLogAction.member_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_update: AuditLogActionCategory.update,
AuditLogAction.role_delete: AuditLogActionCategory.delete,
AuditLogAction.invite_create: AuditLogActionCategory.create,
AuditLogAction.invite_update: AuditLogActionCategory.update,
AuditLogAction.invite_delete: AuditLogActionCategory.delete,
AuditLogAction.webhook_create: AuditLogActionCategory.create,
AuditLogAction.webhook_update: AuditLogActionCategory.update,
AuditLogAction.webhook_delete: AuditLogActionCategory.delete,
AuditLogAction.emoji_create: AuditLogActionCategory.create,
AuditLogAction.emoji_update: AuditLogActionCategory.update,
AuditLogAction.emoji_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]
@ -365,6 +383,8 @@ class AuditLogAction(Enum):
return 'emoji'
elif v < 80:
return 'message'
elif v < 90:
return 'integration'
class UserFlags(Enum):
staff = 1

89
docs/api.rst

@ -1254,6 +1254,34 @@ of :class:`enum.Enum`.
- :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
A new role was created.
@ -1422,8 +1450,7 @@ of :class:`enum.Enum`.
.. attribute:: message_delete
A message was deleted by a moderator. Note that this
only triggers if the message was deleted by either bulk delete
or deletion by someone other than the author.
only triggers if the message was deleted by someone other than the author.
When this is the action, the type of :attr:`~AuditLogEntry.target` is
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.
- ``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

Loading…
Cancel
Save