Package com.gmt2001.twitch.tmi
Class TwitchMessageInterface
- All Implemented Interfaces:
- WsClientFrameHandler,- AutoCloseable,- Flow.Publisher<TMIMessage>
public final class TwitchMessageInterface
extends SubmissionPublisher<TMIMessage>
implements WsClientFrameHandler
A client for the Twitch Message Interface
- Author:
- gmt2001
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidCloses the socketbooleanvoidhandleFrame(ChannelHandlerContext ctx, WebSocketFrame frame) Handles the WebSocket frame and sends a response back to the server, if necessaryvoidHandles the handshake complete eventvoidonClose()Handles the channel closing for any reason.voidNotifies subscribed processors that the socket has closed and initiates reconnecting if there wasn't an outbound 1000 close codevoidonMessages(String messages) Splits a string containing one or more lines of RFC1459-formatted IRC messages and submits each one to subscribed processorsintprivMsgMaxLength(String channel, boolean isAction, String replyToId) Calculates the maximum length for the message content of a PRIVMSG to avoid droppingReturns theWindowedSwitchingRateLimiterused to prevent PRIVMSG spamvoidCloses the connection to TMI, then resets the outbound closing status and attempts to connect again after a 5 second delayvoidsendActionPrivMessage(String channel, String message) Sends an IRC PRIVMSG command with the/me ACTIONspecifier.voidsendActionPrivMessage(String channel, String message, String replyToId) Sends an IRC PRIVMSG command with the/me ACTIONspecifier.voidsendChannelCommand(String command, String channel, String parameter) Sends an IRC command with channel and parameter componentsvoidsendCommand(String command, String parameter) Sends an IRC command with parameter componentvoidSends an IRC command with tags and parameter componentvoidSends an IRC command with tags, channel, and parameter componentsvoidsendPing()Forces a PING to be sentvoidsendPrivMessage(String channel, String message) Sends an IRC PRIVMSG command.voidsendPrivMessage(String channel, String message, String replyToId) Sends an IRC PRIVMSG command as a reply to another message.voidSends a raw IRC messagevoidshutdown()Closes the connection normally.Methods inherited from class java.util.concurrent.SubmissionPublisherclose, closeExceptionally, consume, estimateMaximumLag, estimateMinimumDemand, getClosedException, getExecutor, getMaxBufferCapacity, getNumberOfSubscribers, getSubscribers, hasSubscribers, isClosed, isSubscribed, offer, offer, submit, subscribe
- 
Constructor Details- 
TwitchMessageInterfacepublic TwitchMessageInterface()Initializes the Twitch Message Interface. Creates a newWSClient, then initializes all processors and starts connecting
 
- 
- 
Method Details- 
privMsgMaxLengthCalculates the maximum length for the message content of a PRIVMSG to avoid dropping- Parameters:
- channel- The channel name
- isAction- If this is for a ACTION (/me) message
- replyToId- The- idtag from the- TMIMessage.tagsof the message that is being replied to;- nullif not used
- Returns:
 
- 
rateLimiterReturns theWindowedSwitchingRateLimiterused to prevent PRIVMSG spam- Returns:
- The rate limiter
 
- 
sendPingpublic void sendPing()Forces a PING to be sent
- 
sendActionPrivMessageSends an IRC PRIVMSG command with the/me ACTIONspecifier. If there are no tokens left onrateLimiter, the message is silently dropped- Parameters:
- channel- The channel to send to
- message- The chat message
 
- 
sendPrivMessageSends an IRC PRIVMSG command. If the message starts with/me, then it is passed tosendActionPrivMessage(java.lang.String, java.lang.String)instead. If there are no tokens left onrateLimiter, the message is silently dropped- Parameters:
- channel- The channel to send to
- message- The chat message
 
- 
sendActionPrivMessageSends an IRC PRIVMSG command with the/me ACTIONspecifier. If there are no tokens left onrateLimiter, the message is silently dropped- Parameters:
- channel- The channel to send to
- message- The chat message
- replyToId- The- idtag from the- TMIMessage.tagsof the message that is being replied to
 
- 
sendPrivMessageSends an IRC PRIVMSG command as a reply to another message. If the message starts with/me, then it is passed tosendActionPrivMessage(java.lang.String, java.lang.String, java.lang.String)instead. If there are no tokens left onrateLimiter, the message is silently dropped- Parameters:
- channel- The channel to send to
- message- The chat message
- replyToId- The- idtag from the- TMIMessage.tagsof the message that is being replied to
 
- 
sendCommandSends an IRC command with parameter component- Parameters:
- command- The IRC command
- parameter- The IRC parameter
 
- 
sendCommandSends an IRC command with tags and parameter component- Parameters:
- tags- The IRCv3 tags
- command- The IRC command
- parameter- The IRC parameter
 
- 
sendChannelCommandSends an IRC command with channel and parameter components- Parameters:
- command- The IRC command
- channel- The channel to send to
- parameter- The IRC parameter
 
- 
sendFullCommandpublic void sendFullCommand(Map<String, String> tags, String command, String channel, String parameter) Sends an IRC command with tags, channel, and parameter components- Parameters:
- tags- The IRCv3 tags. If- nullor empty, the tags component is not included
- command- The IRC command
- channel- The channel to send to. If- null, empty, or blank, the channel component of the command is not included
- parameter- The IRC parameters. If- null, the parameter component is not included
 
- 
sendRawSends a raw IRC message- Parameters:
- message- The message to send
 
- 
reconnectpublic void reconnect()Closes the connection to TMI, then resets the outbound closing status and attempts to connect again after a 5 second delay
- 
connectedpublic boolean connected()- Returns:
- trueif the underlying socket is connected. Does not indicate anything about the state other than that the raw socket is connected
 
- 
onMessagesSplits a string containing one or more lines of RFC1459-formatted IRC messages and submits each one to subscribed processors- Parameters:
- messages- A string containing one or more RFC1459-formatted IRC messages
 
- 
onCloseNotifies subscribed processors that the socket has closed and initiates reconnecting if there wasn't an outbound 1000 close code- Parameters:
- code- The close code
- reason- The textual close reason
 
- 
handleFrameDescription copied from interface:WsClientFrameHandlerHandles the WebSocket frame and sends a response back to the server, if necessary- Specified by:
- handleFramein interface- WsClientFrameHandler
- Parameters:
- ctx- The- ChannelHandlerContextof the session
- frame- The- WebSocketFrameto process
 
- 
handshakeCompleteDescription copied from interface:WsClientFrameHandlerHandles the handshake complete event- Specified by:
- handshakeCompletein interface- WsClientFrameHandler
- Parameters:
- ctx- The- ChannelHandlerContextof the session
 
- 
onClosepublic void onClose()Description copied from interface:WsClientFrameHandlerHandles the channel closing for any reason.- Specified by:
- onClosein interface- WsClientFrameHandler
 
- 
closeCloses the socket- Parameters:
- code- The close code
- reason- The textual close reason
 
- 
shutdownpublic void shutdown()Closes the connection normally. Exceptions are discarded
 
-