Thread Tools Display Modes
11-24-07, 03:28 PM   #1
stqn
A Deviate Faerie Dragon
Join Date: Sep 2007
Posts: 11
ChatFrame_MessageEventHandler() being called multiple times per message

Hi!

I'm writing a small chat message filter. I'm hooking ChatFrame_MessageEventHandler() like this:

Code:
-- Store original ChatFrame_MessageEventHandler
local ORIG_ChatFrame_MessageEventHandler = ChatFrame_MessageEventHandler

-- Replacement for ChatFrame_MessageEventHandler
function ChatFrame_MessageEventHandler( event, ... )
	if event == "CHAT_MSG_MONSTER_SAY" then
		-- Ignore annoying NPC messages
		if	arg2 == "Topper McNabb" or
			arg2 == "Thomas Miller" or
			arg2 == "William" or
			arg2 == "Donna" then
			return
		end
	elseif	event == "CHAT_MSG_SAY" or
		event == "CHAT_MSG_CHANNEL" or
		event == "CHAT_MSG_EMOTE" or
		event == "CHAT_MSG_YELL" then

		say( "event="..event..", arg1="..arg1..", arg2="..arg2..", arg3="..arg3..", arg4="..arg4..", arg5="..arg5..", arg6="..arg6..", arg7="..arg7..", arg8="..arg8..", arg9="..arg9)

	end
	return ORIG_ChatFrame_MessageEventHandler( event, ... )
end
...and it turns out I get SEVEN calls to this function per message received in the "LookingForGroup" channel! (don't know about other channels as noone is talking in Desolace ) Seven identical events. The text is output in the chat frame right after the first event is received, and then the 6 others follow.

Is this normal? I can simply process all 7 events like the first one, but it seems like a waste of resources...

Last edited by stqn : 11-24-07 at 03:31 PM.
  Reply With Quote
11-24-07, 03:56 PM   #2
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Thats because its being sent to the 7 Chat frames. I would suggest taking a look at how idChat does it.
  Reply With Quote
11-24-07, 09:38 PM   #3
stqn
A Deviate Faerie Dragon
Join Date: Sep 2007
Posts: 11
Ah, I see, thanks... Looks like the best way would be to hook the function that calls ChatFrame_MessageEventHandler() for each chat frame... If it's possible.

I've googled for idChat and found some old source code, but it's not entirely clear to me (not a single useful comment inside.)

For now processing each message 7 times is not so bad; my addon is still nowhere as CPU-hungry as other addons I'm using . However I'd like to optimize this somehow.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » ChatFrame_MessageEventHandler() being called multiple times per message

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