Thread Tools Display Modes
09/29/19, 05:13 AM   #1
Shawn5150
 
Shawn5150's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2019
Posts: 2
Blocking Chat messages

Hello, I'm writing a simple Addon that block Zone Message everywhere except Cyrodiil/Craglorn. The test chat message display I've inserted in the Addon works correctly, the only thing missing is I can't find a way to block chat message from displaying. I've checked the wiki for events/functions but I can't find a way to block them. How should I block chat messages from displaying ?

Here is the code I've written so far.

Lua Code:
  1. ZonePug = {}
  2. ZonePug.name = "ZonePug"
  3.  
  4. function ZonePug.OnInitialized(eventCode, addOnName)
  5.     if (ZonePug.name ~= addOnName) then return end
  6.     EVENT_MANAGER:RegisterForEvent(ZonePug.name, EVENT_CHAT_MESSAGE_CHANNEL, ZonePug.OnChatMessage)
  7. end
  8.  
  9. function ZonePug.OnChatMessage(eventCode, messageType, fromName, text, isFromCustomerService)
  10.     if messageType == CHAT_CHANNEL_ZONE then
  11.         if GetCurrentMapZoneIndex() == 499 or GetCurrentMapZoneIndex() == 37 then
  12.             df("%s has detected a zone message in Craglorn/Cyrodiil, let it display", ZonePug.name)
  13.         else
  14.             df("%s has detected a zone message elsewhere, block it", ZonePug.name)
  15.             -- Insert block code
  16.         end
  17.     else
  18.         df("%s has detected a non zone message, do nothing", ZonePug.name)
  19.     end
  20. end
  21.  
  22. EVENT_MANAGER:RegisterForEvent(ZonePug.name, EVENT_ADD_ON_LOADED, ZonePug.OnInitialized)
  Reply With Quote
09/29/19, 06:23 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,903
You could use a ZO_PreHook to the function CHAT_SYSTEM.OnChatEvent like this e.g.

Lua Code:
  1. function MyOnChatEvent(control, ...)
  2.     --Setting enabled?
  3.     secondsSinceMidnight = 0
  4.     if settings.enableChatBlacklist and settings.chatKeyWords ~= nil and settings.chatKeyWords ~= "" then
  5.         if settings.blacklistedTextToChat then
  6.             --Get the current time
  7.             secondsSinceMidnight = GetSecondsSinceMidnight()
  8.         end
  9.         --Filter the incoming chat message now
  10.         local chatMessageWasBlacklisted = MyFunctionToCheckIfMessageWasBlacklistedWithBooleanReturnCode or false
  11.         if chatMessageWasBlacklisted then
  12.             --Abort the chat event function so no text is shown in the chat
  13.             return true
  14.         end
  15.     end
  16.     --Call the original chat event method now to show the text in the chat
  17.     return false
  18. end
  19. ZO_PreHook(CHAT_SYSTEM, "OnChatEvent", MyOnChatEvent)

The secondsSinceMdinight is only there if you want to implement something like a "do not too often" or "wait 2 seconds before next blacklisted message check is done".
  Reply With Quote
09/29/19, 07:23 PM   #3
Shawn5150
 
Shawn5150's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2019
Posts: 2
Thank you so much ! It seems to have done the trick.
For anyone curious, here is the new code :

Lua Code:
  1. ZonePug = {}
  2. ZonePug.name = "ZonePug"
  3.  
  4. function ZonePug.OnInitialized(eventCode, addOnName)
  5.     if (ZonePug.name ~= addOnName) then return end
  6.     ZO_PreHook(CHAT_SYSTEM, "OnChatEvent", ZonePug.OnChatMessage)
  7. end
  8.  
  9. function ZonePug.OnChatMessage(eventCode, messageType, fromName, text, isFromCustomerService)
  10.     if fromName == CHAT_CHANNEL_ZONE then
  11.         if GetCurrentMapZoneIndex() == 499 or GetCurrentMapZoneIndex() == 37 then
  12.             -- df("%s has detected a zone message in Craglorn/Cyrodiil, let it display", ZonePug.name)
  13.         else
  14.             -- df("%s has detected a zone message elsewhere, block it", ZonePug.name)
  15.             return true
  16.         end
  17.     else
  18.         -- df("%s has detected a non zone message, do nothing", ZonePug.name)
  19.     end
  20. end
  21.  
  22. EVENT_MANAGER:RegisterForEvent(ZonePug.name, EVENT_ADD_ON_LOADED, ZonePug.OnInitialized)
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Blocking 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