aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-09-19 18:41:14 -0400
committerRapptz <[email protected]>2015-09-19 18:42:19 -0400
commit9559f02f9593265454d443cfa7f2e1ab9b465d19 (patch)
treefef66662794cbbfa626e75822f8453946edbbede
parentRemove duplicated create_channel function. (diff)
downloaddiscord.py-9559f02f9593265454d443cfa7f2e1ab9b465d19.tar.xz
discord.py-9559f02f9593265454d443cfa7f2e1ab9b465d19.zip
accept_invite now works on some invite URLs.
-rw-r--r--discord/client.py20
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)