miggor-StreamGraph/classes/deck/nodes/twitch/twitch_eventsub_event.gd

55 lines
1.4 KiB
GDScript3
Raw Normal View History

# (c) 2023-present Eroax
# (c) 2023-present Yagich
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
extends DeckNode
var cached_event_data : Dictionary
func _init():
name = "Twitch EventSub Event"
node_type = name.to_snake_case()
2024-02-11 20:08:11 +01:00
description = "Listens for a specific Event from Twitch EventSub."
props_to_serialize = []
2024-01-26 11:26:22 +01:00
# Adds a port that allows specifying what type of event to listen for.
add_input_port(DeckType.Types.STRING, "Event Name", "field")
# Adds a port that outputs when the Event has been received
add_output_port(DeckType.Types.ANY, "Event Received")
# Adds a port that outputs the data received when the Event has been received.
add_output_port(DeckType.Types.DICTIONARY, "Event Data")
2024-01-26 11:26:22 +01:00
func _event_received(event_name: StringName, event_data: Dictionary = {}):
2024-01-26 11:26:22 +01:00
if event_name != &"twitch_eventsub":
2024-01-26 11:26:22 +01:00
return
2024-01-26 11:26:22 +01:00
var port_0 = await resolve_input_port_value_async(0)
print("Event Name ", event_data)
if port_0 == null or port_0 != event_data.payload.subscription.type:
2024-01-26 11:26:22 +01:00
return
2024-01-26 11:26:22 +01:00
# Sends the data along as well as the fact that the event happened. While also caching the event data for later access
cached_event_data = event_data.payload
2024-01-26 11:26:22 +01:00
# Sends to indicate that the specified event has happened.
send(0, null)
send(1, event_data)
2024-01-26 11:26:22 +01:00
func _value_request(port):
2024-01-26 11:26:22 +01:00
if port != 1:
2024-01-26 11:26:22 +01:00
return
2024-01-26 11:26:22 +01:00
return cached_event_data
2024-01-26 11:26:22 +01:00