What most people do is hook :AddMessage() on all chatframes (except combatlog), and parse that information.
It might be a bit advanced, but if you understand it, here is an example of how I do it in my chat addon:
Lua Code:
local hooks = {}
local abbrev = {
BATTLEGROUND = 'b',
OFFICER = 'o',
GUILD = 'g',
PARTY = 'p',
RAID = 'r',
}
local function Abbreviate(channel)
-- Replaces channel name from the table above, or uses channel numbers
return string.format('|Hchannel:%s|h%s|h', channel, abbrev[channel] or channel:gsub('channel:', ''))
end
local function AddMessage(self, message, ...)
message = message:gsub('|Hchannel:(.-)|h%[(.-)%]|h', Abbreviate)
return hooks[self](self, message, ...)
end
for index = 1, NUM_CHAT_WINDOWS do
if(index ~= 2) then
local frame = _G['ChatFrame'..index]
hooks[frame] = frame.AddMessage
frame.AddMessage = AddMessage
end
end