Class Chat

java.lang.Object
privbot.hooks.Chat

public final class Chat extends Object
Chat message reading and sending via the RuneLite Client.

On RSPS clients where client.getMessages() may not be populated, containsMessage(String, int) falls back to a widget tree walk (same as DIALOG_CONTAINS) so that both chatbox text and dialog text are checked.

Sending: Lines starting with :: type into the game canvas and press Enter (the same keyboard path as the Builder's type-text and send-Enter steps). Other lines use setVarcStrValue + script 168 first.

  • Constructor Details

    • Chat

      public Chat(net.runelite.api.Client client)
      Parameters:
      client - the client
  • Method Details

    • recordMessage

      public static void recordMessage(String message)
      Record a chat message into the shared buffer. Call this from a @Subscribe public void onChatMessage(ChatMessage) handler on the Plugin class — exactly the same pattern as CoxPlugin.
    • clearMessageBuffer

      public static void clearMessageBuffer()
      Clear the message buffer (e.g. on plugin shutdown or script stop).
    • sendMessage

      @Deprecated public boolean sendMessage(String message)
      Deprecated.
      says nothing about where the text goes, and its non-command branch (and its command branch on the client thread) sends PUBLIC chat. Use sendCommand(String) for :: commands; public chat is sendPublic(String), which is explicit and currently unsupported.
      Sends a chat line. Client commands (::...) are typed on the game canvas with Enter (RSPS/Orion often ignores varc+script injection); other text uses varc + script 168. Safe from the script thread — command typing runs on the caller thread after a short client-thread canvas resolve, never with Thread.sleep on the game thread.
      Parameters:
      message - a ::command or a public chat line
      Returns:
      true when something was dispatched (the varc branch answers true even where it does nothing)
    • typeOnGameCanvas

      public boolean typeOnGameCanvas(String text, boolean sendEnter)
      Types arbitrary text into the focused game input and optionally presses Enter — same behaviour as workflow TypeTextAction / SendEnterAction.
    • addGameMessage

      public boolean addGameMessage(String message)
      Adds a local game message to the chatbox (only this client sees it; nothing is sent).
      Parameters:
      message - the text
      Returns:
      whether it was added
    • getRecentMessages

      public List<String> getRecentMessages(int limit)
      Recent chat lines, newest first: the event-fed buffer (recordMessage(java.lang.String)) when it has lines, else the client's message list.
      Parameters:
      limit - at most this many
      Returns:
      the lines (empty when none or unreadable)
    • containsMessage

      public boolean containsMessage(String substring, int lookback)
      Check if any recent chat message contains the substring (case-insensitive). First checks RuneLite message buffer; if empty, falls back to a full widget tree walk so RSPS clients that don't populate the message buffer still work.
    • containsMessage

      public boolean containsMessage(String substring)
      containsMessage(String, int) over the last 20 lines.
      Parameters:
      substring - the text, case-insensitive
      Returns:
      whether a recent line contains it
    • containsMessage

      public boolean containsMessage(net.runelite.api.ChatMessageType type, String substring, int lookback)
      Parameters:
      type - the message type
      substring - the text, case-insensitive
      lookback - how many recent lines to check
      Returns:
      whether one of them has that type and contains the text
    • sendCommand

      public boolean sendCommand(String command)
      Sends a client command (::home, ::bank) the way a player does: typed on the game canvas and submitted with Enter, through the same keyboard path as sendMessage(String)'s command branch and the Builder's TypeText action. A leading :: is added when missing.

      Refused (false, logged) rather than risked:

      • on the client thread or the EDT (typing paces itself with sleeps; call from the script worker);
      • while an enter-amount / enter-text prompt is open, or when that cannot be read (Dialogue.observedEnterInputOpen()): the characters would go into the prompt. Today the prompt state is readable on Elorin and on RuneLite-API servers (Orion); on Impact and SpawnPK it cannot be read yet, so this answers false there;
      • for text with a line break, which would submit two lines.
      Unlike sendMessage, it never falls back to the varc/script path, which sends public chat.

      Returns dispatch acceptance only: verify the command's effect (a teleport landed, an interface opened).

      Parameters:
      command - the command, with or without the leading ::
      Returns:
      true when the line was typed and submitted
    • sendPublic

      public boolean sendPublic(String text)
      Public chat, said explicitly. No server has a verified, safe path for it yet, so this answers false and logs UNSUPPORTED everywhere: the existing varc/script path (sendMessage(String)'s non-command branch) is unverified (the SDK compatibility matrix marks chat send unsupported on Impact, Elorin and Orion), and typing on the canvas is how text meant for a prompt ends up in public chat. Never emulate it with key presses.
      Parameters:
      text - the line a player would say
      Returns:
      false until a server gains a verified path