Handle GUILD_ROLE_CREATE websocket events.

This commit is contained in:
Rapptz 2015-10-14 21:09:31 -04:00
parent 4ec052a35c
commit 9235a34916
2 changed files with 15 additions and 1 deletions

View File

@ -113,7 +113,8 @@ class WebSocket(WebSocketBaseClient):
'MESSAGE_UPDATE', 'PRESENCE_UPDATE', 'USER_UPDATE',
'CHANNEL_DELETE', 'CHANNEL_UPDATE', 'CHANNEL_CREATE',
'GUILD_MEMBER_ADD', 'GUILD_MEMBER_REMOVE',
'GUILD_MEMBER_UPDATE', 'GUILD_CREATE', 'GUILD_DELETE'):
'GUILD_MEMBER_UPDATE', 'GUILD_CREATE', 'GUILD_DELETE',
'GUILD_ROLE_CREATE'):
self.dispatch('socket_update', event, data)
else:
@ -308,6 +309,12 @@ class ConnectionState(object):
self.servers.remove(server)
self.dispatch('server_delete', server)
def handle_guild_role_create(self, data):
server = self._get_server(data.get('guild_id'))
role = Role(**data.get('role', {}))
server.roles.append(role)
self.dispatch('server_role_create', server, role)
def get_channel(self, id):
if id is None:
return None

View File

@ -160,6 +160,13 @@ to handle it, which defaults to log a traceback and ignore the exception.
:param server: The :class:`Server` that got created or deleted.
.. function:: on_server_role_create(server, role)
Called when a :class:`Server` creates a new :class:`Role`.
:param server: The :class:`Server` that was created.
:param role: The :class:`Role` that was created.
Utility Functions
-----------------