Browse Source

Listen to CHANNEL_UPDATE events and add on_channel_update

pull/8/head
Rapptz 10 years ago
parent
commit
120b9cd3b2
  1. 3
      discord/channel.py
  2. 8
      discord/client.py
  3. 6
      docs/api.rst

3
discord/channel.py

@ -59,6 +59,9 @@ class Channel(object):
"""
def __init__(self, **kwargs):
self.update(**kwargs)
def update(self, **kwargs):
self.name = kwargs.get('name')
self.server = kwargs.get('server')
self.id = kwargs.get('id')

8
discord/client.py

@ -114,6 +114,7 @@ class Client(object):
'on_status': _null_event,
'on_channel_delete': _null_event,
'on_channel_create': _null_event,
'on_channel_update': _null_event,
'on_member_join': _null_event,
'on_member_remove': _null_event,
'on_member_update': _null_event,
@ -265,6 +266,13 @@ class Client(object):
channel = utils.find(lambda c: c.id == channel_id, server.channels)
server.channels.remove(channel)
self._invoke_event('on_channel_delete', channel)
elif event == 'CHANNEL_UPDATE':
server = self._get_server(data.get('guild_id'))
if server is not None:
channel_id = data.get('id')
channel = utils.find(lambda c: c.id == channel_id, server.channels)
channel.update(server=server, **data)
self._invoke_event('on_channel_update', channel)
elif event == 'CHANNEL_CREATE':
is_private = data.get('is_private', False)
channel = None

6
docs/api.rst

@ -86,6 +86,12 @@ All events are 'sandboxed', in that if an exception is thrown while the event is
:param channel: The :class:`Channel` that got added or deleted.
.. function:: on_channel_update(channel)
Called whenever a channel is updated. e.g. changed name, topic, permissions.
:param channel: The :class:`Channel` that got updated.
.. function:: on_member_join(member)
on_member_remove(member)

Loading…
Cancel
Save