Change handling of different request types and callback for 204 requests (nickname change).
This commit is contained in:
parent
26a804ca1f
commit
4d153d1971
1 changed files with 5 additions and 16 deletions
|
|
@ -352,16 +352,7 @@ class DiscordClient(WebSocketClientProtocol, _BASE_SESSION_CLASS):
|
||||||
"""
|
"""
|
||||||
url = f"{DISCORD_API_BASE_URL}/{url}"
|
url = f"{DISCORD_API_BASE_URL}/{url}"
|
||||||
body = FileBodyProducer(BytesIO(json.dumps(data).encode("utf-8")))
|
body = FileBodyProducer(BytesIO(json.dumps(data).encode("utf-8")))
|
||||||
is_patch_request = kwargs.pop("patch", False)
|
request_type = kwargs.pop("type", b"POST")
|
||||||
is_put_request = kwargs.pop("put", False)
|
|
||||||
request_type = "POST"
|
|
||||||
|
|
||||||
if is_patch_request:
|
|
||||||
request_type = b"PATCH"
|
|
||||||
elif is_put_request:
|
|
||||||
request_type = b"PUT"
|
|
||||||
else:
|
|
||||||
request_type = b"POST"
|
|
||||||
|
|
||||||
d = _AGENT.request(
|
d = _AGENT.request(
|
||||||
request_type,
|
request_type,
|
||||||
|
|
@ -377,13 +368,11 @@ class DiscordClient(WebSocketClientProtocol, _BASE_SESSION_CLASS):
|
||||||
)
|
)
|
||||||
|
|
||||||
def cbResponse(response):
|
def cbResponse(response):
|
||||||
if response.code == 200:
|
logger.log_info(response.code)
|
||||||
|
if response.code == 200 or response.code == 204:
|
||||||
d = readBody(response)
|
d = readBody(response)
|
||||||
d.addCallback(self.post_response)
|
d.addCallback(self.post_response)
|
||||||
return d
|
return d
|
||||||
elif response.code == 204:
|
|
||||||
d = readBody(response)
|
|
||||||
d.addCallback(self.post_response)
|
|
||||||
elif should_retry(response.code):
|
elif should_retry(response.code):
|
||||||
delay(300, self._post_json, url, data, **kwargs)
|
delay(300, self._post_json, url, data, **kwargs)
|
||||||
|
|
||||||
|
|
@ -510,12 +499,12 @@ class DiscordClient(WebSocketClientProtocol, _BASE_SESSION_CLASS):
|
||||||
|
|
||||||
data = {"nick": text}
|
data = {"nick": text}
|
||||||
data.update(kwargs)
|
data.update(kwargs)
|
||||||
self._post_json(f"guilds/{guild_id}/members/{user_id}", data, patch=True)
|
self._post_json(f"guilds/{guild_id}/members/{user_id}", data, type=b"PATCH")
|
||||||
|
|
||||||
def send_role(self, role_id, guild_id, user_id, **kwargs):
|
def send_role(self, role_id, guild_id, user_id, **kwargs):
|
||||||
|
|
||||||
data = kwargs
|
data = kwargs
|
||||||
self._post_json(f"guilds/{guild_id}/members/{user_id}/roles/{role_id}", data, put=True)
|
self._post_json(f"guilds/{guild_id}/members/{user_id}/roles/{role_id}", data, type=b"PUT")
|
||||||
|
|
||||||
def send_default(self, *args, **kwargs):
|
def send_default(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue