Fix send_whisper function #36

Merged
Haskaris merged 1 commits from fix_api_connection_send_whisper into master 2023-12-19 19:29:42 +01:00
Showing only changes of commit 1cc126f34b - Show all commits

View File

@ -107,19 +107,28 @@ func send_whisper(from_user_id : String, to_user_id : String, message : String)
"Client-Id: %s" % id_conn.last_token.last_client_id, "Client-Id: %s" % id_conn.last_token.last_client_id,
"Content-Type: application/json" "Content-Type: application/json"
] ]
var response = await(request(HTTPClient.METHOD_POST, "/helix/eventsub/whispers?from_user_id=%s&to_user_id=%s", headers, JSON.stringify({"message": message}))) var params: String = "?"
match (client.get_response_code()): params += "from_user_id=%s" % from_user_id
204: params += "&to_user_id=%s" % to_user_id
var response: Dictionary = await(
request(
HTTPClient.METHOD_POST,
"/helix/whispers" + params,
headers,
JSON.stringify({"message": message})
)
)
var response_code: int = client.get_response_code()
match (response_code):
# 200 is returned even if Twitch documentation says only 204
200, 204:
print("Success! The whisper was sent.")
return true return true
400: # Complete list of error codes according to Twitch documentation
print("Bad Request! Check the data you specified.") 400, 401, 403, 404, 429:
print("[Error (send_whisper)] %s - %s" % [response["status"], response["message"]])
return false return false
403: # Fallback for unknown response codes
print("Forbidden! The account that's sending the message doesn't allow sending whispers.") _:
print("[Default (send_whisper)] %s " % response_code)
return false return false
404:
print("Not Found! The ID in to_user_id was not found.")
429:
print("Too Many Requests! The sending user exceeded the number of whisper requests that they may make.")
return false
return false