Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local unusedVariable, playerClass = UnitClass('player')
- local playerClassColorTable = RAID_CLASS_COLORS[playerClass]
- local playerCharacterName = UnitName('player')..'-'..GetRealmName()
- local eventTable = {}
- table.insert(eventTable, 'CHAT_MSG_SAY')
- table.insert(eventTable, 'CHAT_MSG_YELL')
- table.insert(eventTable, 'CHAT_MSG_EMOTE')
- table.insert(eventTable, 'CHAT_MSG_TEXT_EMOTE')
- table.insert(eventTable, 'CHAT_MSG_CHANNEL')
- table.insert(eventTable, 'CHAT_MSG_CHANNEL_NOTICE')
- table.insert(eventTable, 'CHAT_MSG_WHISPER')
- table.insert(eventTable, 'CHAT_MSG_WHISPER_INFORM')
- table.insert(eventTable, 'CHAT_MSG_BN_WHISPER')
- table.insert(eventTable, 'CHAT_MSG_BN_WHISPER_INFORM')
- table.insert(eventTable, 'CHAT_MSG_GUILD')
- table.insert(eventTable, 'CHAT_MSG_OFFICER')
- table.insert(eventTable, 'CHAT_MSG_PARTY')
- table.insert(eventTable, 'CHAT_MSG_PARTY_LEADER')
- table.insert(eventTable, 'CHAT_MSG_INSTANCE_CHAT')
- table.insert(eventTable, 'CHAT_MSG_INSTANCE_CHAT_LEADER')
- table.insert(eventTable, 'CHAT_MSG_RAID')
- table.insert(eventTable, 'CHAT_MSG_RAID_LEADER')
- table.insert(eventTable, 'CHAT_MSG_RAID_WARNING')
- table.insert(eventTable, 'CHAT_MSG_RAID_BOSS_WHISPER')
- table.insert(eventTable, 'CHAT_MSG_RAID_BOSS_EMOTE')
- table.insert(eventTable, 'CHAT_MSG_MONSTER_SAY')
- table.insert(eventTable, 'CHAT_MSG_MONSTER_YELL')
- table.insert(eventTable, 'CHAT_MSG_MONSTER_EMOTE')
- table.insert(eventTable, 'CHAT_MSG_MONSTER_WHISPER')
- table.insert(eventTable, 'CHAT_MSG_SYSTEM')
- table.insert(eventTable, 'CHAT_MSG_SKILL')
- table.insert(eventTable, 'CHAT_MSG_ACHIEVEMENT')
- table.insert(eventTable, 'CHAT_MSG_GUILD_ACHIEVEMENT')
- table.insert(eventTable, 'CHAT_MSG_LOOT')
- table.insert(eventTable, 'CHAT_MSG_CURRENCY')
- table.insert(eventTable, 'CHAT_MSG_MONEY')
- table.insert(eventTable, 'CHAT_MSG_COMBAT_FACTION_CHANGE')
- table.insert(eventTable, 'CHAT_MSG_COMBAT_HONOR_GAIN')
- table.insert(eventTable, 'CHAT_MSG_BG_SYSTEM_NEUTRAL')
- table.insert(eventTable, 'CHAT_MSG_BG_SYSTEM_ALLIANCE')
- table.insert(eventTable, 'CHAT_MSG_BG_SYSTEM_HORDE')
- local f = CreateFrame('frame')
- for i = 1, #eventTable do
- f:RegisterEvent(eventTable[i])
- ChatFrame_AddMessageEventFilter(eventTable[i], function() return true end)
- end
- local g = CreateFrame('frame')
- g:RegisterEvent('UPDATE_CHAT_COLOR')
- --this will find any channels that are associated with numbers, that is custom channels
- --it does this by first removing the 'CHANNEL' before the number, and converting the string to a number
- --since there are many strings that don't get converted, we find only the ones that are numbers by our if check
- --we then make a table entry for the color rgb so when a player leaves that channel, and no color is associated anymore,
- --the leaving text still matches the color they left
- local channelColorHolderTable = {}
- g:SetScript('OnEvent', function(self, event, ...)
- local channelNumber, r, g, b = ...
- channelNumber = channelNumber:gsub('CHANNEL', '')
- channelNumber = tonumber(channelNumber)
- if channelNumber then
- channelColorHolderTable[channelNumber] = {}
- channelColorHolderTable[channelNumber].r, channelColorHolderTable[channelNumber].g, channelColorHolderTable[channelNumber].b = r, g, b
- end
- end)
- local function rgbPercToHex(r, g, b) --converts decimal rgb to a hexcode
- r = r <= 1 and r >= 0 and r or 0
- g = g <= 1 and g >= 0 and g or 0
- b = b <= 1 and b >= 0 and b or 0
- return string.format('ff%02x%02x%02x', r*255, g*255, b*255)
- end
- --this table holds all the abbreviations for our channel names, note the space before and after to allow proper separation while reducing the need to concactenate afterwards
- local channelAbbreviationsTable = {
- ['SAY'] = ' [S] ',
- ['YELL'] = ' [Y] ',
- ['EMOTE'] = ' [E] ',
- ['TEXT_EMOTE'] = ' [E] ',
- ['PARTY'] = ' [P] ',
- ['PARTY_LEADER'] = ' [L] ',
- ['INSTANCE_CHAT'] = ' [I] ',
- ['INSTANCE_CHAT_LEADER']= ' [L] ',
- ['RAID'] = ' [R] ',
- ['RAID_LEADER'] = ' [L] ',
- ['RAID_WARNING'] = ' [W] ',
- ['OFFICER'] = ' [O] ',
- ['GUILD'] = ' [G] ',
- ['MONSTER_SAY'] = ' [S] ',
- ['MONSTER_YELL'] = ' [Y] ',
- ['MONSTER_WHISPER'] = ' [F] ',
- }
- local letterTable, coloredMessage, holder, placeHolderWord = {}, {} --letterTable will be used to hold our individual words free from any punctuation or numbers, coloredMessage is ultimately what we will return, holder is used to find strings of letters and insert them into our letterTable, placeHolderWord is so we can perform a final gsub at the end
- local function hexColorNames(chatMessage, modChatColor)
- wipe(coloredMessage) --blizzard function that will clear our table
- for word in gmatch(chatMessage, '%S+') do --look at each word individually, separating them by spaces (we look for non-whitespace)
- placeHolderWord = word
- placeHolderWord = placeHolderWord:gsub('%b{}', '') --we immediately remove all instances of {skull} etc for addons that glue it to people's names
- local _
- local class, name, coloredName = nil, nil, nil
- wipe(letterTable) --wipe our letterTable from any previous entries
- while strfind(placeHolderWord, '%a') do --we're going to be removing all blocks of letters from our word
- holder = placeHolderWord:match('[^%p%s%d]+') --extract our blocks of letters, we don't want numbers, spaces, or punctuation, (we use this instead of [%a]+ because it allows for non-ascii characters
- if holder then --safety so we don't throw an error inserting nil into a table
- table.insert(letterTable, holder) --put our letter block into our letterTable holder
- placeHolderWord = placeHolderWord:gsub(holder, '') --names can ultimately be a simple name from your realm, a name from a different realm like john-gurbashi, or a name from a realm with a ' like john-kel'thuzad
- end
- end
- if (#letterTable == 1 and letterTable[1]:lower() ~= 'player' and letterTable[1]:lower() ~= 'target' and letterTable[1]:lower() ~= 'focus' and letterTable[1]:lower() ~= 'pet') then --our table is only 1 entry long, and therefore it can't be someone on another realm
- name = letterTable[1]
- _, class = UnitClass(letterTable[1])
- elseif #letterTable == 2 then --our table is 2 entries long, so it's someone off realm, but not on a realm that has a ' in it
- if strfind(word, 'Area52') then
- name = letterTable[1]..'%-'..letterTable[2]..'52' --we use the % so we can gsub; the '52' won't be transferred to letterTable as it specifically excludes numbers, this is a shitty hack for people on Area 52
- _, class = UnitClass(letterTable[1]..'-'..letterTable[2]..'52')
- else
- name = letterTable[1]..'%-'..letterTable[2] --we use the % so we can gsub
- _, class = UnitClass(letterTable[1]..'-'..letterTable[2])
- end
- elseif #letterTable >= 3 then --we use >= rather than == incase someone adds letters afterwards to try and catch more names this way
- name = letterTable[1]..'%-'..letterTable[2].."%'"..letterTable[3] --we use the % in front of the magic characters so we can gsub
- _, class = UnitClass(letterTable[1]..'-'..letterTable[2].."'"..letterTable[3])
- end
- if (class and class ~= '') then --if we actually got a class and it's not '', then we can modify the text to have class color and return back to the text color before it
- coloredName = '|c'..RAID_CLASS_COLORS[class].colorStr..name..'|c'..modChatColor
- word = word:gsub(name, coloredName)
- end
- table.insert(coloredMessage, word)
- end
- return(table.concat(coloredMessage, ' '))
- end
- local function modHexColorNames(chatMessage, modChatColor) --differs from hexColorNames because it class colors 'You' and 'you' and 'Your' and 'your' and removes realmNames from players
- wipe(coloredMessage) --blizzard function that will clear our table
- local class, name, coloredName
- for word in gmatch(chatMessage, '%S+') do --look at each word individually, separating them by spaces (we look for non-whitespace)
- placeHolderWord = word
- placeHolderWord = placeHolderWord:gsub('%b{}', '') --we immediately remove all instances of '{skull}' etc for addons that glue it to people's names
- placeHolderWord = placeHolderWord:gsub('%|cFFFF0000', '') --we immediately remove all instances of red colors in front of people's names that raid_boss_emote likes to use
- local _
- class, name, coloredName = nil, nil, nil
- wipe(letterTable) --wipe our letterTable from any previous entries
- while strfind(placeHolderWord, '%a') do --we're going to be removing all blocks of letters from our word
- holder = placeHolderWord:match('[^%p%s%d]+') --extract our blocks of letters, we don't want numbers, spaces, or punctuation, (we use this instead of [%a]+ because it allows for non-ascii characters
- if holder then --safety so we don't throw an error inserting nil into a table
- table.insert(letterTable, holder) --put our letter block into our letterTable holder
- placeHolderWord = placeHolderWord:gsub(holder, '') --names can ultimately be a simple name from your realm, a name with a realm, or a name with a realm with a ' in it
- end
- end
- for i = 1, 3 do
- if (letterTable[1] and (letterTable[1]:lower() == 'player' or letterTable[1]:lower() == 'target' or letterTable[1]:lower() == 'focus' or letterTable[1]:lower() == 'pet')) then break end --if not strfind(UnitName(letterTable[1]), word) then break end --then we know that the word is not an actual playername but may be a decoy that would make class be true because it's a unitID or playerGUID or something
- if (i == 1 and letterTable[i]) then --the potential name doesn't have a realm
- _, class = UnitClass(letterTable[1])
- if (class and class ~= '') then break end
- elseif (i == 2 and letterTable[i]) then --the potential name has at least a realm name
- if strfind(word, 'Area52') then --hack because our match specifically avoids numbers, Area 52 is the only realm with numbers
- _, class = UnitClass(letterTable[1]..'-'..letterTable[2]..'52')
- if (class and class ~= '') then break end
- else
- _, class = UnitClass(letterTable[1]..'-'..letterTable[2])
- if (class and class ~= '') then break end
- end
- elseif (i == 3 and letterTable[i]) then --the potential name might have a realm and an ' in the realmName
- _, class = UnitClass(letterTable[1]..'-'..letterTable[2].."'"..letterTable[3])
- end
- end
- if (class and class ~= '') then --if we actually got a class and it's not '' then we can modify the text to have class color and return back to the text color before it
- if #letterTable == 2 then
- word = word:gsub('%-%P+', '') --remove the realm name but preserve any punctuation attached at the end
- elseif #letterTable == 3 then
- word = word:gsub('%-%P+', '') --remove the realm name, but we're going to get stuck on the '
- word = word:gsub("%'%P+", '') --remove the rest of the realm name
- end
- coloredName = '|c'..RAID_CLASS_COLORS[class].colorStr..letterTable[1]..'|c'..modChatColor --color the name
- word = word:gsub(letterTable[1], coloredName) --replace the name with the colored name
- end
- if (letterTable[1] and (letterTable[1]:lower() == 'you' or letterTable[1]:lower() == 'your')) then --color this
- coloredName = '|c'..playerClassColorTable.colorStr..letterTable[1]..'|c'..modChatColor --this is an addon-wide static formed at the beginning of the addon
- word = word:gsub(letterTable[1], coloredName)
- end
- table.insert(coloredMessage, word)
- end
- return(table.concat(coloredMessage, ' '))
- end
- local function formatChatMessage(chatMessage, modChatColor)
- chatMessage = chatMessage:gsub('^%s*(.-)%s*$', '%1') --remove trailing and leading spaces
- chatMessage = chatMessage:gsub(' +', ' ') --condense down excessive spacing (3 or more) to 2 spaces
- chatMessage = chatMessage:gsub('\n', '') --remove those pesky people typing \n into chat
- chatMessage = chatMessage:gsub('([wWhH][wWtT][wWtT][%.pP]%S+[^%p%s])', '|cffffffff|Hurl:%1|h[%1]|h|r') --find any URLs and make them white hyperlinks
- chatMessage = chatMessage:gsub('%|h%|r', '|h|r|c'..modChatColor) --this is a shitty hack so if someone puts a hyperlink in chat, the text afterwards will go back to the default chat color
- return chatMessage
- end
- local function createPlayerLinks(event, chatType, ...) --this creates the clickable hyperlink found for the names of players in chat
- local senderLinkDisplay = GetColoredName(event, ...) --blizzard function
- local _, playerName, _, _, _, _, _, channelNumber, _, _, chatLineID = ...
- if strfind(senderLinkDisplay, '-') then
- senderLinkDisplay = strsub(senderLinkDisplay, 1, strfind(senderLinkDisplay, '-') - 1) --removes realms from players on different realms
- end
- if chatType == 'WHISPER' then --makes both the [F] and [T] in whispers part of the hyperlinks for whispers
- senderLinkDisplay = '|c00FF80FF [F] '..senderLinkDisplay --the hex color in front of F is the default whisper color
- elseif chatType == 'WHISPER_INFORM' then
- senderLinkDisplay = '|c00FF80FF [T] '..senderLinkDisplay --the hex color in front of T is the default whisper color
- end
- local playerLink = GetPlayerLink(playerName, senderLinkDisplay, chatLineID, Chat_GetChatCategory(chatType), tostring(channelNumber) or nil) --blizzard function, have to pass the channel number as a string, some events won't have a channel number (says, whispers, yells etc) so blizzard code doesn't need this argument and accepts nil, too
- return playerLink
- end
- local function createChannelLinks(chatType, modChatColor)
- if (chatType == 'WHISPER' or chatType == 'WHISPER_INFORM') then return '' end --these don't have hyperlinkable channels, so we specially handle them in the "createPlayerLinks" function
- local channel
- if chatType == 'PARTY_LEADER' then --this makes it so when you click on the PL chat it doesn't try to send you to a non-existent chat type
- chatType = 'PARTY'
- channel = '|Hchannel:'..chatType..'|h'..channelAbbreviationsTable['PARTY_LEADER']..'|h' --this makes it so when you click on the IL chat it doesn't try to send you to a non-existent chat type
- elseif chatType == 'INSTANCE_CHAT_LEADER' then
- chatType = 'INSTANCE_CHAT'
- channel = '|Hchannel:'..chatType..'|h'..channelAbbreviationsTable['INSTANCE_CHAT_LEADER']..'|h'
- elseif chatType == 'RAID_LEADER' then --this makes it so when you click on the RL chat it doesn't try to send you to a non-existent chat type
- chatType = 'RAID'
- channel = '|Hchannel:'..chatType..'|h'..channelAbbreviationsTable['RAID_LEADER']..'|h'
- elseif chatType == 'RAID_WARNING' then --this makes it so when you click on the RW chat it doesn't try to send you to a non-existent chat type
- chatType = 'RAID'
- channel = '|Hchannel:'..chatType..'|h'..channelAbbreviationsTable['RAID_WARNING']..'|h'
- elseif chatType == 'TEXT_EMOTE' then
- chatType = 'EMOTE'
- channel = '|Hchannel:'..chatType..'|h'..channelAbbreviationsTable['EMOTE']..'|h'
- elseif channelAbbreviationsTable[chatType] then --if we set up an abbreviation, use it
- channel = '|Hchannel:'..chatType..'|h'..channelAbbreviationsTable[chatType]..'|h'
- else --if not, it is likely a number like our general, trade, local defence, etc channels
- channel = '|Hchannel:'..chatType..'|h'..' ['..chatType..'] '..'|h'
- end
- channel = WrapTextInColorCode(channel, modChatColor)
- return channel
- end
- local function commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...)
- local chatMessage = ...
- chatMessage = hexColorNames(chatMessage, modChatColor)
- chatMessage = formatChatMessage(chatMessage, modChatColor)
- chatMessage = C_ChatInfo.ReplaceIconAndGroupExpressions(chatMessage) --blizzard function that puts the target markers in chat
- local playerLink = createPlayerLinks(event, chatType, ...)
- local channelLink = createChannelLinks(chatType, modChatColor)
- return timeStamp..channelLink..playerLink..' '..WrapTextInColorCode(chatMessage, modChatColor)
- end
- local function handleBNWhispers(event, chatType, modChatColor, ...)
- local chatMessage, bTag, _, _, _, flags, _, _, _, _, lineID, _, bNetPresenceID = ...
- chatMessage = hexColorNames(chatMessage, modChatColor)
- chatMessage = formatChatMessage(chatMessage, modChatColor)
- chatMessage = C_ChatInfo.ReplaceIconAndGroupExpressions(chatMessage)
- local _, _, bTagName = BNGetFriendInfoByID(bNetPresenceID)
- bTagName = strsub(bTagName, 1, strfind(bTagName, '#') - 1) --removes the # and numbers after a btag name so that's all that is left is the btag handle
- local friendIndex = BNGetFriendIndex(bNetPresenceID)
- local accountIndex = BNGetNumFriendGameAccounts(friendIndex)
- local linkDisplayText, playerLink
- local wowCharacter = false
- --there's actually something not completely right with this strategy, and that's if you're whispering someone who has
- --multiple bnet accounts simultaneously logged in, you'll always get the first account's characterName the for loop encounters
- local _, characterName, class
- for i = 1, accountIndex do
- _, characterName, _, _, _, _, _, class = BNGetFriendGameAccountInfo(friendIndex, i)
- if (characterName and characterName ~= '') then
- wowCharacter = true
- break
- end
- end
- if event == 'CHAT_MSG_BN_WHISPER' then
- linkDisplayText = '|c'..modChatColor..' [F] '
- elseif event == 'CHAT_MSG_BN_WHISPER_INFORM' then
- linkDisplayText = '|c'..modChatColor..' [T] '
- end
- if wowCharacter then
- class = class:upper()
- local bNetClassColors = RAID_CLASS_COLORS[class] or RAID_CLASS_COLORS[class:gsub(' ', '')] --death knights and demon hunters return with spaces but the table key doesn't have spaces
- linkDisplayText = linkDisplayText..'['..bTagName..' ('..'|c'..bNetClassColors.colorStr..characterName..'|c'..modChatColor..')]'
- playerLink = GetBNPlayerLink(bTag, linkDisplayText, bNetPresenceID, lineID, Chat_GetChatCategory(chatType), 0)
- else
- linkDisplayText = linkDisplayText..'['..bTagName..']'
- playerLink = GetBNPlayerLink(bTag, linkDisplayText, bNetPresenceID, lineID, Chat_GetChatCategory(chatType), 0)
- end
- return playerLink, chatMessage
- end
- local function commonMonsterChatEventHandler(event, chatType, modChatColor, timeStamp, ...)
- local chatMessage, npcName = ...
- chatMessage = hexColorNames(chatMessage, modChatColor)
- return timeStamp..WrapTextInColorCode(channelAbbreviationsTable[chatType]..npcName..' '..chatMessage, modChatColor)
- end
- local function commonRaidBossEventHandler(event, chatType, modChatColor, timeStamp, ...)
- local chatMessage, monsterName = ...
- chatMessage = chatMessage:gsub('%%s', monsterName)
- chatMessage = chatMessage:gsub('%:%d+%:%d+%:%d+%:%d+', ':14:16:0:0') --these are for the various ability icons that get sent in the chat; they are way too big and make the chat wonky looking
- chatMessage = chatMessage:gsub('%:20|t', ':14|t') --this is an alternate way sometimes blizzard puts icons into chat
- chatMessage = chatMessage:gsub('%|r', '|r|c'..modChatColor) --make sure hyperlinks don't cause the rest of our chat to turn white afterwards
- chatMessage = modHexColorNames(chatMessage, modChatColor)
- return timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor)
- end
- local function commonAchievementEventHandler(event, chatType, modChatColor, timeStamp, ...)
- local achievementString, achieverName = ...
- if (event == 'CHAT_MSG_GUILD_ACHIEVEMENT' and achieverName == playerCharacterName) then --we don't want our achievemnt to double fire, so it just hides it from our chat
- return
- end
- achievementString = achievementString:gsub('%%s has earned the achievement', '+ achievement:') --for some reason, changing the global string doesn't work, so this is our way to make it look how we want
- achievementString = achievementString:gsub('%!', '')
- local playerLink = createPlayerLinks(event, chatType, ...)
- return timeStamp..' '..playerLink..' '..WrapTextInColorCode(achievementString, modChatColor)
- end
- local function commonBattlegroundEventHandler(event, chatType, modChatColor, timeStamp, ...)
- local chatMessage = ...
- chatMessage = modHexColorNames(chatMessage, modChatColor)
- chatMessage = chatMessage:gsub('%|r', '|r|c'..modChatColor)
- return timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor)
- end
- local chatColor = {} --this will hold the color for our channel to be accesssed
- f:SetScript('OnEvent', function(self, event, ...) --this is the main handler that creates timeStamp, gets the chat color and passes it along as a hexcode
- local message, _, _, _, _, _, _, channelNumber = ...
- if strfind(message, "[\227-\237]") then --blocks random asian shit
- return true
- end
- local chatType = strsub(event, 10) --chop off first 'CHAT_MSG_' to get the event
- if strsub(event, 10, 16) == 'CHANNEL' then --this will color chats by their proper color since they're user editable
- chatColor = channelColorHolderTable[channelNumber]
- else
- chatColor = ChatTypeInfo[chatType] or channelColorHolderTable[1] --or just makes the color the generic general chat color
- end
- local timeStamp --this will be used to make our own time stamp for each line
- timeStamp = BetterDate(CHAT_TIMESTAMP_FORMAT, time())
- timeStamp = rgbPercToHex(0.5, 0.5, 0.5)..'['..timeStamp..']|r' --this colors the brackets and text grey and adds them around the text
- timeStamp = gsub(timeStamp, ' ', '') --this removes the random space that gets added between the end of the time string and the ]
- timeStamp = '|c'..timeStamp
- local modChatColor = rgbPercToHex(chatColor.r, chatColor.g, chatColor.b)
- if self[event] then --handle our event
- self[event](self, event, chatType, modChatColor, timeStamp, ...)
- end
- end)
- function f:CHAT_MSG_SAY(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player says something
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_YELL(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player yells something
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_EMOTE(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player performs a custom emote using /e
- local chatMessage = ...
- local channelLink = createChannelLinks(chatType, modChatColor)
- local playerLink = createPlayerLinks(event, chatType, ...)
- chatMessage = modHexColorNames(chatMessage, modChatColor)
- chatMessage = C_ChatInfo.ReplaceIconAndGroupExpressions(chatMessage)
- chatMessage = formatChatMessage(chatMessage, modChatColor)
- ChatFrame1:AddMessage(timeStamp..channelLink..playerLink..' '..WrapTextInColorCode(chatMessage, modChatColor))
- end
- function f:CHAT_MSG_TEXT_EMOTE(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player types in a 'preset' emote
- --so blizzard in their infinite wisdom uses a short name for argument 2 of TEXT_EMOTE
- --this means that if you try and make a hyperlink from the 2nd argument, like we do with literally every other CHAT_MSG_* event, it doesn't work properly
- --we have to instead get the emoteGUID and from that get the name and realm
- local chatMessage, playerName, _, _, _, _, _, _, _, _, chatLineID, emoteGUID = ...
- local _, _, _, _, _, nameFromGUID, realm = GetPlayerInfoByGUID(emoteGUID)
- if realm then --the player is off realm and has a hyphenated name
- playerName = nameFromGUID..'%-'..realm --rejoin the strings with a % before the - so our gsub can actually look for it
- end
- local channelLink = createChannelLinks(chatType, modChatColor)
- local playerLink = nil --if the player performs the emote, it'll leave it as '', but if another player does it, it'll change to an actual hyperlink
- if playerName ~= UnitName('player') then --if we emote, we don't want to create a hyper link to ourselves since the game changes these messages to "You" perform xyz.
- playerLink = createPlayerLinks(event, chatType, _, nameFromGUID..'-'..realm, _, _, _, _, _, 0, _, _, chatLineID, emoteGUID)
- chatMessage = chatMessage:gsub(playerName, playerLink..'|c'..modChatColor)
- end
- chatMessage = modHexColorNames(chatMessage, modChatColor)
- chatMessage = chatMessage:gsub('%|r', '|r|c'..modChatColor) --this is a way to make sure things that get hyperlinked in chat don't cause the rest of our chat to be a certain color; we want it to return to normal
- ChatFrame1:AddMessage(timeStamp..channelLink..WrapTextInColorCode(chatMessage, modChatColor))
- end
- function f:CHAT_MSG_PARTY(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player in your party says something
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_PARTY_LEADER(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player in your party who is leader says something
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_INSTANCE_CHAT(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player says something in instance chat
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_INSTANCE_CHAT_LEADER(event, chatType, modChatColor, timeStamp, ...) --fires when the party leader says something in instance chat
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_RAID(event, chatType, modChatColor, timeStamp, ...) --fires when the you or another player says something in raid chat
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_RAID_LEADER(event, chatType, modChatColor, timeStamp, ...) --fires when the raid leader says something in raid chat
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_RAID_WARNING(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player issues a raid warning
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_WHISPER(event, chatType, modChatColor, timeStamp, ...) --fires when you receive a whisper from another player
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_WHISPER_INFORM(event, chatType, modChatColor, timeStamp, ...) --fires when you send a whisper to another player
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_BN_WHISPER(event, chatType, modChatColor, timeStamp, ...)
- local playerLink, chatMessage = handleBNWhispers(event, chatType, modChatColor, ...)
- ChatFrame1:AddMessage(timeStamp..playerLink..' '..WrapTextInColorCode(chatMessage, modChatColor))
- end
- function f:CHAT_MSG_BN_WHISPER_INFORM(event, chatType, modChatColor, timeStamp, ...)
- local playerLink, chatMessage = handleBNWhispers(event, chatType, modChatColor, ...)
- ChatFrame1:AddMessage(timeStamp..playerLink..' '..WrapTextInColorCode(chatMessage, modChatColor))
- end
- function f:CHAT_MSG_GUILD(event, chatType, modChatColor, timeStamp, ...) --fires when you or a guildmate says something in guild chat
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...)) --due to changes in patch 8.1, we can no longer modify guild chat, as such, sometimes weird stuff occurs with hyperlinks
- end
- function f:CHAT_MSG_OFFICER(event, chatType, modChatColor, timeStamp, ...) --fires when you or a guildmate says something in officer chat
- ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_MONSTER_SAY(event, chatType, modChatColor, timeStamp, ...) --fires when an NPC says something
- ChatFrame1:AddMessage(commonMonsterChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_MONSTER_YELL(event, chatType, modChatColor, timeStamp, ...) --fires when an NPC yells something
- ChatFrame1:AddMessage(commonMonsterChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_MONSTER_EMOTE(event, chatType, modChatColor, timeStamp, ...) --fires when an NPC performs an emote
- ChatFrame1:AddMessage(commonRaidBossEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_MONSTER_WHISPER(event, chatType, modChatColor, timeStamp, ...) --fires when an NPC whispers something to you
- ChatFrame1:AddMessage(commonMonsterChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_RAID_BOSS_WHISPER(event, chatType, modChatColor, timeStamp, ...) --fires with various events in game, sometimes even in BGs
- ChatFrame1:AddMessage(commonRaidBossEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_RAID_BOSS_EMOTE(event, chatType, modChatColor, timeStamp, ...) --fires when a raid boss performs an emote
- ChatFrame1:AddMessage(commonRaidBossEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_ACHIEVEMENT(event, chatType, modChatColor, timeStamp, ...) --fires when you earn an achievement
- ChatFrame1:AddMessage(commonAchievementEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_GUILD_ACHIEVEMENT(event, chatType, modChatColor, timeStamp, ...) --fires when you (when in a guild) or a guild mate earns an achievement
- ChatFrame1:AddMessage(commonAchievementEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_SYSTEM(event, chatType, modChatColor, timeStamp, ...) --fires during a multitude of system events
- local chatMessage = ...
- chatMessage = modHexColorNames(chatMessage, modChatColor)
- chatMessage = chatMessage:gsub('|h|r', '|h|r|c'..modChatColor) --this is a way to make sure things that get hyperlinked in chat don't cause the rest of our chat to be a certain color; we want it to return to normal
- ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
- end
- function f:CHAT_MSG_SKILL(event, chatType, modChatColor, timeStamp, ...)
- local chatMessage = ...
- ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
- end
- function f:CHAT_MSG_MONEY(event, chatType, modChatColor, timeStamp, ...) --fires when you gain money
- local chatMessage = ...
- ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
- end
- function f:CHAT_MSG_CURRENCY(event, chatType, modChatColor, timeStamp, ...) --fires when you gain currency
- local chatMessage = ...
- chatMessage = chatMessage:gsub('You ', '|c'..playerClassColorTable.colorStr..'You |c'..modChatColor):gsub('Your', '|c'..playerClassColorTable.colorStr..'Your'..'|c'..modChatColor) --this will color the 'You' that appears before looting to our class color
- chatMessage = chatMessage:gsub('|h|r', '|h|r|c'..modChatColor) --this is a way to make sure things that get hyperlinked in chat don't cause the rest of our chat to be a certain color; we want it to return to normal
- ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
- end
- function f:CHAT_MSG_COMBAT_HONOR_GAIN(event, chatType, modChatColor, timeStamp, ...) --fires when you gain honor
- local chatMessage = ...
- ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
- end
- function f:CHAT_MSG_BG_SYSTEM_NEUTRAL(event, chatType, modChatColor, timeStamp, ...) --fires in a BG when neutral events happen like the match starting
- ChatFrame1:AddMessage(commonBattlegroundEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_BG_SYSTEM_ALLIANCE(event, chatType, modChatColor, timeStamp, ...) --fires in a BG when the allianace do stuff
- ChatFrame1:AddMessage(commonBattlegroundEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- function f:CHAT_MSG_BG_SYSTEM_HORDE(event, chatType, modChatColor, timeStamp, ...) --fires in a BG when the horde do stuff
- ChatFrame1:AddMessage(commonBattlegroundEventHandler(event, chatType, modChatColor, timeStamp, ...))
- end
- local chatLootMessage = {}
- function f:CHAT_MSG_LOOT(event, chatType, modChatColor, timeStamp, ...) --fires when you or a group member loot an item/creates an item
- local chatMessage, playerName, _, _, _, _, _, channelNumber, _, _, chatLineID = ...
- if playerName ~= playerCharacterName then --we don't do this for the player, we don't want to make a hyperlink for ourselves
- local playerLink = createPlayerLinks(event, chatType, ...)
- local playerNameNoRealm = strsub(playerName, 1, strfind(playerName, '-') - 1) --removes realms from players on different realms
- chatLootMessage = {strsplit(' ', chatMessage)} --split the message into individual words by spaces, all we care about is the first word (the player's name)
- local w = chatLootMessage[1]
- if (w and strfind(w, '-')) then --the player is off realm and has a hyphenated name
- local a, b = strsplit('-', w) --split the hyphenated name into two strings
- playerName = a..'%-'..b --rejoin the strings with a % before the - so our gsub can actually look for it
- end
- if strfind(chatMessage, playerName) then --the person is off realm, we need to look for the full name to gsub
- chatMessage = chatMessage:gsub(playerName, playerLink..'|c'..modChatColor)
- else --the player is on realm, we need to look for the player name without realm to properly replace it
- chatMessage = chatMessage:gsub(playerNameNoRealm, playerLink..'|c'..modChatColor)
- end
- else --playerName == playerCharacterName, so this is the player "You" looting
- chatMessage = chatMessage:gsub('You ', '|c'..playerClassColorTable.colorStr..'You '..'|c'..modChatColor):gsub('Your', '|c'..playerClassColorTable.colorStr..'Your'..'|c'..modChatColor)
- end
- chatMessage = chatMessage:gsub('|h|r', '|h|r|c'..modChatColor) --this is a way to make sure things that get hyperlinked in chat don't cause the rest of our chat to be a certain color; we want it to return to normal
- ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
- end
- function f:CHAT_MSG_COMBAT_FACTION_CHANGE(event, chatType, modChatColor, timeStamp, ...) --fires when you gain/lose reputation
- local chatMessage = ...
- ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
- end
- function f:CHAT_MSG_CHANNEL(event, chatType, modChatColor, timeStamp, ...) --fires anytime a message is added by you or another player or a local defense message is sent out
- local chatMessage, _, _, _, _, _, _, channelNumber, _, _, _, senderGUID = ...
- chatMessage = hexColorNames(chatMessage, modChatColor)
- chatMessage = formatChatMessage(chatMessage, modChatColor)
- channelNumber = createChannelLinks(channelNumber, modChatColor)
- if senderGUID then --hack for local defense 'x zone is under attack' messages trying to make player links when no one was making the phrase
- local playerLink = createPlayerLinks(event, chatType, ...)
- chatMessage = timeStamp..channelNumber..playerLink..' |c'..modChatColor..chatMessage
- else
- chatMessage = timeStamp..channelNumber..' '..chatMessage
- end
- ChatFrame1:AddMessage(chatMessage)
- end
- function f:CHAT_MSG_CHANNEL_NOTICE(event, chatType, modChatColor, timeStamp, ...) --fires when you change channels
- local notice, _, _, _, _, _, _, _, channelName = ...
- if notice then
- local You = '|c'..playerClassColorTable.colorStr..'You|c' --color the word 'You' by your class color
- if notice == 'YOU_CHANGED' then
- ChatFrame1:AddMessage(timeStamp..' '..You..modChatColor..' + '..channelName..'.')
- elseif (notice == 'YOU_LEFT' or notice == 'SUSPENDED') then
- ChatFrame1:AddMessage(timeStamp..' '..You..modChatColor..' - '..channelName..'.')
- elseif notice == 'THROTTLED' then
- ChatFrame1:AddMessage(timeStamp..' '..You..modChatColor..' were throttled in '..channelName..'.')
- elseif notice == 'TRIAL_RESTRICTED' then
- ChatFrame1:AddMessage(timeStamp..' '..modChatColor..CHAT_TRIAL_RESTRICTED_NOTICE)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement