diff options
| author | Rapptz <[email protected]> | 2015-09-19 18:41:14 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2015-09-19 18:42:19 -0400 |
| commit | 9559f02f9593265454d443cfa7f2e1ab9b465d19 (patch) | |
| tree | fef66662794cbbfa626e75822f8453946edbbede | |
| parent | Remove duplicated create_channel function. (diff) | |
| download | discord.py-9559f02f9593265454d443cfa7f2e1ab9b465d19.tar.xz discord.py-9559f02f9593265454d443cfa7f2e1ab9b465d19.zip | |
accept_invite now works on some invite URLs.
| -rw-r--r-- | discord/client.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/discord/client.py b/discord/client.py index ddf9de84..71a2a618 100644 --- a/discord/client.py +++ b/discord/client.py @@ -762,13 +762,27 @@ class Client(object): log.debug(request_logging_format.format(response=response, name='create_invite')) def accept_invite(self, invite): - """Accepts an :class:`Invite`. + """Accepts an :class:`Invite` or a URL to an invite. - :param invite: The :class:`Invite` to accept. + The URL must be a discord.gg URL. e.g. "http://discord.gg/codehere" + + :param invite: The :class:`Invite` or URL to an invite to accept. :returns: True if the invite was successfully accepted, False otherwise. """ - url = '{0}/invite/{1.id}'.format(endpoints.API_BASE, invite) + destination = None + if isinstance(invite, Invite): + destination = invite.id + else: + rx = r'(?:https?\:\/\/)?discord\.gg\/(.+)' + m = re.match(rx, invite) + if m: + destination = m.group(1) + + if destination is None: + return False + + url = '{0}/invite/{1}'.format(endpoints.API_BASE, destination) response = requests.post(url, headers=self.headers) log.debug(request_logging_format.format(response=response, name='accept_invite')) return response.status_code in (200, 201) |