View Single Post
09-11-16, 09:52 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Made some changes for joined/left guild messages, and to more easily support adding more message types:

Code:
local DESTINATION = UIErrorsFrame

local messageTypes = {
	{
		-- X has come online
		pattern = ERR_FRIEND_ONLINE_SS:gsub("%%s", "(.+)"):gsub("[%[%]]", "%%%1"),
		r = 0.3, g = 1, b = 0.3,
	},
	{
		-- X has gone online
		pattern = ERR_FRIEND_OFFLINE_S:gsub("%%s", "(.+)"),
		r = 0.6, g = 0.6, b = 0.6,
	},
	{
		-- X has joined the guild
		pattern = ERR_GUILD_JOIN_S:gsub("%%s", "(.+)"),
		r = 0.3, g = 1, b = 0.3,
	},
	{
		-- X has left the guild
		pattern = ERR_GUILD_LEAVE_S:gsub("%%s", "(.+)"),
		r = 0.6, g = 0.6, b = 0.6,
	},
}

local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_SYSTEM")
f:SetScript("OnEvent", function(self, event, text)
	for i = 1, #messageTypes do
		local messageType = messageTypes[i]
		if text:match(messageType.pattern) then
			if not DESTINATION:IsMouseEnabled() then
				-- Remove link brackets if the destination frame doesn't support clicking
				text = text:gsub("%[(.-)%]", "%1")
			end
			return DESTINATION:AddMessage(text, messageType.r, messageType.g, messageType.b)
		end
	end
end)
__________________
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