2023-12-15 22:44:25 +01:00
|
|
|
extends Control
|
|
|
|
|
2024-03-17 11:28:54 +01:00
|
|
|
var demo_events : Array[No_Twitch.EventSub_Subscription] = [
|
2024-01-25 07:36:05 +01:00
|
|
|
|
2024-03-17 11:28:54 +01:00
|
|
|
No_Twitch.EventSub_Subscription.new("channel.update", {"broadcaster_user_id" : ""}, "", "2")
|
2024-01-25 07:36:05 +01:00
|
|
|
|
|
|
|
]
|
2024-03-17 11:28:54 +01:00
|
|
|
@onready var twitch : No_Twitch = %Twitch_Connection
|
2024-01-25 07:36:05 +01:00
|
|
|
|
2023-12-15 22:44:25 +01:00
|
|
|
func _ready():
|
|
|
|
|
2024-03-17 11:28:54 +01:00
|
|
|
twitch.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():
|
|
|
|
|
2024-03-17 11:28:54 +01:00
|
|
|
await twitch.setup_eventsub_connection()
|
2024-01-25 07:36:05 +01:00
|
|
|
print("Passed Await")
|
2024-03-17 11:28:54 +01:00
|
|
|
twitch.eventsub_socket.notif_received.connect(eventsub_notif_received)
|
2024-01-25 07:36:05 +01:00
|
|
|
|
2024-03-17 11:28:54 +01:00
|
|
|
var resp = await twitch.subscribe_to_channel_points(twitch.user_info.id)
|
2024-01-25 07:36:05 +01:00
|
|
|
resp.response_received.connect(print_http_result)
|
|
|
|
|
2024-03-17 11:28:54 +01:00
|
|
|
)
|
|
|
|
%Get_Followers.pressed.connect(func():
|
|
|
|
|
|
|
|
var resp = twitch.twitch_request("https://api.twitch.tv/helix/channels/followers?broadcaster_id=" + twitch.user_info.id)
|
|
|
|
await resp.response_received
|
|
|
|
print(resp.inf_data)
|
|
|
|
|
2024-01-25 07:36:05 +01:00
|
|
|
)
|
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)
|
|
|
|
|