Package com.github.twitch4j.chat
Class TwitchChat
java.lang.Object
com.github.twitch4j.chat.TwitchChat
- All Implemented Interfaces:
ITwitchChat,AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanWhether 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 longMinimum milliseconds to wait after a join attemptprotected final longTime 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 booleanWhether JOIN/PART events should be enabledstatic final StringThirdParty WebSocket Server for Testingprotected final TwitchIdentityProviderTwitch Identity Providerprotected final io.github.bucket4j.BucketIRC Auth Bucketprotected final BlockingQueue<String>IRC Command Queueprotected final io.github.bucket4j.BucketIRC Join Bucketprotected final io.github.bucket4j.BucketIRC Message Bucketprotected final io.github.bucket4j.BucketIRC Whisper BucketCache of recent number of join attempts for each channelprotected final intThe maximum number of attempts to make for joining each channelprotected final io.github.bucket4j.BandwidthIRC Per-Channel Message Limitprotected final ScheduledFuture<?>IRC Command Queue Threadprotected final booleanWhether join failures should result in removal from current channelsstatic final intprotected final booleanWhether theOAuth2Credentialpassword should be sent when the baseUrl does not match the official twitch websocket server, thus bypassing a security check in the library.protected booleanCommand Queue Thread stop flagprotected final ScheduledExecutorServiceThread Pool Executorstatic final StringTwitch's official WebSocket Serverprotected final booleanWhether OAuth token status should be checked on reconnect -
Constructor Summary
ConstructorsConstructorDescriptionTwitchChat(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, MirroredMessagePolicy mirroredMessagePolicy, Predicate<String> joinedToRoomId, io.github.xanthic.cache.api.Cache<String, Boolean> observedMessageIds) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closevoidconnect()Connecting to IRC-WSvoidDisconnecting from IRC-WSReturns a set of all currently joined channels (without # prefix)Deprecated.com.github.philippheuer.credentialmanager.CredentialManagerCredentialManagerDeprecated.use getChannels() insteadcom.github.philippheuer.events4j.core.EventManagerEventManagerlonggetState()booleanisChannelJoined(String channelName) Check if Chat is currently in a channelprotected voidvoidjoinChannel(String channelName) Joining the channelbooleanleaveChannel(String channelName) leaving the channelprotected voidprotected voidprotected voidonTextMessage(String text) voidReconnecting to IRC-WSprotected voidsendCommand(String command, String... args) Send IRC CommandbooleanSends a message to the channel while including the specified message tags.voidsendPrivateMessage(String targetUser, String message) Deprecated.Twitch will decommission this method on February 18, 2023; migrate to TwitchHelix#sendWhisperbooleanSend raw irc commandMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 theOAuth2Credentialpassword 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
@Internal 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, MirroredMessagePolicy mirroredMessagePolicy, Predicate<String> joinedToRoomId, io.github.xanthic.cache.api.Cache<String, Boolean> observedMessageIds) 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 FiltermirroredMessagePolicy- Mirrored Message PolicyjoinedToRoomId- Joined Room PredicateobservedMessageIds- Cache of Message IDs
-
-
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:
joinChannelin interfaceITwitchChat- Parameters:
channelName- channel name
-
issueJoin
-
leaveChannel
leaving the channel- Specified by:
leaveChannelin interfaceITwitchChat- Parameters:
channelName- channel name- Returns:
- whether the channel was previously joined
-
sendMessage
Description copied from interface:ITwitchChatSends a message to the channel while including the specified message tags.- Specified by:
sendMessagein 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceITwitchChat
-
isChannelJoined
Description copied from interface:ITwitchChatCheck if Chat is currently in a channel- Specified by:
isChannelJoinedin 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:ITwitchChatReturns a set of all currently joined channels (without # prefix)- Specified by:
getChannelsin interfaceITwitchChat- Returns:
- a set of channel names
-
getChannelIdToChannelName
- Specified by:
getChannelIdToChannelNamein interfaceITwitchChat- Returns:
- the cached map used for channel id to name mapping
-
getChannelNameToChannelId
- Specified by:
getChannelNameToChannelIdin interfaceITwitchChat- Returns:
- the cached map used for channel name to id mapping
-
getLatency
public long getLatency()- Specified by:
getLatencyin 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:
getEventManagerin interfaceITwitchChat
-
getCredentialManager
public com.github.philippheuer.credentialmanager.CredentialManager getCredentialManager()CredentialManager
-
getState()instead