Browse Source

Handle GUILD_ROLE_UPDATE websocket events.

pull/24/head
Rapptz 10 years ago
parent
commit
4ff7d22edd
  1. 13
      discord/client.py
  2. 3
      discord/server.py
  3. 6
      docs/api.rst

13
discord/client.py

@ -114,7 +114,8 @@ class WebSocket(WebSocketBaseClient):
'CHANNEL_DELETE', 'CHANNEL_UPDATE', 'CHANNEL_CREATE',
'GUILD_MEMBER_ADD', 'GUILD_MEMBER_REMOVE',
'GUILD_MEMBER_UPDATE', 'GUILD_CREATE', 'GUILD_DELETE',
'GUILD_ROLE_CREATE', 'GUILD_ROLE_DELETE'):
'GUILD_ROLE_CREATE', 'GUILD_ROLE_DELETE',
'GUILD_ROLE_UPDATE'):
self.dispatch('socket_update', event, data)
else:
@ -321,7 +322,15 @@ class ConnectionState(object):
role_id = data.get('role_id')
role = utils.find(lambda r: r.id == role_id, server.roles)
server.roles.remove(role)
self.dispatch('server_role_delete', server, role)
self.dispatch('server_role_delete', server, role)
def handle_guild_role_update(self, data):
server = self._get_server(data.get('guild_id'))
if server is not None:
role_id = data['role']['id']
role = utils.find(lambda r: r.id == role_id, server.roles)
role.update(**data['role'])
self.dispatch('server_role_update', role)
def get_channel(self, id):
if id is None:

3
discord/server.py

@ -55,6 +55,9 @@ class Role(object):
"""
def __init__(self, **kwargs):
self.update(**kwargs)
def update(self, **kwargs):
self.id = kwargs.get('id')
self.name = kwargs.get('name')
self.permissions = Permissions(kwargs.get('permissions', 0))

6
docs/api.rst

@ -168,6 +168,12 @@ to handle it, which defaults to log a traceback and ignore the exception.
:param server: The :class:`Server` that was created or deleted.
:param role: The :class:`Role` that was created or deleted.
.. function:: on_server_role_update(role)
Called when a :class:`Role` is changed server-wide.
:param role: The :class:`Role` that was updated.
Utility Functions
-----------------

Loading…
Cancel
Save