miggor-StreamGraph/addons/no_twitch/demo/demo_scene.gd
Lera Elvoé d0313b9697 Twitch updates pt. 1 (#56)
- Add credential saving for Twitch
- Sync NoTwitch with upstream to allow for API and EventSub access
- Add Twitch Connected Account Info and Twitch Request User Info nodes

Co-authored-by: Eroax <eroaxe.business@gmail.com>
Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/56
Co-authored-by: Lera Elvoé <yagich@poto.cafe>
Co-committed-by: Lera Elvoé <yagich@poto.cafe>
2024-01-25 06:36:05 +00:00

67 lines
1.5 KiB
GDScript

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)