ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   EVENT_CHAT_MESSAGE_CHANNEL Question (https://www.esoui.com/forums/showthread.php?t=2295)

Argusus 09/30/14 10:04 PM

EVENT_CHAT_MESSAGE_CHANNEL Question
 
hello,

i'm using the EVENT_CHAT_MESSAGE_CHANNEL event to see if a friend is whispering me, it seems to be working properly but i'm friend that the message display even when its not a direct whisper and its even a "group chat" message to the group we are in. I'd only like to catch when someone whispers me directly rather than seeing the debug statement when the message is in group chat. any ideas?

Code:

function ChatMessageChannel(eventCode, messageType, fromName, text)

local pstPerson = zo_strformat(SI_UNIT_NAME, fromName)

if messageType == CHAT_CATEGORY_WHISPER_INCOMING and then
        d(pstPerson)
        if (IsFriend(pstPerson)) then
                d("A friend just whispered you")
        end
end


end


Ayantir 10/01/14 04:28 AM

Lua Code:
  1. local function ChatMessageChannel(messageType, fromName, text)
  2.    
  3.     if messageType == CHAT_CHANNEL_WHISPER then
  4.    
  5.         -- Don't zo_strformat UserId's
  6.         local pstPerson
  7.         if string.find(from, "@") == nil then
  8.             pstPerson = zo_strformat(SI_UNIT_NAME, fromName)
  9.         end
  10.        
  11.         d(pstPerson)
  12.        
  13.         if (IsFriend(pstPerson)) then
  14.             d("A friend just whispered you")
  15.         end
  16.        
  17.     end
  18.    
  19. end
  20.  
  21. ZO_ChatSystem_AddEventHandler(EVENT_CHAT_MESSAGE_CHANNEL, ChatMessageChannel)

I didn't checked it, but it should work as intended, no?

Garkin 10/01/14 04:54 AM

Quote:

Originally Posted by Ayantir (Post 12433)
Lua Code:
  1. local function ChatMessageChannel(messageType, fromName, text)
  2.    
  3.     if messageType == CHAT_CHANNEL_WHISPER then
  4.    
  5.         -- Don't zo_strformat UserId's
  6.         local pstPerson
  7.         if string.find(from, "@") == nil then
  8.             pstPerson = zo_strformat(SI_UNIT_NAME, fromName)
  9.         end
  10.        
  11.         d(pstPerson)
  12.        
  13.         if (IsFriend(pstPerson)) then
  14.             d("A friend just whispered you")
  15.         end
  16.        
  17.     end
  18.    
  19. end
  20.  
  21. ZO_ChatSystem_AddEventHandler(EVENT_CHAT_MESSAGE_CHANNEL, ChatMessageChannel)

I didn't checked it, but it should work as intended, no?

This function will replace existing event handler, so it can cause conflicts between this and other addons. I'd recommend hooking of the existing event handler.
Lua Code:
  1. local function ChatMessageChannel(messageType, fromName, ...)
  2.     if messageType == CHAT_CHANNEL_WHISPER then
  3.         if IsFriend(fromName) then
  4.             d("A friend just whispered you")
  5.         end
  6.     end
  7. end
  8.  
  9. ZO_PreHook(ZO_ChatSystem_GetEventHandlers(), EVENT_CHAT_MESSAGE_CHANNEL, ChatMessageChannel)

Argusus 10/01/14 05:37 PM

Excellent, thank you both for the help. I'm a newb, wasn't aware of the ZO_Chat Event Handlers.. those seem to be magic. can't find a lot of docs on them.

Sasky 10/01/14 06:15 PM

Main event manager works fine too. I use that in AutoInvite:
Lua Code:
  1. AutoInvite.callback = function(_, messageType, from, message)
  2.     -- ...
  3. end
  4.  
  5. EVENT_MANAGER:RegisterForEvent(AutoInvite.AddonId, EVENT_CHAT_MESSAGE_CHANNEL, AutoInvite.callback)

Garkin 10/01/14 07:41 PM

Quote:

Originally Posted by Sasky (Post 12441)
Main event manager works fine too. I use that in AutoInvite:
Lua Code:
  1. AutoInvite.callback = function(_, messageType, from, message)
  2.     -- ...
  3. end
  4.  
  5. EVENT_MANAGER:RegisterForEvent(AutoInvite.AddonId, EVENT_CHAT_MESSAGE_CHANNEL, AutoInvite.callback)

This solution is probably the best one as it is completely independent on chat handlers, so it should always work.
If you don't need to modify chat output, this is what you are looking for.

Argusus 10/02/14 01:57 PM

Interesting.. Hopefully this stuff will start clicking for me on my own. I'm just looking to recognize if a friend whisps me. And put out a message.

Argusus 10/15/14 10:25 AM

Quote:

Originally Posted by Garkin (Post 12442)
This solution is probably the best one as it is completely independent on chat handlers, so it should always work.
If you don't need to modify chat output, this is what you are looking for.

In my testing messages from friends in group chat, the message type is showing up as CHAT_CHANNEL_WHISPER. Should I be using another constant? I just would like to detect /tell messages to me.

Garkin 10/15/14 10:51 AM

If messages are correcly displayed in the chat, there must be something wrong in your code (like single = instead of double == in the condtion). Chat doesn't use anything else then messageType.

Lua Code:
  1. local function ChatMessageChannel(eventCode, messageType, fromName, text, isFromCustomerService)
  2.     if messageType == CHAT_CHANNEL_WHISPER then
  3.         fromName = IsDecoratedDisplayName(fromName) and fromName or zo_strformat(SI_UNIT_NAME, fromName)
  4.         d(fromName)
  5.         if IsFriend(fromName) then
  6.             d("A friend just whispered you")
  7.         end
  8.     end
  9. end
  10.      
  11. EVENT_MANAGER:RegisterForEvent("MyAddonName", EVENT_CHAT_MESSAGE_CHANNEL, ChatMessageChannel)

Message types are listed here: http://wiki.esoui.com/Globals#MsgChannelType

Argusus 10/15/14 11:01 AM

Quote:

Originally Posted by Garkin (Post 12643)
If messages are correcly displayed in the chat, there must be something wrong in your code (like single = instead of double == in the condtion). Chat doesn't use anything else then messageType.

Lua Code:
  1. function ChatMessageChannel(eventCode, messageType, fromName, text, isFromCustomerService)
  2.     if messageType == CHAT_CHANNEL_WHISPER then
  3.         fromName = IsDecoratedDisplayName(fromName) and fromName or zo_strformat(SI_UNIT_NAME, fromName)
  4.         d(fromName)
  5.         if IsFriend(fromName) then
  6.             d("A friend just whispered you")
  7.         end
  8.     end
  9. end
  10.      
  11. EVENT_MANAGER:RegisterForEvent("MyAddonName", EVENT_CHAT_MESSAGE_CHANNEL, ChatMessageChannel)

Message types are listed here: http://wiki.esoui.com/Globals#MsgChannelType

Oh ok. I'll try that later, thanks again!

Argusus 10/15/14 02:21 PM

Quote:

Originally Posted by Garkin (Post 12643)
If messages are correcly displayed in the chat, there must be something wrong in your code (like single = instead of double == in the condtion). Chat doesn't use anything else then messageType.

Lua Code:
  1. local function ChatMessageChannel(eventCode, messageType, fromName, text, isFromCustomerService)
  2.     if messageType == CHAT_CHANNEL_WHISPER then
  3.         fromName = IsDecoratedDisplayName(fromName) and fromName or zo_strformat(SI_UNIT_NAME, fromName)
  4.         d(fromName)
  5.         if IsFriend(fromName) then
  6.             d("A friend just whispered you")
  7.         end
  8.     end
  9. end
  10.      
  11. EVENT_MANAGER:RegisterForEvent("MyAddonName", EVENT_CHAT_MESSAGE_CHANNEL, ChatMessageChannel)

Message types are listed here: http://wiki.esoui.com/Globals#MsgChannelType

Sorry Garkin, one more thing. I was wondering if you have tried this and see if a plain message in a group chat displays the whisper message when you send a message or someone else does in the group channel rather than the whisper channel?

Garkin 10/15/14 03:24 PM

No didn't try it. But I have checked chat system code and there is no way that chat system will print whisper to the party chat or party message to the whisper. Messages are sorted by category and then printed to the chat to the correct channels.

Lua Code:
  1. category = GetChannelCategoryFromChannel(CHAT_CHANNEL_WHISPER)
  2. --returns CHAT_CATEGORY_WHISPER_INCOMING (3)
  3.  
  4. category = GetChannelCategoryFromChannel(CHAT_CHANNEL_PARTY)
  5. --returns CHAT_CATEGORY_PARTY (7)


If you want to use category the same way as chat system, you can change code to:
Lua Code:
  1. local function ChatMessageChannel(eventCode, messageType, fromName, text, isFromCustomerService)
  2.     if GetChannelCategoryFromChannel(messageType) == CHAT_CATEGORY_WHISPER_INCOMING then
  3.         fromName = IsDecoratedDisplayName(fromName) and fromName or zo_strformat(SI_UNIT_NAME, fromName)
  4.         d(fromName)
  5.         if IsFriend(fromName) then
  6.             d("A friend just whispered you")
  7.         end
  8.     end
  9. end
  10.          
  11. EVENT_MANAGER:RegisterForEvent("MyAddonName", EVENT_CHAT_MESSAGE_CHANNEL, ChatMessageChannel)
But I think it will not make any difference.


All times are GMT -6. The time now is 10:45 PM.

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