The method I presented, using filters as one piece printing and filtering, does seem like it's complicated, but using the filters is the best (or only) way to do what you want without replacing Blizzard objects. I also included duplicate prevention because I have had problems with some addons doing weird stuff with chat filters. Prat and WIM do weird things together when you try to add a filter that does more than filter.
An easier way to use the filters is to have a simple filter that blocks all default events for the event you want to manipulate, while using the event that fired directly. You'll have to specify the ChatFrame to go to since that's not self anymore. Also, keep in mind this blanket method clashes with all other chat addons, since they all use the combo filter method I posted originally and a straight "return true" filter will just kill all changes they do. If you don't have any other chat addons and your addon is meant to be used alone, this is fine.
Here's a piece of code that does what I posted earlier, but standalone without your code:
Lua Code:
-- block ALL channel events from default UI
ChatFrame_AddMessageEventFilter( "CHAT_MSG_CHANNEL", function( ) return true end )
local f = CreateFrame( "frame" )
f:RegisterEvent( "CHAT_MSG_CHANNEL" )
f:SetScript( "OnEvent", function( self, event, ... )
local type = strsub( event, 10 )
local info = ChatTypeInfo[ type ]
arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, _, arg11, arg12 = ...
if event == "CHAT_MSG_CHANNEL" then
arg1 = "|Hchannel:channel:" .. arg8 .. "|h" .. arg8 .. ".|h " .. arg1
if CHAT_TIMESTAMP_FORMAT then
arg1 = BetterDate( CHAT_TIMESTAMP_FORMAT, time( ) ) .. arg1
end
ChatFrame1:AddMessage( arg1, info.r, info.g, info.b, info.id )
end
end )
I also have a way to automatically choose which ChatFrame to post to based on Blizzard's chat settings using IsEventRegistered, but I wanted to keep this simple.