Class TwitchMessageInterface

java.lang.Object
java.util.concurrent.SubmissionPublisher<TMIMessage>
com.gmt2001.twitch.tmi.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 Details

    • TwitchMessageInterface

      public TwitchMessageInterface()
      Initializes the Twitch Message Interface. Creates a new WSClient, then initializes all processors and starts connecting
  • Method Details

    • privMsgMaxLength

      public int privMsgMaxLength(String channel, boolean isAction, String replyToId)
      Calculates 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 id tag from the TMIMessage.tags of the message that is being replied to; null if not used
      Returns:
    • rateLimiter

      public WindowedSwitchingRateLimiter rateLimiter()
      Returns the WindowedSwitchingRateLimiter used to prevent PRIVMSG spam
      Returns:
      The rate limiter
    • sendPing

      public void sendPing()
      Forces a PING to be sent
    • sendActionPrivMessage

      public void sendActionPrivMessage(String channel, String message)
      Sends an IRC PRIVMSG command with the /me ACTION specifier. If there are no tokens left on rateLimiter, the message is silently dropped
      Parameters:
      channel - The channel to send to
      message - The chat message
    • sendPrivMessage

      public void sendPrivMessage(String channel, String message)
      Sends an IRC PRIVMSG command. If the message starts with /me, then it is passed to sendActionPrivMessage(java.lang.String, java.lang.String) instead. If there are no tokens left on rateLimiter, the message is silently dropped
      Parameters:
      channel - The channel to send to
      message - The chat message
    • sendActionPrivMessage

      public void sendActionPrivMessage(String channel, String message, String replyToId)
      Sends an IRC PRIVMSG command with the /me ACTION specifier. If there are no tokens left on rateLimiter, the message is silently dropped
      Parameters:
      channel - The channel to send to
      message - The chat message
      replyToId - The id tag from the TMIMessage.tags of the message that is being replied to
    • sendPrivMessage

      public void sendPrivMessage(String channel, String message, String replyToId)
      Sends an IRC PRIVMSG command as a reply to another message. If the message starts with /me, then it is passed to sendActionPrivMessage(java.lang.String, java.lang.String, java.lang.String) instead. If there are no tokens left on rateLimiter, the message is silently dropped
      Parameters:
      channel - The channel to send to
      message - The chat message
      replyToId - The id tag from the TMIMessage.tags of the message that is being replied to
    • sendCommand

      public void sendCommand(String command, String parameter)
      Sends an IRC command with parameter component
      Parameters:
      command - The IRC command
      parameter - The IRC parameter
    • sendCommand

      public void sendCommand(Map<String,String> tags, String command, String parameter)
      Sends an IRC command with tags and parameter component
      Parameters:
      tags - The IRCv3 tags
      command - The IRC command
      parameter - The IRC parameter
    • sendChannelCommand

      public void sendChannelCommand(String command, String channel, String parameter)
      Sends an IRC command with channel and parameter components
      Parameters:
      command - The IRC command
      channel - The channel to send to
      parameter - 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. If null or 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
    • sendRaw

      public void sendRaw(String message)
      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:
      true if the underlying socket is connected. Does not indicate anything about the state other than that the raw socket is connected
    • onMessages

      public void onMessages(String messages)
      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

      public void onClose(int code, String reason)
      Notifies 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
    • handleFrame

      public void handleFrame(ChannelHandlerContext ctx, WebSocketFrame frame)
      Description copied from interface: WsClientFrameHandler
      Handles the WebSocket frame and sends a response back to the server, if necessary
      Specified by:
      handleFrame in interface WsClientFrameHandler
      Parameters:
      ctx - The ChannelHandlerContext of the session
      frame - The WebSocketFrame to process
    • handshakeComplete

      public void handshakeComplete(ChannelHandlerContext ctx)
      Description copied from interface: WsClientFrameHandler
      Handles the handshake complete event
      Specified by:
      handshakeComplete in interface WsClientFrameHandler
      Parameters:
      ctx - The ChannelHandlerContext of the session
    • onClose

      public void onClose()
      Description copied from interface: WsClientFrameHandler
      Handles the channel closing for any reason.
      Specified by:
      onClose in interface WsClientFrameHandler
    • close

      public void close(int code, String reason)
      Closes the socket
      Parameters:
      code - The close code
      reason - The textual close reason
    • shutdown

      public void shutdown()
      Closes the connection normally. Exceptions are discarded