PageRenderTime 142ms CodeModel.GetById 81ms app.highlight 2ms RepoModel.GetById 58ms app.codeStats 0ms

/Tukui/modules/chat/blizzfixrealidlink.lua

http://github.com/Asphyxia/Tukui
Lua | 47 lines | 40 code | 4 blank | 3 comment | 14 complexity | d05e73a52bd4b3209613563620caf655 MD5 | raw file
 1local function GetLinkColor(data)
 2	local type, id, arg1 = string.match(data, '(%w+):(%d+):(%d+)')
 3	
 4	-- prevent lua error for unknown item type and return yellow for these items
 5	if not type then return '|cffffd000' end
 6	
 7	if(type == 'item') then
 8		local _, _, quality = GetItemInfo(id)
 9		if(quality) then
10			local _, _, _, hex = GetItemQualityColor(quality)
11			return hex
12		else
13			-- Item is not cached yet, show a white color instead
14			-- Would like to fix this somehow
15			return '|cffffffff'
16		end
17	elseif(type == 'quest') then
18		local color = GetQuestDifficultyColor(arg1)
19		return format('|cff%02x%02x%02x', color.r * 255, color.g * 255, color.b * 255)
20	elseif(type == 'spell') then
21		return '|cff71d5ff'
22	elseif(type == 'achievement') then
23		return '|cffffff00'
24	elseif(type == 'trade' or type == 'enchant') then
25		return '|cffffd000'
26	elseif(type == 'instancelock') then
27		return '|cffff8000'
28	elseif(type == 'glyph') then
29		return '|cff66bbff'
30	elseif(type == 'talent') then
31		return '|cff4e96f7'
32	elseif(type == 'levelup') then
33		return '|cffFF4E00'
34	end
35end
36
37local function AddLinkColors(self, event, msg, ...)
38	local data = string.match(msg, '|H(.-)|h(.-)|h')
39	if(data) then
40		return false, msg:gsub('|H(.-)|h(.-)|h', GetLinkColor(data) .. '|H%1|h%2|h|r'), ...
41	else
42		return false, msg, ...
43	end
44end
45
46ChatFrame_AddMessageEventFilter('CHAT_MSG_BN_WHISPER', AddLinkColors)
47ChatFrame_AddMessageEventFilter('CHAT_MSG_BN_WHISPER_INFORM', AddLinkColors)