From 8896fed2f8ee877656b3e190608c8a7c3a67ebcf Mon Sep 17 00:00:00 2001 From: Eroax Date: Tue, 9 Apr 2024 05:49:54 +0000 Subject: [PATCH] Added Handling for Invalid NoTwitch Credentials (#135) Just a quick fix that implements handling for if your Twitch authorization is invalid by adding a new signal that gets emitted, No_Twitch.invalid_auth. Which is connected to a lambda in twitch_setup_dialog that asks for authorization and opens the browser if it's received. It's not *pretty*, but it solves the problem temporarily. Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/135 Co-authored-by: Eroax Co-committed-by: Eroax --- addons/no_twitch/twitch_connection.gd | 39 +++++++++++++++++----- graph_node_renderer/twitch_setup_dialog.gd | 12 ++++++- 2 files changed, 42 insertions(+), 9 deletions(-) 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")