I wrote a mod (ForumName2 on WoWI) a while back that pastes a custom note next to peoples' names in chat messages by running the code below in a hook of ChatFrame.AddMessage for each chat frame. In the post 4.0 UI code though, the code below doesn't do anything because "event" doesn't exist.
function ForumName2:AddMessage(frame, msg, ...)
if(event == "CHAT_MSG_SYSTEM") then
for i, info in pairs(systemMessageInfo) do
local output = self:SystemMessageHelper(msg, info, string_match(msg, info.pattern))
if(output) then
msg = output
break
end
end
elseif(chatEvents[event]) then
local note = self:GetNote(arg2)
if note then
msg = string_gsub(msg, "|h(.*)" .. arg2 .. "(.*)|h", "|h%1" .. arg2 .. " (" .. note .. ")" .. "%2|h", 1)
end
end
self.hooks[frame]["AddMessage"](frame, msg, ...)
end
I tried changing this to use the chat message filter system, but the message you are passed in a chat filter does not contain the full formatting so I can't put the note next to the player's name as in the above code. I also tried just changing the name (which IS passed to you in the chat filter) but this causes issues with display in further messages.
So, I'm looking for a way to either a) get access to "event" in ChatFrame_AddMessage or b) accomplish the above using chat message filters. Any ideas?
I wrote a mod (ForumName2 on WoWI) a while back that pastes a custom note next to peoples' names in chat messages by running the code below in a hook of ChatFrame.AddMessage for each chat frame. In the post 4.0 UI code though, the code below doesn't do anything because "event" doesn't exist.
function ForumName2:AddMessage(frame, msg, ...)
if(event == "CHAT_MSG_SYSTEM") then
for i, info in pairs(systemMessageInfo) do
local output = self:SystemMessageHelper(msg, info, string_match(msg, info.pattern))
if(output) then
msg = output
break
end
end
elseif(chatEvents[event]) then
local note = self:GetNote(arg2)
if note then
msg = string_gsub(msg, "|h(.*)" .. arg2 .. "(.*)|h", "|h%1" .. arg2 .. " (" .. note .. ")" .. "%2|h", 1)
end
end
self.hooks[frame]["AddMessage"](frame, msg, ...)
end
I tried changing this to use the chat message filter system, but the message you are passed in a chat filter does not contain the full formatting so I can't put the note next to the player's name as in the above code. I also tried just changing the name (which IS passed to you in the chat filter) but this causes issues with display in further messages.
So, I'm looking for a way to either a) get access to "event" in ChatFrame_AddMessage or b) accomplish the above using chat message filters. Any ideas?
function ForumName2:AddMessage([B]event[/B], msg, ...)
if(event == "CHAT_MSG_SYSTEM") then
for i, info in pairs(systemMessageInfo) do
local output = self:SystemMessageHelper(msg, info, string_match(msg, info.pattern))
if(output) then
msg = output
break
end
end
elseif(chatEvents[event]) then
local note = self:GetNote(arg2)
if note then
msg = string_gsub(msg, "|h(.*)" .. arg2 .. "(.*)|h", "|h%1" .. arg2 .. " (" .. note .. ")" .. "%2|h", 1)
end
end
self.hooks[[B]self[/B]]["AddMessage"]([B]self[/B], event, msg, ...)
end
Since that's the only code you posted, I'm going to assume that you know how to fix everything else that's related.
@egingell: The chat frame's AddMessage method doesn't get an event parameter.
@arnath2: The other stuff is relevant though; the global arg2 etc are no longer set, so the parts of your code that look for those will fail.
Anyway, I solve this "problem" in my chat addon by just looking for player name links and not worrying about which event generated the message. Here's the relevant code, somewhat adapted for your purposes:
local nameReplacements = {
["Phanxtwo"] = "Phanx",
["Somedude"] = "Dude",
["Joesalt"] = "Joe",
}
local hooks = { }
local PLAYER_LINK = "|Hplayer:%s|h[%s]|h"
local function AddMessage(frame, message, ...)
if type(message) == "string" then
local plink, pdata, pname = message:match("(|Hplayer:(.-)|h%[(.-)%]|h)")
if plink then
message = message:replace(plink, PLAYER_LINK:format(pdata, nameReplacements[pname] or pname))
end
end
return hooks[frame].AddMessage(frame, message, ...)
end
hooks[ChatFrame1].AddMessage = ChatFrame1.AddMessage
ChatFrame1.AddMessage = AddMessage
The type check on message is needed because some addons sometimes pass random crap to AddMessage that string functions choke on, and I figured just making sure it was a string was easier than dealing with an endless parade of bug reports from people using out-of-date versions of poorly written addons that hadn't been updated in years anyway. :p
Did they change something about how the dropdown that shows up when you right click a player link in chat works? Before, if I changed the player name (the stuff inside |h |h), everything worked just fine. However, now (post 4.0) when I do this, I get the following results:
Because it for some reason thinks the player's name is "Laud (TestNote)", when I try to whisper or invite through this dropdown, it fails because the player doesn't exist.
1) Does anyone know if something changed about this behavior in the 4.0 patch?
2) Any way to avoid this problem? I basically copied Phanx's code from above.
I tried using message filters and it had the problem I had above. Fixed the old AddMessage hook I had but forgot to remove the message filters and re-add the hooks.
I tried changing this to use the chat message filter system, but the message you are passed in a chat filter does not contain the full formatting so I can't put the note next to the player's name as in the above code. I also tried just changing the name (which IS passed to you in the chat filter) but this causes issues with display in further messages.
So, I'm looking for a way to either a) get access to "event" in ChatFrame_AddMessage or b) accomplish the above using chat message filters. Any ideas?
Since that's the only code you posted, I'm going to assume that you know how to fix everything else that's related.
I didn't notice the arg2.
Anyway, I was referring to where the function is being called from.
Fix arg2 by declaring it.
local arg1, arg2 = ... will do.
@arnath2: The other stuff is relevant though; the global arg2 etc are no longer set, so the parts of your code that look for those will fail.
Anyway, I solve this "problem" in my chat addon by just looking for player name links and not worrying about which event generated the message. Here's the relevant code, somewhat adapted for your purposes:
The type check on message is needed because some addons sometimes pass random crap to AddMessage that string functions choke on, and I figured just making sure it was a string was easier than dealing with an endless parade of bug reports from people using out-of-date versions of poorly written addons that hadn't been updated in years anyway. :p
Oops. I didn't notice it was an :AddMessage(). I was preoccupied by the improperly used self, and frame variables.
Because it for some reason thinks the player's name is "Laud (TestNote)", when I try to whisper or invite through this dropdown, it fails because the player doesn't exist.
1) Does anyone know if something changed about this behavior in the 4.0 patch?
2) Any way to avoid this problem? I basically copied Phanx's code from above.
If you want to copy some working (ugly) code which does exactly that kind of replacement, take a peek at Ouro Guild Alts.
I tried using message filters and it had the problem I had above. Fixed the old AddMessage hook I had but forgot to remove the message filters and re-add the hooks.