miggor-StreamGraph/addons/no_twitch/demo/demo_scene.gd

68 lines
1.5 KiB
GDScript3
Raw Normal View History

extends Control
var demo_events : Array[Twitch_Connection.EventSub_Subscription] = [
Twitch_Connection.EventSub_Subscription.new("channel.update", {"broadcaster_user_id" : ""}, "", "2")
]
func _ready():
$Twitch_Connection.token_received.connect(save_token)
%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)
)
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
%Twitch_Connection.cache_user_data()
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)