mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-10 07:49:48 +00:00
Begin working on gateway v6 changes.
The first batch of changes are related to channel types and group direct messages. Support these first so READY begins parsing.
This commit is contained in:
parent
e977bddc1f
commit
ddd3fd0a3d
@ -30,6 +30,7 @@ from .enums import ChannelType
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from .mixins import Hashable
|
from .mixins import Hashable
|
||||||
from .role import Role
|
from .role import Role
|
||||||
|
from .user import User
|
||||||
from .member import Member
|
from .member import Member
|
||||||
|
|
||||||
Overwrites = namedtuple('Overwrites', 'id allow deny type')
|
Overwrites = namedtuple('Overwrites', 'id allow deny type')
|
||||||
@ -298,24 +299,68 @@ class PrivateChannel(Hashable):
|
|||||||
|
|
||||||
Attributes
|
Attributes
|
||||||
----------
|
----------
|
||||||
user : :class:`User`
|
recipients: list of :class:`User`
|
||||||
The user you are participating with in the private channel.
|
The users you are participating with in the private channel.
|
||||||
id : str
|
id: str
|
||||||
The private channel ID.
|
The private channel ID.
|
||||||
is_private : bool
|
is_private: bool
|
||||||
``True`` if the channel is a private channel (i.e. PM). ``True`` in this case.
|
``True`` if the channel is a private channel (i.e. PM). ``True`` in this case.
|
||||||
|
type: :class:`ChannelType`
|
||||||
|
The type of private channel.
|
||||||
|
owner: Optional[:class:`User`]
|
||||||
|
The user that owns the private channel. If the channel type is not
|
||||||
|
:attr:`ChannelType.group` then this is always ``None``.
|
||||||
|
icon: Optional[str]
|
||||||
|
The private channel's icon hash. If the channel type is not
|
||||||
|
:attr:`ChannelType.group` then this is always ``None``.
|
||||||
|
name: Optional[str]
|
||||||
|
The private channel's name. If the channel type is not
|
||||||
|
:attr:`ChannelType.group` then this is always ``None``.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ['user', 'id', 'is_private']
|
__slots__ = ['id', 'is_private', 'recipients', 'type', 'owner', 'icon', 'name']
|
||||||
|
|
||||||
def __init__(self, user, id, **kwargs):
|
def __init__(self, me, **kwargs):
|
||||||
self.user = user
|
self.recipients = [User(**u) for u in kwargs['recipients']]
|
||||||
self.id = id
|
self.id = kwargs['id']
|
||||||
self.is_private = True
|
self.is_private = True
|
||||||
|
self.type = ChannelType(kwargs['type'])
|
||||||
|
|
||||||
|
owner_id = kwargs.get('owner_id')
|
||||||
|
self.owner = None
|
||||||
|
self.icon = kwargs.get('icon')
|
||||||
|
self.name = kwargs.get('name')
|
||||||
|
|
||||||
|
self.recipients = []
|
||||||
|
for data in kwargs['recipients']:
|
||||||
|
to_add = User(**data)
|
||||||
|
if to_add.id == owner_id:
|
||||||
|
self.owner = to_add
|
||||||
|
self.recipients.append(to_add)
|
||||||
|
|
||||||
|
if owner_id == me.id:
|
||||||
|
self.owner = me
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'Direct Message with {0.name}'.format(self.user)
|
return 'Direct Message with {0.name}'.format(self.user)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user(self):
|
||||||
|
"""A property that returns the first recipient of the private channel.
|
||||||
|
|
||||||
|
This is mainly for compatibility and ease of use with old style private
|
||||||
|
channels that had a single recipient.
|
||||||
|
"""
|
||||||
|
return self.recipients[0]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon_url(self):
|
||||||
|
"""Returns the channel's icon URL if available or an empty string otherwise."""
|
||||||
|
if self.icon is None:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
return 'https://cdn.discordapp.com/channel-icons/{0.id}/{0.icon}.jpg'.format(self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def created_at(self):
|
def created_at(self):
|
||||||
"""Returns the private channel's creation time in UTC."""
|
"""Returns the private channel's creation time in UTC."""
|
||||||
@ -332,7 +377,9 @@ class PrivateChannel(Hashable):
|
|||||||
|
|
||||||
- send_tts_messages: You cannot send TTS messages in a PM.
|
- send_tts_messages: You cannot send TTS messages in a PM.
|
||||||
- manage_messages: You cannot delete others messages in a PM.
|
- manage_messages: You cannot delete others messages in a PM.
|
||||||
- mention_everyone: There is no one to mention in a PM.
|
|
||||||
|
This also handles permissions for :attr:`ChannelType.group` channels
|
||||||
|
such as kicking or mentioning everyone.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
-----------
|
-----------
|
||||||
@ -348,7 +395,11 @@ class PrivateChannel(Hashable):
|
|||||||
base = Permissions.text()
|
base = Permissions.text()
|
||||||
base.send_tts_messages = False
|
base.send_tts_messages = False
|
||||||
base.manage_messages = False
|
base.manage_messages = False
|
||||||
base.mention_everyone = False
|
base.mention_everyone = self.type is ChannelType.group
|
||||||
|
|
||||||
|
if user == self.owner:
|
||||||
|
base.kick_members = True
|
||||||
|
|
||||||
return base
|
return base
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,11 +27,13 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
class ChannelType(Enum):
|
class ChannelType(Enum):
|
||||||
text = 'text'
|
text = 0
|
||||||
voice = 'voice'
|
private = 1
|
||||||
|
voice = 2
|
||||||
|
group = 3
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.value
|
return self.name
|
||||||
|
|
||||||
class ServerRegion(Enum):
|
class ServerRegion(Enum):
|
||||||
us_west = 'us-west'
|
us_west = 'us-west'
|
||||||
|
@ -98,7 +98,7 @@ class VoiceKeepAliveHandler(KeepAliveHandler):
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
||||||
"""Implements a WebSocket for Discord's gateway v4.
|
"""Implements a WebSocket for Discord's gateway v6.
|
||||||
|
|
||||||
This is created through :func:`create_main_websocket`. Library
|
This is created through :func:`create_main_websocket`. Library
|
||||||
users should never create this manually.
|
users should never create this manually.
|
||||||
|
@ -53,7 +53,7 @@ class HTTPClient:
|
|||||||
"""Represents an HTTP client sending HTTP requests to the Discord API."""
|
"""Represents an HTTP client sending HTTP requests to the Discord API."""
|
||||||
|
|
||||||
BASE = 'https://discordapp.com'
|
BASE = 'https://discordapp.com'
|
||||||
API_BASE = BASE + '/api'
|
API_BASE = BASE + '/api/v6'
|
||||||
GATEWAY = API_BASE + '/gateway'
|
GATEWAY = API_BASE + '/gateway'
|
||||||
USERS = API_BASE + '/users'
|
USERS = API_BASE + '/users'
|
||||||
ME = USERS + '/@me'
|
ME = USERS + '/@me'
|
||||||
@ -500,4 +500,4 @@ class HTTPClient:
|
|||||||
data = yield from self.get(self.GATEWAY, bucket=_func_())
|
data = yield from self.get(self.GATEWAY, bucket=_func_())
|
||||||
except HTTPException as e:
|
except HTTPException as e:
|
||||||
raise GatewayNotFound() from e
|
raise GatewayNotFound() from e
|
||||||
return data.get('url') + '?encoding=json&v=5'
|
return data.get('url') + '?encoding=json&v=6'
|
||||||
|
@ -205,8 +205,7 @@ class ConnectionState:
|
|||||||
servers.append(server)
|
servers.append(server)
|
||||||
|
|
||||||
for pm in data.get('private_channels'):
|
for pm in data.get('private_channels'):
|
||||||
self._add_private_channel(PrivateChannel(id=pm['id'],
|
self._add_private_channel(PrivateChannel(self.user, **pm))
|
||||||
user=User(**pm['recipient'])))
|
|
||||||
|
|
||||||
compat.create_task(self._delay_ready(), loop=self.loop)
|
compat.create_task(self._delay_ready(), loop=self.loop)
|
||||||
|
|
||||||
@ -303,9 +302,7 @@ class ConnectionState:
|
|||||||
is_private = data.get('is_private', False)
|
is_private = data.get('is_private', False)
|
||||||
channel = None
|
channel = None
|
||||||
if is_private:
|
if is_private:
|
||||||
recipient = User(**data.get('recipient'))
|
channel = PrivateChannel(self.user, **data)
|
||||||
pm_id = data.get('id')
|
|
||||||
channel = PrivateChannel(id=pm_id, user=recipient)
|
|
||||||
self._add_private_channel(channel)
|
self._add_private_channel(channel)
|
||||||
else:
|
else:
|
||||||
server = self._get_server(data.get('guild_id'))
|
server = self._get_server(data.get('guild_id'))
|
||||||
|
@ -391,6 +391,12 @@ All enumerations are subclasses of `enum`_.
|
|||||||
.. attribute:: voice
|
.. attribute:: voice
|
||||||
|
|
||||||
A voice channel.
|
A voice channel.
|
||||||
|
.. attribute:: private
|
||||||
|
|
||||||
|
A private text channel. Also called a direct message.
|
||||||
|
.. attribute:: group
|
||||||
|
|
||||||
|
A private group text channel.
|
||||||
|
|
||||||
.. class:: ServerRegion
|
.. class:: ServerRegion
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user