mirror of
				https://github.com/Rapptz/discord.py.git
				synced 2025-10-25 10:32:59 +00:00 
			
		
		
		
	Client.register now takes an invite URL or class.
This commit is contained in:
		| @@ -398,6 +398,16 @@ class Client(object): | |||||||
|         else: |         else: | ||||||
|             return [] |             return [] | ||||||
|  |  | ||||||
|  |     def _resolve_invite(self, invite): | ||||||
|  |         if isinstance(invite, Invite): | ||||||
|  |             return invite.id | ||||||
|  |         else: | ||||||
|  |             rx = r'(?:https?\:\/\/)?discord\.gg\/(.+)' | ||||||
|  |             m = re.match(rx, invite) | ||||||
|  |             if m: | ||||||
|  |                 return m.group(1) | ||||||
|  |         return None | ||||||
|  |  | ||||||
|     def on_error(self, event_method, *args, **kwargs): |     def on_error(self, event_method, *args, **kwargs): | ||||||
|         msg = 'Caught exception in {} with args (*{}, **{})' |         msg = 'Caught exception in {} with args (*{}, **{})' | ||||||
|         log.exception(msg.format(event_method, args, kwargs)) |         log.exception(msg.format(event_method, args, kwargs)) | ||||||
| @@ -630,14 +640,14 @@ class Client(object): | |||||||
|         occur. |         occur. | ||||||
|  |  | ||||||
|         :param str username: The username to register as. |         :param str username: The username to register as. | ||||||
|         :param str invite: The invite to register with. |         :param invite: An invite URL or :class:`Invite` to register with. | ||||||
|         :param str fingerprint: Unkown API parameter, defaults to None |         :param str fingerprint: Unkown API parameter, defaults to None | ||||||
|         """ |         """ | ||||||
|  |  | ||||||
|         payload = { |         payload = { | ||||||
|             'fingerprint': fingerprint, |             'fingerprint': fingerprint, | ||||||
|             'username': username, |             'username': username, | ||||||
|             'invite': invite |             'invite': self._resolve_invite(invite) | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         r = requests.post(endpoints.REGISTER, json=payload) |         r = requests.post(endpoints.REGISTER, json=payload) | ||||||
| @@ -919,14 +929,7 @@ class Client(object): | |||||||
|         :returns: True if the invite was successfully accepted, False otherwise. |         :returns: True if the invite was successfully accepted, False otherwise. | ||||||
|         """ |         """ | ||||||
|  |  | ||||||
|         destination = None |         destination = self._resolve_invite(invite) | ||||||
|         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: |         if destination is None: | ||||||
|             return False |             return False | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user