ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Blocking Chat messages (https://www.esoui.com/forums/showthread.php?t=8776)

Shawn5150 09/29/19 05:13 AM

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)

Baertram 09/29/19 06:23 AM

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".

Shawn5150 09/29/19 07:23 PM

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)


All times are GMT -6. The time now is 02:12 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI