Provide server/channel id/name as Object if client not joined to server.
This commit is contained in:
parent
39988a36c9
commit
0176517453
@ -1160,8 +1160,9 @@ class Client(object):
|
|||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
If the server attribute of the returned invite is ``None`` then that means
|
If the invite is for a server you have not joined, the server and channel
|
||||||
that you have not joined the server.
|
attributes of the returned invite will be :class:`Object` with the names
|
||||||
|
patched in.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -1172,10 +1173,17 @@ class Client(object):
|
|||||||
utils._verify_successful_response(response)
|
utils._verify_successful_response(response)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
server = self.connection._get_server(data['guild']['id'])
|
server = self.connection._get_server(data['guild']['id'])
|
||||||
|
if server is not None:
|
||||||
|
ch_id = data['channel']['id']
|
||||||
|
channels = getattr(server, 'channels', [])
|
||||||
|
channel = utils.find(lambda c: c.id == ch_id, channels)
|
||||||
|
else:
|
||||||
|
server = Object(id=data['guild']['id'])
|
||||||
|
server.name = data['guild']['name']
|
||||||
|
channel = Object(id=data['channel']['id'])
|
||||||
|
channel.name = data['channel']['name']
|
||||||
data['server'] = server
|
data['server'] = server
|
||||||
ch_id = data['channel']['id']
|
data['channel'] = channel
|
||||||
channels = getattr(server, 'channels', [])
|
|
||||||
data['channel'] = utils.find(lambda c: c.id == ch_id, channels)
|
|
||||||
return Invite(**data)
|
return Invite(**data)
|
||||||
|
|
||||||
def accept_invite(self, invite):
|
def accept_invite(self, invite):
|
||||||
@ -1458,4 +1466,3 @@ class Client(object):
|
|||||||
sent = json.dumps(payload)
|
sent = json.dumps(payload)
|
||||||
log.debug('Sending "{}" to change status'.format(sent))
|
log.debug('Sending "{}" to change status'.format(sent))
|
||||||
self.ws.send(sent)
|
self.ws.send(sent)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user