miggor-StreamGraph/classes/deck/nodes/twitch/twitch_send_chat.gd
Lera Elvoé 677e7b36c5 add an API for buttons on ports (#96)
closes #91

Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/96
Co-authored-by: Lera Elvoé <yagich@poto.cafe>
Co-committed-by: Lera Elvoé <yagich@poto.cafe>
2024-03-06 07:50:23 +00:00

79 lines
1.4 KiB
GDScript

# (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
enum inputs {
message,
channel,
send
}
func _init():
name = "Twitch Send Chat"
node_type = "twitch_send_chat"
description = "Sends a message to a Twitch chat."
add_input_port(
DeckType.Types.STRING,
"Message",
"field"
)
add_input_port(
DeckType.Types.STRING,
"Channel",
"field"
)
add_input_port(
DeckType.Types.ANY,
"Send",
"button",
Port.UsageType.TRIGGER,
).button_pressed.connect(_receive.bind(inputs.send, null))
func _receive(to_input_port: int, data: Variant) -> void:
data = str(data)
var message
var channel
match to_input_port:
inputs.message:
message = data
channel = await resolve_input_port_value_async(inputs.channel)
inputs.channel:
channel = data
message = await resolve_input_port_value_async(inputs.message)
inputs.send:
channel = await resolve_input_port_value_async(inputs.channel)
message = await resolve_input_port_value_async(inputs.message)
if channel == null:
channel = ""
if message == null:
return
if message.is_empty():
DeckHolder.logger.log_node("Twitch Send Chat: Port %d: Supplied message was empty." % [to_input_port])
Connections.twitch.send_chat(message, channel)