Support unavailable servers.
This commit is contained in:
@ -202,6 +202,8 @@ class ConnectionState(object):
|
||||
guilds = data.get('guilds')
|
||||
|
||||
for guild in guilds:
|
||||
if guild.get('unavailable', False):
|
||||
continue
|
||||
self._add_server(guild)
|
||||
|
||||
for pm in data.get('private_channels'):
|
||||
@ -327,10 +329,33 @@ class ConnectionState(object):
|
||||
self.dispatch('member_update', member)
|
||||
|
||||
def handle_guild_create(self, data):
|
||||
if data.get('unavailable') is not None:
|
||||
# GUILD_CREATE with unavailable in the response
|
||||
# usually means that the server has become available
|
||||
# and is therefore in the cache
|
||||
server = self._get_server(data.get('id'))
|
||||
if server is not None:
|
||||
server.unavailable = False
|
||||
self.dispatch('server_available', server)
|
||||
return
|
||||
|
||||
# if we're at this point then it was probably
|
||||
# unavailable during the READY event and is now
|
||||
# available, so it isn't in the cache...
|
||||
|
||||
self._add_server(data)
|
||||
self.dispatch('server_create', self.servers[-1])
|
||||
|
||||
def handle_guild_delete(self, data):
|
||||
if data.get('unavailable', False):
|
||||
# GUILD_DELETE with unavailable being True means that the
|
||||
# server that was available is now currently unavailable
|
||||
server = self._get_server(data.get('id'))
|
||||
if server is not None:
|
||||
server.unavailable = True
|
||||
self.dispatch('server_unavailable', server)
|
||||
return
|
||||
|
||||
server = self._get_server(data.get('id'))
|
||||
self.servers.remove(server)
|
||||
self.dispatch('server_delete', server)
|
||||
|
@ -136,6 +136,13 @@ class Server(object):
|
||||
.. attribute:: owner
|
||||
|
||||
The :class:`Member` who owns the server.
|
||||
.. attribute:: unavailable
|
||||
|
||||
A boolean indicating if the server is unavailable. If this is ``True`` then the
|
||||
reliability of other attributes outside of :meth:`Server.id` is slim and they might
|
||||
all be None. It is best to not do anything with the server if it is unavailable.
|
||||
|
||||
Check the :func:`on_server_unavailable` and :func:`on_server_available` events.
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
@ -148,6 +155,7 @@ class Server(object):
|
||||
self.icon = kwargs.get('icon')
|
||||
self.id = kwargs.get('id')
|
||||
self.owner = kwargs.get('owner')
|
||||
self.unavailable = kwargs.get('unavailable', False)
|
||||
|
||||
def get_default_role(self):
|
||||
"""Gets the @everyone role that all members have by default."""
|
||||
|
Reference in New Issue
Block a user