From 717b69c35c92f3400f8b08e3375de074391cf9d2 Mon Sep 17 00:00:00 2001 From: Eroax Date: Sun, 21 Jan 2024 21:42:11 -0700 Subject: [PATCH] Updated NoTwitch to allow #50 --- addons/no_twitch/chat_socket.gd | 7 ++++++- addons/no_twitch/twitch_connection.gd | 13 ++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/addons/no_twitch/chat_socket.gd b/addons/no_twitch/chat_socket.gd index bdc52cf..b5ef776 100644 --- a/addons/no_twitch/chat_socket.gd +++ b/addons/no_twitch/chat_socket.gd @@ -16,7 +16,10 @@ var user_regex := RegEx.new() var user_pattern := r":([\w]+)!" -func _init(): +func _init(owner : Twitch_Connection): + + chat_received_rich.connect(owner.check_chat_socket.bind(true)) + chat_received.connect(owner.check_chat_socket) packet_received.connect(data_received) @@ -38,6 +41,8 @@ func connect_to_chat(token, extra = false, nick = "terribletwitch"): send_text("CAP REQ :twitch.tv/commands twitch.tv/tags") + + ## Handles checking the received packet from [signal Websocket_Client.packet_received] func data_received(packet : PackedByteArray): diff --git a/addons/no_twitch/twitch_connection.gd b/addons/no_twitch/twitch_connection.gd index 65d8c30..dc73a5a 100644 --- a/addons/no_twitch/twitch_connection.gd +++ b/addons/no_twitch/twitch_connection.gd @@ -7,6 +7,9 @@ class_name Twitch_Connection signal token_received(token : String) +signal chat_received(chat_dict) +signal chat_received_rich(chat_dict) + @export var client_id := "qyjg1mtby1ycs5scm1pvctos7yvyc1" @export var redirect_uri := "http://localhost" ## Port that the redirect_uri will head to on your local system. Defaults to 80 for most cases. Linux tends to prefer 8000 or possibly 1338 @@ -66,8 +69,7 @@ func authenticate_with_twitch(scopes : Array[String] = ["chat:read", "chat:edit" ## Sets up the chat connection. Joining 1 room with [param token] as it's "PASS" specifying what account it's on. And the optional [param default_chat] specifying the default room to join. While [param nick] specifies the "nickname" (Not the username on Twitch) func setup_chat_connection(default_chat : String = "", token : String = token, request_twitch_info = true, nick = "terribletwitch"): - chat_socket = chat_socket_class.new() - chat_socket.chat_received_rich.connect(check_chat_socket) + chat_socket = chat_socket_class.new(self) # Connects to the Twitch IRC server. chat_socket.connect_to_chat(token, request_twitch_info) @@ -260,11 +262,16 @@ func check_auth_peer(peer : StreamPeerTCP): token_received.emit(token) -func check_chat_socket(dict): +func check_chat_socket(dict, rich = false): prints(dict.user, dict.message) + if rich: + + chat_received_rich.emit(dict) + return + chat_received.emit(dict) ## "Promise" Class used for relaying the info received from the supplied [HTTPRequest] node.