aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-08-23 23:37:41 -0400
committerRapptz <[email protected]>2015-08-23 23:37:56 -0400
commit35084cf98a1d861361c17009df3db30aabf1244a (patch)
tree5ee14e9d882070b53f22d29eb7efe082a180a412
parentFix setuputils script (diff)
downloaddiscord.py-35084cf98a1d861361c17009df3db30aabf1244a.tar.xz
discord.py-35084cf98a1d861361c17009df3db30aabf1244a.zip
Add support for channel creation events.
-rw-r--r--discord/client.py18
-rw-r--r--docs/api.rst7
-rw-r--r--setup.py7
3 files changed, 25 insertions, 7 deletions
diff --git a/discord/client.py b/discord/client.py
index ca5bd80d..714fd045 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -97,7 +97,7 @@ class Client(object):
'on_message_edit': _null_event,
'on_status': _null_event,
'on_channel_delete': _null_event,
- 'on_channel_creation': _null_event,
+ 'on_channel_create': _null_event,
}
self.ws = WebSocketClient(endpoints.WEBSOCKET_HUB, protocols=['http-only', 'chat'])
@@ -214,8 +214,22 @@ class Client(object):
channel = next((c for c in server.channels if c.id == channel_id), None)
server.channels.remove(channel)
self._invoke_event('on_channel_delete', channel)
+ elif event == 'CHANNEL_CREATE':
+ is_private = data.get('is_private', False)
+ channel = None
+ if is_private:
+ recipient = User(**data.get('recipient'))
+ pm_id = data.get('id')
+ channel = PrivateChannel(id=pm_id, user=recipient)
+ self.private_channels.append(channel)
+ else:
+ guild_id = data.get('guild_id')
+ server = next((s for s in self.servers if s.id == guild_id), None)
+ if server is not None:
+ channel = Channel(server=server, **data)
+ server.channels.append(channel)
-
+ self._invoke_event('on_channel_create', channel)
def _opened(self):
print('Opened at {}'.format(int(time.time())))
diff --git a/docs/api.rst b/docs/api.rst
index 79a58cd8..9909bcd1 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -64,12 +64,15 @@ All events are 'sandboxed', in that if an exception is thrown while the event is
:param game_id: The game ID that the user is playing. Can be None.
.. function:: on_channel_delete(channel)
+ on_channel_create(channel)
- Called whenever a channel is removed from a server.
+ Called whenever a channel is removed or added from a server.
Note that you can get the server from :attr:`Channel.server`.
+ :func:`on_channel_create` could also pass in a :class:`PrivateChannel` depending
+ on the value of :attr:`Channel.is_private`.
- :param channel: The :class:`Channel` that got deleted.
+ :param channel: The :class:`Channel` that got added or deleted.
Data Classes
--------------
diff --git a/setup.py b/setup.py
index 20245d04..a76f466f 100644
--- a/setup.py
+++ b/setup.py
@@ -1,9 +1,10 @@
from setuptools import setup
import re
-requirements = ''
-with open('requirements.txt') as f:
- requirements = f.read().splitlines()
+requirements = [
+ 'ws4py',
+ 'requests'
+]
version = ''
with open('discord/__init__.py') as f: