I'm pretty sure that I've found a good way of getting everything I need now, using Ravagernl's suggestion.
Lua Code:
local frame;
for i = 1, NUM_CHAT_FRAMES do
frame = _G["ChatFrame"..i];
frame:HookScript("OnEvent", function(self, event, ...)
self.lastEvent = (self.isDocked and MONITORED_EVENTS[event]) and event;
end);
hooksecurefunc(frame, "AddMessage", function(self, message, r, g, b, ...)
if (not self.lastEvent) then return; end
-- do my thing...
end);
end
That way I have a guarantee that the message will actually be displayed. It should be reliable because self.lastEvent will always be obtained immediately before AddMessage gets called.
Cheers all