Thread Tools Display Modes
09/30/14, 10:04 PM   #1
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
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
  Reply With Quote
10/01/14, 04:28 AM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
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?

Last edited by Ayantir : 10/01/14 at 04:37 AM.
  Reply With Quote
10/01/14, 04:54 AM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Ayantir View Post
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)
  Reply With Quote
10/01/14, 05:37 PM   #4
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
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.
  Reply With Quote
10/01/14, 06:15 PM   #5
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 231
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)
  Reply With Quote
10/01/14, 07:41 PM   #6
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Sasky View Post
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.

Last edited by Garkin : 10/01/14 at 07:47 PM.
  Reply With Quote
10/02/14, 01:57 PM   #7
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
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.
  Reply With Quote
10/15/14, 10:25 AM   #8
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Originally Posted by Garkin View Post
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.
  Reply With Quote
10/15/14, 10:51 AM   #9
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
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

Last edited by Garkin : 10/15/14 at 11:08 AM. Reason: function is now local...
  Reply With Quote
10/15/14, 11:01 AM   #10
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Originally Posted by Garkin View Post
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!
  Reply With Quote
10/15/14, 02:21 PM   #11
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Originally Posted by Garkin View Post
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?
  Reply With Quote
10/15/14, 03:24 PM   #12
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
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.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » EVENT_CHAT_MESSAGE_CHANNEL Question


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