TwitchIrcChannel Node (Deprecated)
DeprecatedWarning: This node relies entirely on the TwitchIRC
system, which Twitch plans to deprecate and remove. Avoid using TwitchIrcChannel
for new development. Migrate existing usage to EventSub-based solutions like TwitchChat
and TwitchEventListener
. Using this node may result in broken functionality in the future.
The TwitchIrcChannel
node provides a focused way to interact with a single, specific Twitch channel when using the underlying TwitchIRC
connection manager. It's primarily intended for scenarios where your application needs to connect to and manage multiple Twitch channels concurrently.
Overview
While the main TwitchIRC
node handles the overall connection and receives events for all joined channels, TwitchIrcChannel
acts as a filter and interface for just one of those channels.
When added to the scene and configured with a channel_name
:
- It finds the main
TwitchIRC
instance (via the assignedTwitchService
). - It registers itself with the
TwitchIRC
node usingirc.add_channel(self)
. This tells theTwitchIRC
node to potentially JOIN this channel if it hasn't already. - It listens to the global signals from
TwitchIRC
(received_privmsg
,received_roomstate
,received_userstate
). - When an event arrives from
TwitchIRC
, this node checks if the event's channel matches its ownchannel_name
. - If the channel matches, it emits its own, more specific signal (e.g.,
message_received
instead ofreceived_privmsg
). - It provides a
chat()
method that automatically targets its specific channel. - It tracks whether the
ROOMSTATE
for its channel has been received, indicating a successful join (joined
property,has_joined
signal).
Prerequisites
- Functional
TwitchIRC
: You must have a correctly configured and connectedTwitchIRC
node available, typically managed via a parentTwitchService
node. - Add the Node: Add a
TwitchIrcChannel
node to your scene. - Assign Dependencies:
Twitch Service
: Assign the parentTwitchService
instance that contains the activeTwitchIRC
node.Channel Name
: Crucially, set this property in the Inspector to the name of the Twitch channel (e.g., "your_channel_name", without#
) that this node should represent.
Configuration (Inspector Properties)
Twitch Service
(TwitchService
): Required. A reference to theTwitchService
node that holds the activeTwitchIRC
instance.Channel Name
(StringName
): Required. The login name of the Twitch channel this node instance will manage and filter events for (e.g., "kani_dev"). Setting this property triggers registration with the parentTwitchIRC
.
Signals
These signals are emitted only for events related to this node's specific channel_name
:
message_received(from_user: String, message: String, tags: TwitchTags.Message)
- Emitted when a
PRIVMSG
arrives from the parentTwitchIRC
that matches this node'schannel_name
. tags
: A processedTwitchTags.Message
object, which attempts to load emote/badge sprites using theTwitchService
'sTwitchMediaLoader
.
- Emitted when a
user_state_received(tags: TwitchTags.Userstate)
- Emitted when a
USERSTATE
message arrives fromTwitchIRC
for this channel, providing the bot's current state (badges, color, etc.) in this specific channel.
- Emitted when a
room_state_received(tags: TwitchTags.Roomstate)
- Emitted when a
ROOMSTATE
message arrives fromTwitchIRC
for this channel, indicating current chat settings (emote-only, etc.). This signal also triggers thehas_joined
signal the first time it's received.
- Emitted when a
has_joined()
- Emitted once when the
ROOMSTATE
for this channel is first received, indicating the bot has successfully joined and received initial state information.
- Emitted once when the
has_left()
- Emitted when the node is notified of leaving the channel (typically when removed from the scene tree or when
irc.leave_channel
is called).
- Emitted when the node is notified of leaving the channel (typically when removed from the scene tree or when
Methods
chat(message: String) -> void
- Sends a chat message specifically to this node's
channel_name
via the parentTwitchIRC
node'schat
method. - It implicitly waits (
await is_joined()
) until thehas_joined
signal has been emitted before attempting to send the message, ensuring the bot is actually in the channel.
- Sends a chat message specifically to this node's
is_joined() -> void
- An asynchronous utility function. If the channel hasn't received its initial
ROOMSTATE
yet (joined
is false), it waits for thehas_joined
signal to be emitted. Useful for ensuring actions are only taken after joining is confirmed. Useawait
when calling.
- An asynchronous utility function. If the channel hasn't received its initial
leave() -> void
- Internal method called when the channel is being parted from. It resets the internal
joined
state and emits thehas_left
signal. Usually triggered automatically when the node exits the tree orirc.remove_channel(self)
is called.
- Internal method called when the channel is being parted from. It resets the internal
Usage Example
Scenario: Connecting to two channels ("channel_one", "channel_two") and handling their chat separately.
- Set up
TwitchService
withTwitchIRC
as usual. - Add two
TwitchIrcChannel
nodes as children (e.g.,IrcChannelOne
,IrcChannelTwo
). - In the Inspector for
IrcChannelOne
:- Assign the
TwitchService
node to theTwitch Service
property. - Set
Channel Name
to"channel_one"
.
- Assign the
- In the Inspector for
IrcChannelTwo
:- Assign the
TwitchService
node to theTwitch Service
property. - Set
Channel Name
to"channel_two"
.
- Assign the
extends Node
# References to the specific channel nodes
@onready var channel_one_handler: TwitchIrcChannel = $IrcChannelOne
@onready var channel_two_handler: TwitchIrcChannel = $IrcChannelTwo
func _ready() -> void:
# Ensure TwitchService (and thus TwitchIRC) is set up first
# await TwitchService.setup() # Assuming TwitchService is accessible
channel_one_handler.message_received.connect(_on_channel_one_message)
channel_one_handler.has_joined.connect(_on_channel_joined.bind(&"Channel One"))
channel_two_handler.message_received.connect(_on_channel_two_message)
channel_two_handler.has_joined.connect(_on_channel_joined.bind(&"Channel Two"))
func _on_channel_joined(channel_identifier: StringName) -> void:
print("%s successfully joined!" % channel_identifier)
# Maybe send a welcome message after joining
if channel_identifier == &"Channel One":
channel_one_handler.chat("Bot connected to Channel One!")
elif channel_identifier == &"Channel Two":
channel_two_handler.chat("Bot connected to Channel Two!")
func _on_channel_one_message(from_user: String, message: String, tags: TwitchTags.Message) -> void:
print("[Channel One] %s: %s" % [from_user, message])
# Handle message specific to channel one
func _on_channel_two_message(from_user: String, message: String, tags: TwitchTags.Message) -> void:
print("[Channel Two] %s: %s" % [from_user, message])
# Handle message specific to channel two