mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Change handling of different request types and callback for 204 requests (nickname change).
This commit is contained in:
parent
78d573eee5
commit
2562d65a4d
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}"
|
||||
body = FileBodyProducer(BytesIO(json.dumps(data).encode("utf-8")))
|
||||
is_patch_request = kwargs.pop("patch", False)
|
||||
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"
|
||||
request_type = kwargs.pop("type", b"POST")
|
||||
|
||||
d = _AGENT.request(
|
||||
request_type,
|
||||
|
|
@ -377,13 +368,11 @@ class DiscordClient(WebSocketClientProtocol, _BASE_SESSION_CLASS):
|
|||
)
|
||||
|
||||
def cbResponse(response):
|
||||
if response.code == 200:
|
||||
logger.log_info(response.code)
|
||||
if response.code == 200 or response.code == 204:
|
||||
d = readBody(response)
|
||||
d.addCallback(self.post_response)
|
||||
return d
|
||||
elif response.code == 204:
|
||||
d = readBody(response)
|
||||
d.addCallback(self.post_response)
|
||||
elif should_retry(response.code):
|
||||
delay(300, self._post_json, url, data, **kwargs)
|
||||
|
||||
|
|
@ -510,12 +499,12 @@ class DiscordClient(WebSocketClientProtocol, _BASE_SESSION_CLASS):
|
|||
|
||||
data = {"nick": text}
|
||||
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):
|
||||
|
||||
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):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue