Rename internal ConnectionState attribute to have an underscore.
Some people like to use that variable name apparently. See #568 and #569.
This commit is contained in:
parent
9cbbd8af65
commit
df90aaa610
@ -110,13 +110,13 @@ class Client:
|
|||||||
connector = options.pop('connector', None)
|
connector = options.pop('connector', None)
|
||||||
self.http = HTTPClient(connector, loop=self.loop)
|
self.http = HTTPClient(connector, loop=self.loop)
|
||||||
|
|
||||||
self.connection = ConnectionState(dispatch=self.dispatch, chunker=self._chunker,
|
self._connection = ConnectionState(dispatch=self.dispatch, chunker=self._chunker,
|
||||||
syncer=self._syncer, http=self.http, loop=self.loop, **options)
|
syncer=self._syncer, http=self.http, loop=self.loop, **options)
|
||||||
|
|
||||||
self.connection.shard_count = self.shard_count
|
self._connection.shard_count = self.shard_count
|
||||||
self._closed = asyncio.Event(loop=self.loop)
|
self._closed = asyncio.Event(loop=self.loop)
|
||||||
self._ready = asyncio.Event(loop=self.loop)
|
self._ready = asyncio.Event(loop=self.loop)
|
||||||
self.connection._get_websocket = lambda g: self.ws
|
self._connection._get_websocket = lambda g: self.ws
|
||||||
|
|
||||||
if VoiceClient.warn_nacl:
|
if VoiceClient.warn_nacl:
|
||||||
VoiceClient.warn_nacl = False
|
VoiceClient.warn_nacl = False
|
||||||
@ -162,22 +162,22 @@ class Client:
|
|||||||
@property
|
@property
|
||||||
def user(self):
|
def user(self):
|
||||||
"""Optional[:class:`ClientUser`]: Represents the connected client. None if not logged in."""
|
"""Optional[:class:`ClientUser`]: Represents the connected client. None if not logged in."""
|
||||||
return self.connection.user
|
return self._connection.user
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def guilds(self):
|
def guilds(self):
|
||||||
"""List[:class:`Guild`]: The guilds that the connected client is a member of."""
|
"""List[:class:`Guild`]: The guilds that the connected client is a member of."""
|
||||||
return self.connection.guilds
|
return self._connection.guilds
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def emojis(self):
|
def emojis(self):
|
||||||
"""List[:class:`Emoji`]: The emojis that the connected client has."""
|
"""List[:class:`Emoji`]: The emojis that the connected client has."""
|
||||||
return self.connection.emojis
|
return self._connection.emojis
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def private_channels(self):
|
def private_channels(self):
|
||||||
"""List[:class:`abc.PrivateChannel`]: The private channels that the connected client is participating on."""
|
"""List[:class:`abc.PrivateChannel`]: The private channels that the connected client is participating on."""
|
||||||
return self.connection.private_channels
|
return self._connection.private_channels
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def messages(self):
|
def messages(self):
|
||||||
@ -187,12 +187,12 @@ class Client:
|
|||||||
The number of messages stored in this deque is controlled by the
|
The number of messages stored in this deque is controlled by the
|
||||||
``max_messages`` parameter.
|
``max_messages`` parameter.
|
||||||
"""
|
"""
|
||||||
return self.connection.messages
|
return self._connection.messages
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def voice_clients(self):
|
def voice_clients(self):
|
||||||
"""List[:class:`VoiceClient`]: Represents a list of voice connections."""
|
"""List[:class:`VoiceClient`]: Represents a list of voice connections."""
|
||||||
return self.connection.voice_clients
|
return self._connection.voice_clients
|
||||||
|
|
||||||
def is_ready(self):
|
def is_ready(self):
|
||||||
"""bool: Specifies if the client's internal cache is ready for use."""
|
"""bool: Specifies if the client's internal cache is ready for use."""
|
||||||
@ -298,7 +298,7 @@ class Client:
|
|||||||
if any(not g.large or g.unavailable for g in guilds):
|
if any(not g.large or g.unavailable for g in guilds):
|
||||||
raise InvalidArgument('An unavailable or non-large guild was passed.')
|
raise InvalidArgument('An unavailable or non-large guild was passed.')
|
||||||
|
|
||||||
yield from self.connection.request_offline_members(guilds)
|
yield from self._connection.request_offline_members(guilds)
|
||||||
|
|
||||||
# login state management
|
# login state management
|
||||||
|
|
||||||
@ -331,7 +331,7 @@ class Client:
|
|||||||
|
|
||||||
log.info('logging in using static token')
|
log.info('logging in using static token')
|
||||||
yield from self.http.static_login(token, bot=bot)
|
yield from self.http.static_login(token, bot=bot)
|
||||||
self.connection.is_bot = bot
|
self._connection.is_bot = bot
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def logout(self):
|
def logout(self):
|
||||||
@ -516,26 +516,26 @@ class Client:
|
|||||||
@property
|
@property
|
||||||
def users(self):
|
def users(self):
|
||||||
"""Returns a list of all the :class:`User` the bot can see."""
|
"""Returns a list of all the :class:`User` the bot can see."""
|
||||||
return list(self.connection._users.values())
|
return list(self._connection._users.values())
|
||||||
|
|
||||||
def get_channel(self, id):
|
def get_channel(self, id):
|
||||||
"""Returns a :class:`abc.GuildChannel` or :class:`abc.PrivateChannel` with the following ID.
|
"""Returns a :class:`abc.GuildChannel` or :class:`abc.PrivateChannel` with the following ID.
|
||||||
|
|
||||||
If not found, returns None.
|
If not found, returns None.
|
||||||
"""
|
"""
|
||||||
return self.connection.get_channel(id)
|
return self._connection.get_channel(id)
|
||||||
|
|
||||||
def get_guild(self, id):
|
def get_guild(self, id):
|
||||||
"""Returns a :class:`Guild` with the given ID. If not found, returns None."""
|
"""Returns a :class:`Guild` with the given ID. If not found, returns None."""
|
||||||
return self.connection._get_guild(id)
|
return self._connection._get_guild(id)
|
||||||
|
|
||||||
def get_user(self, id):
|
def get_user(self, id):
|
||||||
"""Returns a :class:`User` with the given ID. If not found, returns None."""
|
"""Returns a :class:`User` with the given ID. If not found, returns None."""
|
||||||
return self.connection.get_user(id)
|
return self._connection.get_user(id)
|
||||||
|
|
||||||
def get_emoji(self, id):
|
def get_emoji(self, id):
|
||||||
"""Returns a :class:`Emoji` with the given ID. If not found, returns None."""
|
"""Returns a :class:`Emoji` with the given ID. If not found, returns None."""
|
||||||
return self.connection.get_emoji(id)
|
return self._connection.get_emoji(id)
|
||||||
|
|
||||||
def get_all_channels(self):
|
def get_all_channels(self):
|
||||||
"""A generator that retrieves every :class:`Channel` the client can 'access'.
|
"""A generator that retrieves every :class:`Channel` the client can 'access'.
|
||||||
@ -742,7 +742,7 @@ class Client:
|
|||||||
|
|
||||||
yield from self.ws.change_presence(game=game, status=status, afk=afk)
|
yield from self.ws.change_presence(game=game, status=status, afk=afk)
|
||||||
|
|
||||||
for guild in self.connection.guilds:
|
for guild in self._connection.guilds:
|
||||||
me = guild.me
|
me = guild.me
|
||||||
if me is None:
|
if me is None:
|
||||||
continue
|
continue
|
||||||
@ -793,7 +793,7 @@ class Client:
|
|||||||
region = region.value
|
region = region.value
|
||||||
|
|
||||||
data = yield from self.http.create_guild(name, region, icon)
|
data = yield from self.http.create_guild(name, region, icon)
|
||||||
return Guild(data=data, state=self.connection)
|
return Guild(data=data, state=self._connection)
|
||||||
|
|
||||||
# Invite management
|
# Invite management
|
||||||
|
|
||||||
@ -829,7 +829,7 @@ class Client:
|
|||||||
|
|
||||||
invite_id = self._resolve_invite(url)
|
invite_id = self._resolve_invite(url)
|
||||||
data = yield from self.http.get_invite(invite_id)
|
data = yield from self.http.get_invite(invite_id)
|
||||||
return Invite.from_incomplete(state=self.connection, data=data)
|
return Invite.from_incomplete(state=self._connection, data=data)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def delete_invite(self, invite):
|
def delete_invite(self, invite):
|
||||||
@ -879,7 +879,7 @@ class Client:
|
|||||||
data = yield from self.http.application_info()
|
data = yield from self.http.application_info()
|
||||||
return AppInfo(id=data['id'], name=data['name'],
|
return AppInfo(id=data['id'], name=data['name'],
|
||||||
description=data['description'], icon=data['icon'],
|
description=data['description'], icon=data['icon'],
|
||||||
owner=User(state=self.connection, data=data['owner']))
|
owner=User(state=self._connection, data=data['owner']))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def get_user_info(self, user_id):
|
def get_user_info(self, user_id):
|
||||||
@ -908,7 +908,7 @@ class Client:
|
|||||||
Fetching the user failed.
|
Fetching the user failed.
|
||||||
"""
|
"""
|
||||||
data = yield from self.http.get_user_info(user_id)
|
data = yield from self.http.get_user_info(user_id)
|
||||||
return User(state=self.connection, data=data)
|
return User(state=self._connection, data=data)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def get_user_profile(self, user_id):
|
def get_user_profile(self, user_id):
|
||||||
@ -934,7 +934,7 @@ class Client:
|
|||||||
The profile of the user.
|
The profile of the user.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
state = self.connection
|
state = self._connection
|
||||||
data = yield from self.http.get_user_profile(user_id)
|
data = yield from self.http.get_user_profile(user_id)
|
||||||
|
|
||||||
def transform(d):
|
def transform(d):
|
||||||
|
@ -195,15 +195,15 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
|
|
||||||
# dynamically add attributes needed
|
# dynamically add attributes needed
|
||||||
ws.token = client.http.token
|
ws.token = client.http.token
|
||||||
ws._connection = client.connection
|
ws._connection = client._connection
|
||||||
ws._dispatch = client.dispatch
|
ws._dispatch = client.dispatch
|
||||||
ws.gateway = gateway
|
ws.gateway = gateway
|
||||||
ws.shard_id = shard_id
|
ws.shard_id = shard_id
|
||||||
ws.shard_count = client.connection.shard_count
|
ws.shard_count = client._connection.shard_count
|
||||||
ws.session_id = session
|
ws.session_id = session
|
||||||
ws.sequence = sequence
|
ws.sequence = sequence
|
||||||
|
|
||||||
client.connection._update_references(ws)
|
client._connection._update_references(ws)
|
||||||
|
|
||||||
log.info('Created websocket connected to {}'.format(gateway))
|
log.info('Created websocket connected to {}'.format(gateway))
|
||||||
|
|
||||||
|
@ -115,8 +115,8 @@ class AutoShardedClient(Client):
|
|||||||
elif not isinstance(self.shard_ids, (list, tuple)):
|
elif not isinstance(self.shard_ids, (list, tuple)):
|
||||||
raise ClientException('shard_ids parameter must be a list or a tuple.')
|
raise ClientException('shard_ids parameter must be a list or a tuple.')
|
||||||
|
|
||||||
self.connection = AutoShardedConnectionState(dispatch=self.dispatch, chunker=self._chunker,
|
self._connection = AutoShardedConnectionState(dispatch=self.dispatch, chunker=self._chunker,
|
||||||
syncer=self._syncer, http=self.http, loop=self.loop, **kwargs)
|
syncer=self._syncer, http=self.http, loop=self.loop, **kwargs)
|
||||||
|
|
||||||
# instead of a single websocket, we have multiple
|
# instead of a single websocket, we have multiple
|
||||||
# the key is the shard_id
|
# the key is the shard_id
|
||||||
@ -126,7 +126,7 @@ class AutoShardedClient(Client):
|
|||||||
i = (guild_id >> 22) % self.shard_count
|
i = (guild_id >> 22) % self.shard_count
|
||||||
return self.shards[i].ws
|
return self.shards[i].ws
|
||||||
|
|
||||||
self.connection._get_websocket = _get_websocket
|
self._connection._get_websocket = _get_websocket
|
||||||
self._still_sharding = True
|
self._still_sharding = True
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -179,7 +179,7 @@ class AutoShardedClient(Client):
|
|||||||
_guilds = sorted(guilds, key=lambda g: g.shard_id)
|
_guilds = sorted(guilds, key=lambda g: g.shard_id)
|
||||||
for shard_id, sub_guilds in itertools.groupby(_guilds, key=lambda g: g.shard_id):
|
for shard_id, sub_guilds in itertools.groupby(_guilds, key=lambda g: g.shard_id):
|
||||||
sub_guilds = list(sub_guilds)
|
sub_guilds = list(sub_guilds)
|
||||||
yield from self.connection.request_offline_members(sub_guilds, shard_id=shard_id)
|
yield from self._connection.request_offline_members(sub_guilds, shard_id=shard_id)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def pending_reads(self, shard):
|
def pending_reads(self, shard):
|
||||||
@ -199,7 +199,7 @@ class AutoShardedClient(Client):
|
|||||||
return (yield from self.launch_shard(gateway, shard_id))
|
return (yield from self.launch_shard(gateway, shard_id))
|
||||||
|
|
||||||
ws.token = self.http.token
|
ws.token = self.http.token
|
||||||
ws._connection = self.connection
|
ws._connection = self._connection
|
||||||
ws._dispatch = self.dispatch
|
ws._dispatch = self.dispatch
|
||||||
ws.gateway = gateway
|
ws.gateway = gateway
|
||||||
ws.shard_id = shard_id
|
ws.shard_id = shard_id
|
||||||
@ -226,7 +226,7 @@ class AutoShardedClient(Client):
|
|||||||
else:
|
else:
|
||||||
gateway = yield from self.http.get_gateway()
|
gateway = yield from self.http.get_gateway()
|
||||||
|
|
||||||
self.connection.shard_count = self.shard_count
|
self._connection.shard_count = self.shard_count
|
||||||
|
|
||||||
shard_ids = self.shard_ids if self.shard_ids else range(self.shard_count)
|
shard_ids = self.shard_ids if self.shard_ids else range(self.shard_count)
|
||||||
|
|
||||||
@ -312,11 +312,11 @@ class AutoShardedClient(Client):
|
|||||||
for shard in self.shards.values():
|
for shard in self.shards.values():
|
||||||
yield from shard.ws.change_presence(game=game, status=status, afk=afk)
|
yield from shard.ws.change_presence(game=game, status=status, afk=afk)
|
||||||
|
|
||||||
guilds = self.connection.guilds
|
guilds = self._connection.guilds
|
||||||
else:
|
else:
|
||||||
shard = self.shards[shard_id]
|
shard = self.shards[shard_id]
|
||||||
yield from shard.ws.change_presence(game=game, status=status, afk=afk)
|
yield from shard.ws.change_presence(game=game, status=status, afk=afk)
|
||||||
guilds = [g for g in self.connection.guilds if g.shard_id == shard_id]
|
guilds = [g for g in self._connection.guilds if g.shard_id == shard_id]
|
||||||
|
|
||||||
for guild in guilds:
|
for guild in guilds:
|
||||||
me = guild.me
|
me = guild.me
|
||||||
|
Loading…
x
Reference in New Issue
Block a user