Browse Source

Fix issue with roles being passed in being strings.

Client.add_roles and Client.remove_roles would dispatch to the
Client.replace_roles function. However, replace_roles expects Role
objects while the dispatching involved string IDs. So as a result this
needed another layer of dispatch into a _replace_roles function to do
the actual call that all three of them dispatch to.
pull/60/head
Rapptz 9 years ago
parent
commit
7d08a07cb9
  1. 29
      discord/client.py

29
discord/client.py

@ -1967,6 +1967,19 @@ class Client:
yield from utils._verify_successful_response(response)
yield from response.release()
@asyncio.coroutine
def _replace_roles(self, member, *roles):
url = '{0}/{1.server.id}/members/{1.id}'.format(endpoints.SERVERS, member)
payload = {
'roles': list(roles)
}
r = yield from aiohttp.patch(url, headers=self.headers, data=utils.to_json(payload), loop=self.loop)
log.debug(request_logging_format.format(method='PATCH', response=r))
yield from utils._verify_successful_response(r)
yield from r.release()
@asyncio.coroutine
def add_roles(self, member, *roles):
"""|coro|
@ -1994,7 +2007,7 @@ class Client:
"""
new_roles = [role.id for role in itertools.chain(member.roles, roles)]
yield from self.replace_roles(member, *new_roles)
yield from self._replace_roles(member, *new_roles)
@asyncio.coroutine
def remove_roles(self, member, *roles):
@ -2022,7 +2035,7 @@ class Client:
"""
new_roles = {role.id for role in member.roles}
new_roles = new_roles.difference(roles)
yield from self.replace_roles(member, *new_roles)
yield from self._replace_roles(member, *new_roles)
@asyncio.coroutine
def replace_roles(self, member, *roles):
@ -2054,16 +2067,8 @@ class Client:
Removing roles failed.
"""
url = '{0}/{1.server.id}/members/{1.id}'.format(endpoints.SERVERS, member)
payload = {
'roles': [role.id for role in roles]
}
r = yield from aiohttp.patch(url, headers=self.headers, data=utils.to_json(payload), loop=self.loop)
log.debug(request_logging_format.format(method='PATCH', response=r))
yield from utils._verify_successful_response(r)
yield from r.release()
new_roles = [role.id for role in roles]
yield from self._replace_roles(member, *new_roles)
@asyncio.coroutine
def create_role(self, server, **fields):

Loading…
Cancel
Save