2023-12-15 22:44:25 +01:00
|
|
|
extends Control
|
|
|
|
|
2024-01-25 07:36:05 +01:00
|
|
|
var demo_events : Array[Twitch_Connection.EventSub_Subscription] = [
|
|
|
|
|
|
|
|
Twitch_Connection.EventSub_Subscription.new("channel.update", {"broadcaster_user_id" : ""}, "", "2")
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2023-12-15 22:44:25 +01:00
|
|
|
func _ready():
|
|
|
|
|
|
|
|
$Twitch_Connection.token_received.connect(save_token)
|
2024-01-25 07:36:05 +01:00
|
|
|
%Get_User.pressed.connect(func():
|
|
|
|
|
|
|
|
var resp = %Twitch_Connection.request_user_info()
|
|
|
|
resp.response_received.connect(print_http_result)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
%Get_Channel.pressed.connect(func():
|
|
|
|
|
|
|
|
var resp = %Twitch_Connection.request_channel_info()
|
|
|
|
resp.response_received.connect(print_http_result)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
%Connect_Channel_Points.pressed.connect(func():
|
|
|
|
|
|
|
|
await %Twitch_Connection.setup_eventsub_connection()
|
|
|
|
print("Passed Await")
|
|
|
|
%Twitch_Connection.eventsub_socket.notif_received.connect(eventsub_notif_received)
|
|
|
|
|
|
|
|
var resp = %Twitch_Connection.subscribe_to_channel_points(%Twitch_Connection.user_info.id)
|
|
|
|
resp.response_received.connect(print_http_result)
|
|
|
|
|
|
|
|
)
|
2023-12-15 22:44:25 +01:00
|
|
|
|
|
|
|
load_token()
|
|
|
|
|
|
|
|
|
|
|
|
func save_token(token):
|
|
|
|
|
|
|
|
var res = TokenSaver.new()
|
|
|
|
res.token = token
|
|
|
|
ResourceSaver.save(res, "user://token.tres")
|
|
|
|
|
|
|
|
|
|
|
|
func load_token():
|
|
|
|
|
|
|
|
if !FileAccess.file_exists("user://token.tres"):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
var res = ResourceLoader.load("user://token.tres")
|
|
|
|
$Twitch_Connection.token = res.token
|
2024-01-25 07:36:05 +01:00
|
|
|
%Twitch_Connection.cache_user_data()
|
2023-12-15 22:44:25 +01:00
|
|
|
|
|
|
|
|
2024-01-25 07:36:05 +01:00
|
|
|
func print_http_result(data):
|
|
|
|
|
|
|
|
print(data)
|
|
|
|
|
|
|
|
|
|
|
|
func eventsub_notif_received(info):
|
|
|
|
print(info)
|
|
|
|
printt(info.payload.event.reward.id, info.payload.event.user_input, info.payload.event.reward.title)
|
|
|
|
|