diff --git a/addons/no_twitch/twitch_connection.gd b/addons/no_twitch/twitch_connection.gd index 3b3de60..c45c385 100644 --- a/addons/no_twitch/twitch_connection.gd +++ b/addons/no_twitch/twitch_connection.gd @@ -7,6 +7,10 @@ class_name No_Twitch signal token_received(token : String) +signal twitch_error(error : String) + +signal invalid_auth() + signal chat_received(chat_dict) signal chat_received_rich(chat_dict) @@ -43,18 +47,27 @@ func _ready(): ## Function that handles Caching the data of the Account tied to the Connections Token func cache_user_data(): - + if token.is_empty(): - + return - - + + var resp = request_user_info() resp.response_received.connect(func(data): - + + # Error handling here. + if data.has("error") and not data.error.is_empty(): # If we have an error. + + invalid_auth.emit() + + # Return out. + return + + user_info = data.data print("User Info Cached") - + ) @@ -196,7 +209,18 @@ func twitch_request(url : String, method : HTTPClient.Method = HTTPClient.METHOD var resp = HTTPResponse.new(http, responses) add_child(http) http.request(url, headers, method, body) - + + # Generic error signal handling to ensure the signal is emitted. + resp.response_received.connect(func(data): + # If there's no error return. + if !data.has("error") or data.error.is_empty(): + + return + + twitch_error.emit(data.error, data.message) + + ) + return resp @@ -322,7 +346,6 @@ class HTTPResponse: if info.has("error"): - push_error("No_Twitch Twitch API Error: " + str(info)) emit_response(info, http, storage) return diff --git a/graph_node_renderer/twitch_setup_dialog.gd b/graph_node_renderer/twitch_setup_dialog.gd index b480224..2d3033a 100644 --- a/graph_node_renderer/twitch_setup_dialog.gd +++ b/graph_node_renderer/twitch_setup_dialog.gd @@ -20,13 +20,23 @@ func authenticate_twitch(): Connections.twitch.token = loaded_creds.data.token if loaded_creds.data.has("channel"): + %Default_Chat.text = loaded_creds.data.channel + + Connections.twitch.cache_user_data() + # Binds invalid auth to call No_Twitch.authenticate_with_twitch, handles if the cache of auth is invalid. + Connections.twitch.invalid_auth.connect(func(): + + var url = Connections.twitch.authenticate_with_twitch(%Client_ID.text) + OS.shell_open(url) + ) + connect_to_chat() return - # Temporary setup for saving tokens. +# Handles first authentication/invalid cached authentication. Connections.twitch.token_received.connect(func(token): Connections.save_credentials({"token" : token}, "twitch")