Skip to main content

ChatRoomMessageHandler

A chat message handler.

This is used in ChatRoomMessage to perform filtering and actions on the recieved message. You can register one of those with ChatRoomRegisterMessageHandler if you need to peek at incoming messages.

Message processing is done in three phases:

  • all pre-handlers are called
  • metadata extraction & tag substitutions are collected from the message's dictionary, then latter are applied to the message's contents.
  • finally, post-handlers are called.

The handler's priority determines when the handler will get executed:

  • Negative values make the handler run before metadata extraction
  • Positive values make it run afterward. In both cases, lower values mean higher priority, so -100 handler will run before a -1, and a 1 handler will run before a 100.

The return from the callback determines what will happen: if it's true, message processing will stop, making the filter act like a handler. If it's false, then it will continue. You can also return an object with a msg property if the handler is a transformation and wishes to update the message's contents inflight and/or a skip property if you'd like to cause a subsequent handler to not be called.

@warning

Note that the in-flight message is only escaped when it gets sent to the chat log via ChatRoomMessageDisplay. If you're manipulating that by any other means, make sure to call ChatRoomEscapeEntities on its content to close any injection attacks.

A few notable priority values are:

-200: ghosted player cutoff -1: default Hidden message processing (and cutoff) 0: emotes reformatting 100: sensory-deprivation processing 200: automatic actions on others' cutoff 300: sensory-deprivation cutoff. 500: usually output handlers. That's when audio, notifications and the message being added to the chat happens.

Hidden messages never make it to post-processing.

Index

Properties

Callback

Callback: (data: ServerChatRoomMessage, sender: Character, msg: string, metadata?: IChatRoomMessageMetadata) => boolean | { msg?: string; skip?: (handler: ChatRoomMessageHandler) => boolean }

Actual action to perform.

@returns

true if the message was handled and the processing should stop, false otherwise.


Type declaration

optionalDescription

Description?: string

A short description of what the handler does. For debugging purposes

Priority

Priority: number

This handler's priority, used to determine when the code should run.

Page Options