View Single Post
10-04-12, 05:23 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Something like this should work:
Code:
local function TranslateLinks(_, _, message, ...)
	local linkType, linkID, linkText = strmatch(message, "|H(.-):(%d+).*%|h[(.+)%]")
	if linkType == "item" then
		local itemName = GetItemInfo(linkID)
		message = gsub(message, linkText, itemName)
	end
	return false, message, ...
end

local events = {
	"CHAT_MSG_BATTLEGROUND",
	"CHAT_MSG_BATTLEGROUND_LEADER",
	"CHAT_MSG_CHANNEL",
	"CHAT_MSG_GUILD",
	"CHAT_MSG_OFFICER",
	"CHAT_MSG_PARTY",
	"CHAT_MSG_PARTY_LEADER",
	"CHAT_MSG_RAID",
	"CHAT_MSG_RAID_LEADER",
	"CHAT_MSG_SAY",
	"CHAT_MSG_YELL",
}

for _, event in pairs(events) do
	ChatFrame_AddMessageEventFilter(event, TranslateLinks)
end
If the color codes are inside the brackets, the pattern will need to be changed.

You could easily extend it to handle other types of links, though I'm not sure there's a clean way (eg. not tooltip scanning) to get information about quests by their questID, and maybe some other link types.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote