Browse Source

Audit log role add and removes are lists, not single item.

Breaking change. role -> roles and it's now a list.
pull/572/head
Rapptz 8 years ago
parent
commit
7916878eb5
  1. 25
      discord/audit_logs.py
  2. 8
      docs/api.rst

25
discord/audit_logs.py

@ -121,10 +121,10 @@ class AuditLogChanges:
# special cases for role add/remove
if attr == '$add':
self._handle_role(self.before, self.after, entry, elem)
self._handle_role(self.before, self.after, entry, elem['new_value'])
continue
elif attr == '$remove':
self._handle_role(self.after, self.before, entry, elem)
self._handle_role(self.after, self.before, entry, elem['new_value'])
continue
transformer = self.TRANSFORMERS.get(attr)
@ -157,17 +157,22 @@ class AuditLogChanges:
self.before.color = self.before.colour
def _handle_role(self, first, second, entry, elem):
setattr(first, 'role', None)
setattr(first, 'roles', None)
# TODO: partial data?
role_id = int(elem['id'])
role = utils.find(lambda r: r.id == role_id, entry.guild.roles)
data = []
roles = entry.guild.roles
if role is None:
role = discord.Object(id=role_id)
role.name = elem['name']
for e in elem:
role_id = int(e['id'])
role = utils.find(lambda r: r.id == role_id, roles)
if role is None:
role = discord.Object(id=role_id)
role.name = e['name']
data.append(role)
setattr(second, 'role', role)
setattr(second, 'roles', data)
class AuditLogEntry:
"""Represents an Audit Log entry.

8
docs/api.rst

@ -915,7 +915,7 @@ All enumerations are subclasses of `enum`_.
Possible attributes for :class:`AuditLogDiff`:
- :attr:`~AuditLogDiff.role`
- :attr:`~AuditLogDiff.roles`
.. attribute:: role_create
@ -1375,12 +1375,12 @@ this goal, it must make use of a couple of data classes that aid in this goal.
a ``type`` attribute set to either ``'role'`` or ``'member'`` to help
decide what type of ID it is.
.. attribute:: role
.. attribute:: roles
*Union[:class:`Role`, :class:`Object`]* – A role being added or removed
*List[Union[:class:`Role`, :class:`Object`]]* – A list of roles being added or removed
from a member.
If the role is not found then it is a :class:`Object` with the ID being
If a role is not found then it is a :class:`Object` with the ID being
filled in.
.. attribute:: nick

Loading…
Cancel
Save