Package com.github.twitch4j.chat
Class TwitchChat
java.lang.Object
com.github.twitch4j.chat.TwitchChat
- All Implemented Interfaces:
ITwitchChat,java.lang.AutoCloseable
public class TwitchChat extends java.lang.Object implements ITwitchChat
-
Field Summary
Fields Modifier and Type Field Description protected booleanautoJoinOwnChannelWhether one's own channel should automatically be joinedprotected com.github.twitch4j.common.util.ExponentialBackoffStrategybackoffHelper class to compute delays between connection retries.protected java.lang.StringbaseUrlThe websocket url for the chat client to connect to.protected java.util.Collection<java.lang.String>botOwnerIdsBot Owner IDsprotected java.util.Map<java.lang.String,java.lang.String>channelIdToChannelNameCache: ChannelId to ChannelNameprotected java.util.Map<java.lang.String,java.lang.String>channelNameToChannelIdCache: ChannelName to ChannelIdprotected longchatQueueTimeoutTime 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 shutdownprotected java.util.List<java.lang.String>commandPrefixesIRC Command Handlersprotected java.util.Set<java.lang.String>currentChannelsCurrent Channelsprotected booleanenableMembershipEventsWhether JOIN/PART events should be enabledstatic java.lang.StringFDGT_TEST_SOCKET_SERVERThirdParty WebSocket Server for Testingprotected java.util.concurrent.BlockingQueue<java.lang.String>ircCommandQueueIRC Command Queueprotected io.github.bucket4j.BucketircJoinBucketIRC Join Bucketprotected io.github.bucket4j.BucketircMessageBucketIRC Message Bucketprotected io.github.bucket4j.BucketircWhisperBucketIRC Whisper Bucketprotected java.util.concurrent.ScheduledFuture<?>queueThreadIRC Command Queue Threadstatic intREQUIRED_THREAD_COUNTprotected booleansendCredentialToThirdPartyHostWhether theOAuth2Credentialpassword should be sent when the baseUrl does not match the official twitch websocket server, thus bypassing a security check in the library.protected booleanstopQueueThreadCommand Queue Thread stop flagprotected java.util.concurrent.ScheduledExecutorServicetaskExecutorThread Pool Executorstatic java.lang.StringTWITCH_WEB_SOCKET_SERVERTwitch's official WebSocket Serverprotected com.neovisionaries.ws.client.WebSocketFactorywebSocketFactoryWebSocket Factory -
Constructor Summary
Constructors Constructor Description TwitchChat(com.github.philippheuer.events4j.core.EventManager eventManager, com.github.philippheuer.credentialmanager.CredentialManager credentialManager, com.github.philippheuer.credentialmanager.domain.OAuth2Credential chatCredential, java.lang.String baseUrl, boolean sendCredentialToThirdPartyHost, java.util.List<java.lang.String> commandPrefixes, java.lang.Integer chatQueueSize, io.github.bucket4j.Bucket ircMessageBucket, io.github.bucket4j.Bucket ircWhisperBucket, io.github.bucket4j.Bucket ircJoinBucket, java.util.concurrent.ScheduledThreadPoolExecutor taskExecutor, long chatQueueTimeout, com.github.twitch4j.common.config.ProxyConfig proxyConfig, boolean autoJoinOwnChannel, boolean enableMembershipEvents, java.util.Collection<java.lang.String> botOwnerIds)Constructor -
Method Summary
Modifier and Type Method Description voidclose()Closevoidconnect()Connecting to IRC-WSvoiddisconnect()Disconnecting from IRC-WSjava.util.Map<java.lang.String,java.lang.String>getChannelIdToChannelName()java.util.Map<java.lang.String,java.lang.String>getChannelNameToChannelId()java.util.Set<java.lang.String>getChannels()Returns a set of all currently joined channels (without # prefix)TMIConnectionStategetConnectionState()The connection state Default: (TMIConnectionState.DISCONNECTED)com.github.philippheuer.credentialmanager.CredentialManagergetCredentialManager()CredentialManagerjava.util.List<java.lang.String>getCurrentChannels()Deprecated.use getChannels() insteadcom.github.philippheuer.events4j.core.EventManagergetEventManager()EventManagerbooleanisChannelJoined(java.lang.String channelName)Check if Chat is currently in a channelvoidjoinChannel(java.lang.String channelName)Joining the channelbooleanleaveChannel(java.lang.String channelName)leaving the channelvoidreconnect()Reconnecting to IRC-WSprotected voidsendCommand(java.lang.String command, java.lang.String... args)Send IRC CommandbooleansendMessage(java.lang.String channel, java.lang.String message, java.util.Map<java.lang.String,java.lang.Object> tags)Sends a message to the channel while including the specified message tags.voidsendPrivateMessage(java.lang.String targetUser, java.lang.String message)Sends a user a private messagebooleansendRaw(java.lang.String command)Send 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, sendMessage, sendMessage, setEmoteOnly, setFollowersOnly, setSlowMode, setSubscribersOnly, setUniqueChat, timeout, unban
-
Field Details
-
REQUIRED_THREAD_COUNT
public static final int REQUIRED_THREAD_COUNT- See Also:
- Constant Field Values
-
TWITCH_WEB_SOCKET_SERVER
public static final java.lang.String TWITCH_WEB_SOCKET_SERVERTwitch's official WebSocket Server- See Also:
- Constant Field Values
-
FDGT_TEST_SOCKET_SERVER
public static final java.lang.String FDGT_TEST_SOCKET_SERVERThirdParty WebSocket Server for Testing- See Also:
- Constant Field Values
-
baseUrl
protected final java.lang.String baseUrlThe websocket url for the chat client to connect to. -
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
protected final java.util.Set<java.lang.String> currentChannelsCurrent Channels -
channelIdToChannelName
protected final java.util.Map<java.lang.String,java.lang.String> channelIdToChannelNameCache: ChannelId to ChannelName -
channelNameToChannelId
protected final java.util.Map<java.lang.String,java.lang.String> channelNameToChannelIdCache: 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 -
ircCommandQueue
protected final java.util.concurrent.BlockingQueue<java.lang.String> ircCommandQueueIRC Command Queue -
queueThread
protected final java.util.concurrent.ScheduledFuture<?> queueThreadIRC Command Queue Thread -
stopQueueThread
protected volatile boolean stopQueueThreadCommand Queue Thread stop flag -
botOwnerIds
protected final java.util.Collection<java.lang.String> botOwnerIdsBot Owner IDs -
commandPrefixes
protected final java.util.List<java.lang.String> commandPrefixesIRC Command Handlers -
taskExecutor
protected final java.util.concurrent.ScheduledExecutorService taskExecutorThread 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 -
webSocketFactory
protected final com.neovisionaries.ws.client.WebSocketFactory webSocketFactoryWebSocket Factory -
autoJoinOwnChannel
protected final boolean autoJoinOwnChannelWhether one's own channel should automatically be joined -
enableMembershipEvents
protected final boolean enableMembershipEventsWhether JOIN/PART events should be enabled -
backoff
protected final com.github.twitch4j.common.util.ExponentialBackoffStrategy backoffHelper class to compute delays between connection retries.- See Also:
- Official suggestion
-
-
Constructor Details
-
TwitchChat
public TwitchChat(com.github.philippheuer.events4j.core.EventManager eventManager, com.github.philippheuer.credentialmanager.CredentialManager credentialManager, com.github.philippheuer.credentialmanager.domain.OAuth2Credential chatCredential, java.lang.String baseUrl, boolean sendCredentialToThirdPartyHost, java.util.List<java.lang.String> commandPrefixes, java.lang.Integer chatQueueSize, io.github.bucket4j.Bucket ircMessageBucket, io.github.bucket4j.Bucket ircWhisperBucket, io.github.bucket4j.Bucket ircJoinBucket, java.util.concurrent.ScheduledThreadPoolExecutor taskExecutor, long chatQueueTimeout, com.github.twitch4j.common.config.ProxyConfig proxyConfig, boolean autoJoinOwnChannel, boolean enableMembershipEvents, java.util.Collection<java.lang.String> botOwnerIds)Constructor- Parameters:
eventManager- 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 joinstaskExecutor- 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 IDs
-
-
Method Details
-
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
protected void sendCommand(java.lang.String command, java.lang.String... args)Send IRC Command- Parameters:
command- IRC Commandargs- command arguments
-
sendRaw
public boolean sendRaw(java.lang.String command)Send raw irc command- Parameters:
command- raw irc command
-
joinChannel
public void joinChannel(java.lang.String channelName)Joining the channel- Specified by:
joinChannelin interfaceITwitchChat- Parameters:
channelName- channel name
-
leaveChannel
public boolean leaveChannel(java.lang.String channelName)leaving the channel- Specified by:
leaveChannelin interfaceITwitchChat- Parameters:
channelName- channel name- Returns:
- whether the channel was previously joined
-
sendMessage
public boolean sendMessage(java.lang.String channel, java.lang.String message, @Unofficial java.util.Map<java.lang.String,java.lang.Object> tags)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 (unofficial).- Returns:
- whether the message was added to the queue
-
sendPrivateMessage
public void sendPrivateMessage(java.lang.String targetUser, java.lang.String message)Sends a user a private message- Parameters:
targetUser- usernamemessage- message
-
close
public void close()Close- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceITwitchChat
-
isChannelJoined
public boolean isChannelJoined(java.lang.String channelName)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 public java.util.List<java.lang.String> getCurrentChannels()Deprecated.use getChannels() insteadReturns a set of all currently joined channels (without # prefix)- Returns:
- a set of channel names
-
getChannels
public java.util.Set<java.lang.String> 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
public java.util.Map<java.lang.String,java.lang.String> getChannelIdToChannelName()- Specified by:
getChannelIdToChannelNamein interfaceITwitchChat- Returns:
- the cached map used for channel id to name mapping
-
getChannelNameToChannelId
public java.util.Map<java.lang.String,java.lang.String> getChannelNameToChannelId()- Specified by:
getChannelNameToChannelIdin interfaceITwitchChat- Returns:
- the cached map used for channel name to id mapping
-
getEventManager
public com.github.philippheuer.events4j.core.EventManager getEventManager()EventManager- Specified by:
getEventManagerin interfaceITwitchChat
-
getCredentialManager
public com.github.philippheuer.credentialmanager.CredentialManager getCredentialManager()CredentialManager -
getConnectionState
The connection state Default: (TMIConnectionState.DISCONNECTED)
-