Intercept Chat Messages - ESOUI
Thread Tools Display Modes
03/29/21, 01:33 PM   #1
Join Date: Mar 2021
Posts: 2
Intercept Chat Messages

I know addons like pChat can filter out spam messages in zone chat and I'm curious how to go about doing this for my own addon. From my research I know I can add a function to the EVENT_CHAT_MESSAGE_CHANNEL but I would assume this does not actually intercept the message it just lets you see what the message is and do something with the information provided, or am I wrong?

For example, would the following code prevent whispers from appearing if I'm in a group instance? This is not exactly what I want to do, its just an example so I can understand things better.
OnChatMessage(eventCode, channelType, senderAcc, message, isCustomerSevice, senderName)
		if IsInGroupInstance() then return end
Now, if I'm correct and this does not intercept the message how would I go about ensuring specific message from this event does not make it through to the chat window?

Thanks for any help you can provide.
  Reply With Quote
03/30/21, 01:33 AM   #2
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 3,440
If you just use a direct event callback to e.g. EVENT_CHAT_MESSAGE_CHANNEL you create a function which will be executed as the event fires ingame. If you return true or false in there this won't block other addon's event callback functions on the same event, nor the vanilla UI callback functions.
So returning true or false won't change the call behaviour.

If you PreHook (using ZO_PreHook -> will register a function that will be called before the "hooked" function) a function you are able to return with true, which will prevent the original function code to run afterwards.
In your example the code line would need to be this then:
Lua Code:
  1. if IsInGroupInstance() then
  2. --return true!! to prevent the original function you have PreHooked to runa fterwards. Return false or nil to let the orig. function run normally afterwards
  3. return true
  4. end

Read more about PreHooks and PostHooks at the Wiki:

For your chat related use-case check this addon for an example e.g.:

It's not the best way to do but for the moment it's using a ZO_preHook on the CHAT_ROUTER function FormatAndAddChatMessage.
This might break other addons which rely on this function, e.g. building a message history, as the messages are stripepd before the other addon might notice it.
But you can use your txt file of your addon and add a line like e.g. ## OptionalDependsOn: pChat rChat to assure these other addons run before your addon and register theire prehook etc before your's then (asuming they do this in EVENT_ADD_ON_LOADED! If they do it later in e.g. EVENT_PLAYER_ACTIVATED, as the chat is special and msot chat related stuff is first ready at this event, it might not change a thing and your PreHook could still break them).

Lua Code:
  1. ZO_PreHook(CHAT_ROUTER, "FormatAndAddChatMessage", AB.spamFilter)

Within AB.spamFilter it returns true then to prevent the execution of the vanilla UI chat message function "FormatAndAddChatMessage", if a spam message was detected in the function AB.spamFilter

Currently the CHAT_ROUTEr only allows 1 chat mesasge handling and formatting function. This makes it hard to add multiple filter functions etc. You can only prehook it, or all addons would need to use the same library which would handle the message formatters internally and call all registered addon's filter/formatting funtions then after another + provide the results.
LibChatmessage was created to do this but is currently not working for that usecase as ZOs had changed the chat stuff some patches ago.
So we need to wait for LibChatMessage2 e.g.

Last edited by Baertram : 03/30/21 at 01:38 AM.
  Reply With Quote
04/08/21, 07:56 AM   #3
Join Date: Mar 2021
Posts: 2
Sorry for the late reply been so busy with the event. Just want to thank you so much for this detailed information, its helped me a lot with the direction I should take with my addon. I was able to successfully pre-hook the function and log chat information with LibDebugLogger, now I will be able to proceed further. If I have any further questions I'll be sure to ask in the forums, thanks again!
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Intercept Chat Messages

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off