Originally Posted by pelf
Incidentally, what is the chat type of a message that gets added like this?
Code:
DEFAULT_CHAT_FRAME:AddMessage("Hello, world.")
|
It doesn't have a type. Adding a message directly does not trigger any event handlers.
Originally Posted by pelf
After ChatTypeGroup is defined, a reverse lookup table is created called ChatTypeGroupInverted. Couldn't that be used instead of the one you created in your code? The output is the key into ChatTypeInfo, so I assume it could be.
|
Ah, I missed that. Yes, that will work.
Also, I've realized that using
only a filter could "alert" on messages that aren't actually added to the frame (due to being removed by another filter). If you want to account for that possibility, you
could use an AddMessage hook in conjunction with a filter, but you'd want to be a little smarter about it than just assuming the last event seen by the filter was related to the current message.
Code:
local lastGroup = {}
local ChatTypeGroupInverted = ChatTypeGroupInverted
ChatFrame_AddMessageEventFilter(function(frame, event, ...)
lastGroup[frame] = ChatTypeGroupInverted[event]
end)
local function AddMessage(frame, message, r, g, b)
local group = lastGroup[frame]
lastGroup[frame] = nil
if not group or not MONITORED_EVENTS[group] or not frame.isDocked then return end
local color = ChatTypeInfo[group]
if r == color.r and g == color.g and b == color.b then
-- check group against your settings and flash if desired
end
end
for i = 1, 10 do
local frame = _G["ChatFrame"..i]
hooksecurefunc(frame, "AddMessage", AddMessage)
end
Still not foolproof, but better than no checking at all. Also note that your MONITORED_EVENTS table would need to be changed to hold chat groups (eg. the keys in ChatTypeInfo) rather than all the individual events... if you actually want to let users pick and choose individual events instead of whole groups, just set
event as the value in the filter, and do the
ChatTypeGroupInverted lookup to find the group (to find the color) in the
AddMessage hook after the return check.