diff options
| author | Rapptz <[email protected]> | 2015-12-29 01:18:28 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2015-12-29 01:18:28 -0500 |
| commit | 2cd1ec30662ebb487c70730d8f2d115cd55928df (patch) | |
| tree | bdde044b04510fc14d30814e663c4e70c4741f32 | |
| parent | Client.get_invite now works without a websocket connection (diff) | |
| download | discord.py-2cd1ec30662ebb487c70730d8f2d115cd55928df.tar.xz discord.py-2cd1ec30662ebb487c70730d8f2d115cd55928df.zip | |
Client.create_invite now works without a websocket connection
| -rw-r--r-- | discord/client.py | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/discord/client.py b/discord/client.py index 157b2986..0f8df2d5 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1738,6 +1738,22 @@ class Client: # Invite management + def _fill_invite_data(self, data): + server = None + if self.connection is not None: + 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['channel'] = channel + @asyncio.coroutine def create_invite(self, destination, **options): """|coro| @@ -1786,10 +1802,7 @@ class Client: yield from utils._verify_successful_response(response) data = yield from response.json() log.debug(request_success_log.format(json=payload, response=response, data=data)) - - data['server'] = self.connection._get_server(data['guild']['id']) - channel_id = data['channel']['id'] - data['channel'] = utils.find(lambda ch: ch.id == channel_id, data['server'].channels) + self._fill_invite_data(data) return Invite(**data) @asyncio.coroutine @@ -1828,20 +1841,7 @@ class Client: log.debug(request_logging_format.format(method='GET', response=response)) yield from utils._verify_successful_response(response) data = yield from response.json() - server = None - if self.connection is not None: - 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['channel'] = channel + self._fill_invite_data(data) return Invite(**data) @asyncio.coroutine |