Package com.github.twitch4j.chat
Class TwitchChat
java.lang.Object
com.github.twitch4j.chat.TwitchChat
- All Implemented Interfaces:
ITwitchChat
,AutoCloseable
-
Field Summary
Modifier and TypeFieldDescriptionprotected final boolean
Whether one's own channel should automatically be joinedprotected final Collection<String>
Bot Owner IDsprotected final io.github.xanthic.cache.api.Cache<String,
io.github.bucket4j.Bucket> Cache of per-channel message bucketsCache: ChannelId to ChannelNameCache: ChannelName to ChannelIdprotected final long
Minimum milliseconds to wait after a join attemptprotected final long
Time to wait for an item on the chat queue before continuing to next iteration If set too high your thread will be late check to shutdownIRC Command HandlersCurrent Channelsprotected final boolean
Whether JOIN/PART events should be enabledstatic final String
ThirdParty WebSocket Server for Testingprotected final TwitchIdentityProvider
Twitch Identity Providerprotected final io.github.bucket4j.Bucket
IRC Auth Bucketprotected final BlockingQueue<String>
IRC Command Queueprotected final io.github.bucket4j.Bucket
IRC Join Bucketprotected final io.github.bucket4j.Bucket
IRC Message Bucketprotected final io.github.bucket4j.Bucket
IRC Whisper BucketCache of recent number of join attempts for each channelprotected final int
The maximum number of attempts to make for joining each channelprotected final io.github.bucket4j.Bandwidth
IRC Per-Channel Message Limitprotected final ScheduledFuture<?>
IRC Command Queue Threadprotected final boolean
Whether join failures should result in removal from current channelsstatic final int
protected final boolean
Whether theOAuth2Credential
password should be sent when the baseUrl does not match the official twitch websocket server, thus bypassing a security check in the library.protected boolean
Command Queue Thread stop flagprotected final ScheduledExecutorService
Thread Pool Executorstatic final String
Twitch's official WebSocket Serverprotected final boolean
Whether OAuth token status should be checked on reconnect -
Constructor Summary
ConstructorDescriptionTwitchChat
(WebsocketConnection websocketConnection, com.github.philippheuer.events4j.core.EventManager eventManager, com.github.philippheuer.credentialmanager.CredentialManager credentialManager, com.github.philippheuer.credentialmanager.domain.OAuth2Credential chatCredential, String baseUrl, boolean sendCredentialToThirdPartyHost, Collection<String> commandPrefixes, Integer chatQueueSize, io.github.bucket4j.Bucket ircMessageBucket, io.github.bucket4j.Bucket ircWhisperBucket, io.github.bucket4j.Bucket ircJoinBucket, io.github.bucket4j.Bucket ircAuthBucket, ScheduledThreadPoolExecutor taskExecutor, long chatQueueTimeout, ProxyConfig proxyConfig, boolean autoJoinOwnChannel, boolean enableMembershipEvents, Collection<String> botOwnerIds, boolean removeChannelOnJoinFailure, int maxJoinRetries, long chatJoinTimeout, int wsPingPeriod, IBackoffStrategy connectionBackoffStrategy, io.github.bucket4j.Bandwidth perChannelRateLimit, boolean validateOnConnect, int wsCloseDelay, BiPredicate<TwitchChat, String> outboundCommandFilter) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closevoid
connect()
Connecting to IRC-WSvoid
Disconnecting from IRC-WSReturns a set of all currently joined channels (without # prefix)Deprecated.com.github.philippheuer.credentialmanager.CredentialManager
CredentialManagerDeprecated.use getChannels() insteadcom.github.philippheuer.events4j.core.EventManager
EventManagerlong
getState()
boolean
isChannelJoined
(String channelName) Check if Chat is currently in a channelprotected void
void
joinChannel
(String channelName) Joining the channelboolean
leaveChannel
(String channelName) leaving the channelprotected void
protected void
protected void
onTextMessage
(String text) void
Reconnecting to IRC-WSprotected void
sendCommand
(String command, String... args) Send IRC Commandboolean
Sends a message to the channel while including the specified message tags.void
sendPrivateMessage
(String targetUser, String message) Deprecated.Twitch will decommission this method on February 18, 2023; migrate to TwitchHelix#sendWhisperboolean
Send raw irc commandMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.github.twitch4j.chat.ITwitchChat
ban, clearChat, delete, sendActionMessage, sendAnnouncement, sendMessage, sendMessage, setEmoteOnly, setFollowersOnly, setSlowMode, setSubscribersOnly, setUniqueChat, timeout, unban
-
Field Details
-
REQUIRED_THREAD_COUNT
public static final int REQUIRED_THREAD_COUNT- See Also:
-
TWITCH_WEB_SOCKET_SERVER
Twitch's official WebSocket Server- See Also:
-
FDGT_TEST_SOCKET_SERVER
ThirdParty WebSocket Server for Testing- See Also:
-
sendCredentialToThirdPartyHost
protected final boolean sendCredentialToThirdPartyHostWhether theOAuth2Credential
password should be sent when the baseUrl does not match the official twitch websocket server, thus bypassing a security check in the library. -
currentChannels
Current Channels -
channelIdToChannelName
Cache: ChannelId to ChannelName -
channelNameToChannelId
Cache: ChannelName to ChannelId -
ircMessageBucket
protected final io.github.bucket4j.Bucket ircMessageBucketIRC Message Bucket -
ircWhisperBucket
protected final io.github.bucket4j.Bucket ircWhisperBucketIRC Whisper Bucket -
ircJoinBucket
protected final io.github.bucket4j.Bucket ircJoinBucketIRC Join Bucket -
ircAuthBucket
protected final io.github.bucket4j.Bucket ircAuthBucketIRC Auth Bucket -
perChannelRateLimit
protected final io.github.bucket4j.Bandwidth perChannelRateLimitIRC Per-Channel Message Limit -
ircCommandQueue
IRC Command Queue -
queueThread
IRC Command Queue Thread -
stopQueueThread
protected volatile boolean stopQueueThreadCommand Queue Thread stop flag -
botOwnerIds
Bot Owner IDs -
commandPrefixes
IRC Command Handlers -
taskExecutor
Thread Pool Executor -
chatQueueTimeout
protected final long chatQueueTimeoutTime to wait for an item on the chat queue before continuing to next iteration If set too high your thread will be late check to shutdown -
autoJoinOwnChannel
protected final boolean autoJoinOwnChannelWhether one's own channel should automatically be joined -
removeChannelOnJoinFailure
protected final boolean removeChannelOnJoinFailureWhether join failures should result in removal from current channels -
enableMembershipEvents
protected final boolean enableMembershipEventsWhether JOIN/PART events should be enabled -
maxJoinRetries
protected final int maxJoinRetriesThe maximum number of attempts to make for joining each channel -
chatJoinTimeout
protected final long chatJoinTimeoutMinimum milliseconds to wait after a join attempt -
joinAttemptsByChannelName
Cache of recent number of join attempts for each channel -
bucketByChannelName
protected final io.github.xanthic.cache.api.Cache<String,io.github.bucket4j.Bucket> bucketByChannelNameCache of per-channel message buckets -
identityProvider
Twitch Identity Provider -
validateOnConnect
protected final boolean validateOnConnectWhether OAuth token status should be checked on reconnect
-
-
Constructor Details
-
TwitchChat
public TwitchChat(WebsocketConnection websocketConnection, com.github.philippheuer.events4j.core.EventManager eventManager, com.github.philippheuer.credentialmanager.CredentialManager credentialManager, com.github.philippheuer.credentialmanager.domain.OAuth2Credential chatCredential, String baseUrl, boolean sendCredentialToThirdPartyHost, Collection<String> commandPrefixes, Integer chatQueueSize, io.github.bucket4j.Bucket ircMessageBucket, io.github.bucket4j.Bucket ircWhisperBucket, io.github.bucket4j.Bucket ircJoinBucket, io.github.bucket4j.Bucket ircAuthBucket, ScheduledThreadPoolExecutor taskExecutor, long chatQueueTimeout, ProxyConfig proxyConfig, boolean autoJoinOwnChannel, boolean enableMembershipEvents, Collection<String> botOwnerIds, boolean removeChannelOnJoinFailure, int maxJoinRetries, long chatJoinTimeout, int wsPingPeriod, IBackoffStrategy connectionBackoffStrategy, io.github.bucket4j.Bandwidth perChannelRateLimit, boolean validateOnConnect, int wsCloseDelay, BiPredicate<TwitchChat, String> outboundCommandFilter) Constructor- Parameters:
websocketConnection
- WebsocketConnectioneventManager
- EventManagercredentialManager
- CredentialManagerchatCredential
- Chat CredentialbaseUrl
- The websocket url for the chat client to connect tosendCredentialToThirdPartyHost
- Whether the password should be sent when the baseUrl is not officialcommandPrefixes
- Command PrefixeschatQueueSize
- Chat Queue SizeircMessageBucket
- Bucket for chatircWhisperBucket
- Bucket for whispersircJoinBucket
- Bucket for joinsircAuthBucket
- Bucket for authstaskExecutor
- ScheduledThreadPoolExecutorchatQueueTimeout
- Timeout to wait for events in Chat QueueproxyConfig
- Proxy ConfigurationautoJoinOwnChannel
- Whether one's own channel should automatically be joinedenableMembershipEvents
- Whether JOIN/PART events should be enabledbotOwnerIds
- Bot Owner IDsremoveChannelOnJoinFailure
- Whether channels should be removed after a join failuremaxJoinRetries
- Maximum join retries per channelchatJoinTimeout
- Minimum milliseconds to wait after a join attemptwsPingPeriod
- WebSocket Ping PeriodconnectionBackoffStrategy
- WebSocket Connection Backoff StrategyperChannelRateLimit
- Per channel message limitvalidateOnConnect
- Whether token should be validated on connectwsCloseDelay
- Websocket Close DelayoutboundCommandFilter
- Outbound Command Filter
-
-
Method Details
-
onConnected
protected void onConnected() -
onTextMessage
-
onDisconnecting
protected void onDisconnecting() -
connect
public void connect()Connecting to IRC-WS -
disconnect
public void disconnect()Disconnecting from IRC-WS -
reconnect
public void reconnect()Reconnecting to IRC-WS -
sendCommand
Send IRC Command- Parameters:
command
- IRC Commandargs
- command arguments
-
sendRaw
Send raw irc commandNote: perChannelRateLimit does not apply when directly using this method
- Parameters:
command
- raw irc command
-
joinChannel
Joining the channel- Specified by:
joinChannel
in interfaceITwitchChat
- Parameters:
channelName
- channel name
-
issueJoin
-
leaveChannel
leaving the channel- Specified by:
leaveChannel
in interfaceITwitchChat
- Parameters:
channelName
- channel name- Returns:
- whether the channel was previously joined
-
sendMessage
Description copied from interface:ITwitchChat
Sends a message to the channel while including the specified message tags.- Specified by:
sendMessage
in interfaceITwitchChat
- Parameters:
channel
- the name of the channel to send the message to.message
- the message to be sent.tags
- the message tags.- Returns:
- whether the message was added to the queue
-
sendPrivateMessage
Deprecated.Twitch will decommission this method on February 18, 2023; migrate to TwitchHelix#sendWhisperSends a user a private message- Parameters:
targetUser
- usernamemessage
- message
-
close
public void close()Close- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceITwitchChat
-
isChannelJoined
Description copied from interface:ITwitchChat
Check if Chat is currently in a channel- Specified by:
isChannelJoined
in interfaceITwitchChat
- Parameters:
channelName
- channel to check (without # prefix)- Returns:
- boolean
-
getCurrentChannels
Deprecated.use getChannels() insteadReturns a set of all currently joined channels (without # prefix)- Returns:
- a set of channel names
-
getChannels
Description copied from interface:ITwitchChat
Returns a set of all currently joined channels (without # prefix)- Specified by:
getChannels
in interfaceITwitchChat
- Returns:
- a set of channel names
-
getChannelIdToChannelName
- Specified by:
getChannelIdToChannelName
in interfaceITwitchChat
- Returns:
- the cached map used for channel id to name mapping
-
getChannelNameToChannelId
- Specified by:
getChannelNameToChannelId
in interfaceITwitchChat
- Returns:
- the cached map used for channel name to id mapping
-
getLatency
public long getLatency()- Specified by:
getLatency
in interfaceITwitchChat
- Returns:
- the most recently measured round-trip latency for the socket(s) in milliseconds, or -1 if unknown
-
getState
- Returns:
- the connection state
-
getConnectionState
Deprecated.usegetState()
instead- Returns:
- the connection state
-
getEventManager
public com.github.philippheuer.events4j.core.EventManager getEventManager()EventManager- Specified by:
getEventManager
in interfaceITwitchChat
-
getCredentialManager
public com.github.philippheuer.credentialmanager.CredentialManager getCredentialManager()CredentialManager
-
getState()
instead