From 2a3307f70129fe0e685c33238254e55072e658d7 Mon Sep 17 00:00:00 2001 From: Eroax Date: Mon, 22 Jan 2024 20:09:04 -0700 Subject: [PATCH] Added Twitch Request User Info Adds in a node that exposes access to the Twitch API "Get Users" request. --- .../nodes/twitch/twitch_request_user_info.gd | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 classes/deck/nodes/twitch/twitch_request_user_info.gd diff --git a/classes/deck/nodes/twitch/twitch_request_user_info.gd b/classes/deck/nodes/twitch/twitch_request_user_info.gd new file mode 100644 index 0000000..5b3b9a9 --- /dev/null +++ b/classes/deck/nodes/twitch/twitch_request_user_info.gd @@ -0,0 +1,65 @@ +# (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 + + +func _init(): + name = "Twitch Request User Info" + node_type = name.to_snake_case() + description = "Requests to the Twitch API for the User info for the supplied Login or ID" + + props_to_serialize = [] + +# Adds the User input. + add_input_port(DeckType.Types.STRING, "User Login", "field") + +# Adds the Checkbox for using IDs vs Logins and sets it to true. + add_input_port(DeckType.Types.BOOL, "User Input as ID", "checkbox") + get_input_ports()[1].set_value(true) + + get_input_ports()[1].value_updated.connect(switch_user_input_type) + + add_output_port(DeckType.Types.ANY, "User Info") + + +func switch_user_input_type(value): + + var user_port = get_input_ports()[0] + + if value: + + user_port.label = "User ID" + + else: + + user_port.label = "User Login" + + + ports_updated.emit() + + + +func _value_request(from_port): + + var user_input = resolve_input_port_value(0) + var as_id = resolve_input_port_value(1) + + var req_url := "https://api.twitch.tv/helix/users?" + if as_id: + + req_url += "id=" + user_input + + else: + + req_url += "login=" + user_input + + + var resp = Connections.twitch.twitch_request(req_url) + + await resp.response_received + var data = resp.inf_data + + return data + +