mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 20:28:38 +00:00
Add support for channel creation events.
This commit is contained in:
parent
9b99834221
commit
35084cf98a
@ -97,7 +97,7 @@ class Client(object):
|
|||||||
'on_message_edit': _null_event,
|
'on_message_edit': _null_event,
|
||||||
'on_status': _null_event,
|
'on_status': _null_event,
|
||||||
'on_channel_delete': _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'])
|
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)
|
channel = next((c for c in server.channels if c.id == channel_id), None)
|
||||||
server.channels.remove(channel)
|
server.channels.remove(channel)
|
||||||
self._invoke_event('on_channel_delete', 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):
|
def _opened(self):
|
||||||
print('Opened at {}'.format(int(time.time())))
|
print('Opened at {}'.format(int(time.time())))
|
||||||
|
@ -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.
|
:param game_id: The game ID that the user is playing. Can be None.
|
||||||
|
|
||||||
.. function:: on_channel_delete(channel)
|
.. 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`.
|
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
|
Data Classes
|
||||||
--------------
|
--------------
|
||||||
|
7
setup.py
7
setup.py
@ -1,9 +1,10 @@
|
|||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
import re
|
import re
|
||||||
|
|
||||||
requirements = ''
|
requirements = [
|
||||||
with open('requirements.txt') as f:
|
'ws4py',
|
||||||
requirements = f.read().splitlines()
|
'requests'
|
||||||
|
]
|
||||||
|
|
||||||
version = ''
|
version = ''
|
||||||
with open('discord/__init__.py') as f:
|
with open('discord/__init__.py') as f:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user