diff --git a/addons/no_twitch/eventsub_socket.gd b/addons/no_twitch/eventsub_socket.gd index 682db60..993766c 100644 --- a/addons/no_twitch/eventsub_socket.gd +++ b/addons/no_twitch/eventsub_socket.gd @@ -33,7 +33,12 @@ func connect_to_eventsub(events : Array[Twitch_Connection.EventSub_Subscription] for all in events: - responses.append(connection.add_eventsub_subscription(all)) + responses.append(await connection.add_eventsub_subscription(all)) + + + if responses.size() == 1: + + return responses[0] return responses diff --git a/addons/no_twitch/twitch_connection.gd b/addons/no_twitch/twitch_connection.gd index c70c08e..ae8c297 100644 --- a/addons/no_twitch/twitch_connection.gd +++ b/addons/no_twitch/twitch_connection.gd @@ -105,6 +105,16 @@ func setup_eventsub_connection(events : Array[EventSub_Subscription] = [], timeo func add_eventsub_subscription(sub_type : EventSub_Subscription): + if eventsub_socket == null: + + return await setup_eventsub_connection([sub_type]) + + + if sub_type.session_id == "": + + sub_type.session_id = eventsub_socket.session_id + + return twitch_request("https://api.twitch.tv/helix/eventsub/subscriptions", HTTPClient.METHOD_POST, str(sub_type.return_request_dictionary())) @@ -116,7 +126,7 @@ func subscribe_to_channel_points(user_id : String): return - return add_eventsub_subscription(EventSub_Subscription.new("channel.channel_points_custom_reward_redemption.add", {"broadcaster_user_id" : user_id}, eventsub_socket.session_id)) + return await add_eventsub_subscription(EventSub_Subscription.new("channel.channel_points_custom_reward_redemption.add", {"broadcaster_user_id" : user_id}, eventsub_socket.session_id)) func _process(delta): @@ -324,7 +334,7 @@ class EventSub_Subscription: var method = "websocket" - func _init(sub_type : String, cond : Dictionary, sess_id : String, vers : String = "1"): + func _init(sub_type : String, cond : Dictionary, sess_id : String = "", vers : String = "1"): subscription_type = sub_type version = vers