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 Summary
Constructors -
Method Summary
Modifier 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.SubmissionPublisher
close, closeExceptionally, consume, estimateMaximumLag, estimateMinimumDemand, getClosedException, getExecutor, getMaxBufferCapacity, getNumberOfSubscribers, getSubscribers, hasSubscribers, isClosed, isSubscribed, offer, offer, submit, subscribe
-
Constructor Details
-
TwitchMessageInterface
public TwitchMessageInterface()Initializes the Twitch Message Interface. Creates a newWSClient, then initializes all processors and starts connecting
-
-
Method Details
-
privMsgMaxLength
Calculates the maximum length for the message content of a PRIVMSG to avoid dropping- Parameters:
channel- The channel nameisAction- If this is for a ACTION (/me) messagereplyToId- Theidtag from theTMIMessage.tagsof the message that is being replied to;nullif not used- Returns:
-
rateLimiter
Returns theWindowedSwitchingRateLimiterused to prevent PRIVMSG spam- Returns:
- The rate limiter
-
sendPing
public void sendPing()Forces a PING to be sent -
sendActionPrivMessage
Sends 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 tomessage- The chat message
-
sendPrivMessage
Sends 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 tomessage- The chat message
-
sendActionPrivMessage
Sends 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 tomessage- The chat messagereplyToId- Theidtag from theTMIMessage.tagsof the message that is being replied to
-
sendPrivMessage
Sends 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 tomessage- The chat messagereplyToId- Theidtag from theTMIMessage.tagsof the message that is being replied to
-
sendCommand
Sends an IRC command with parameter component- Parameters:
command- The IRC commandparameter- The IRC parameter
-
sendCommand
Sends an IRC command with tags and parameter component- Parameters:
tags- The IRCv3 tagscommand- The IRC commandparameter- The IRC parameter
-
sendChannelCommand
Sends an IRC command with channel and parameter components- Parameters:
command- The IRC commandchannel- The channel to send toparameter- The IRC parameter
-
sendFullCommand
public 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. Ifnullor empty, the tags component is not includedcommand- The IRC commandchannel- The channel to send to. Ifnull, empty, or blank, the channel component of the command is not includedparameter- The IRC parameters. Ifnull, the parameter component is not included
-
sendRaw
Sends a raw IRC message- Parameters:
message- The message to send
-
reconnect
public void reconnect()Closes the connection to TMI, then resets the outbound closing status and attempts to connect again after a 5 second delay -
connected
public boolean connected()- Returns:
trueif the underlying socket is connected. Does not indicate anything about the state other than that the raw socket is connected
-
onMessages
Splits 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
-
onClose
Notifies subscribed processors that the socket has closed and initiates reconnecting if there wasn't an outbound 1000 close code- Parameters:
code- The close codereason- The textual close reason
-
handleFrame
Description copied from interface:WsClientFrameHandlerHandles the WebSocket frame and sends a response back to the server, if necessary- Specified by:
handleFramein interfaceWsClientFrameHandler- Parameters:
ctx- TheChannelHandlerContextof the sessionframe- TheWebSocketFrameto process
-
handshakeComplete
Description copied from interface:WsClientFrameHandlerHandles the handshake complete event- Specified by:
handshakeCompletein interfaceWsClientFrameHandler- Parameters:
ctx- TheChannelHandlerContextof the session
-
onClose
public void onClose()Description copied from interface:WsClientFrameHandlerHandles the channel closing for any reason.- Specified by:
onClosein interfaceWsClientFrameHandler
-
close
Closes the socket- Parameters:
code- The close codereason- The textual close reason
-
shutdown
public void shutdown()Closes the connection normally. Exceptions are discarded
-