mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
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 <eroaxebusiness@duck.com> Co-committed-by: Eroax <eroaxebusiness@duck.com>
This commit is contained in:
parent
5a4a62ef44
commit
8896fed2f8
2 changed files with 42 additions and 9 deletions
|
@ -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)
|
||||
|
||||
|
@ -52,6 +56,15 @@ func cache_user_data():
|
|||
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")
|
||||
|
||||
|
@ -197,6 +210,17 @@ func twitch_request(url : String, method : HTTPClient.Method = HTTPClient.METHOD
|
|||
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
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue