SHARE
TWEET

Untitled

a guest Jul 7th, 2019 36 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local unusedVariable, playerClass = UnitClass('player')
  2. local playerClassColorTable = RAID_CLASS_COLORS[playerClass]
  3. local playerCharacterName = UnitName('player')..'-'..GetRealmName()
  4.  
  5. local eventTable = {}
  6. table.insert(eventTable, 'CHAT_MSG_SAY')
  7. table.insert(eventTable, 'CHAT_MSG_YELL')
  8. table.insert(eventTable, 'CHAT_MSG_EMOTE')
  9. table.insert(eventTable, 'CHAT_MSG_TEXT_EMOTE')
  10. table.insert(eventTable, 'CHAT_MSG_CHANNEL')
  11. table.insert(eventTable, 'CHAT_MSG_CHANNEL_NOTICE')
  12. table.insert(eventTable, 'CHAT_MSG_WHISPER')
  13. table.insert(eventTable, 'CHAT_MSG_WHISPER_INFORM')
  14. table.insert(eventTable, 'CHAT_MSG_BN_WHISPER')
  15. table.insert(eventTable, 'CHAT_MSG_BN_WHISPER_INFORM')
  16.  
  17.  
  18. table.insert(eventTable, 'CHAT_MSG_GUILD')
  19. table.insert(eventTable, 'CHAT_MSG_OFFICER')
  20. table.insert(eventTable, 'CHAT_MSG_PARTY')
  21. table.insert(eventTable, 'CHAT_MSG_PARTY_LEADER')
  22. table.insert(eventTable, 'CHAT_MSG_INSTANCE_CHAT')
  23. table.insert(eventTable, 'CHAT_MSG_INSTANCE_CHAT_LEADER')
  24. table.insert(eventTable, 'CHAT_MSG_RAID')
  25. table.insert(eventTable, 'CHAT_MSG_RAID_LEADER')
  26. table.insert(eventTable, 'CHAT_MSG_RAID_WARNING')
  27. table.insert(eventTable, 'CHAT_MSG_RAID_BOSS_WHISPER')
  28. table.insert(eventTable, 'CHAT_MSG_RAID_BOSS_EMOTE')
  29. table.insert(eventTable, 'CHAT_MSG_MONSTER_SAY')
  30. table.insert(eventTable, 'CHAT_MSG_MONSTER_YELL')
  31. table.insert(eventTable, 'CHAT_MSG_MONSTER_EMOTE')
  32. table.insert(eventTable, 'CHAT_MSG_MONSTER_WHISPER')
  33. table.insert(eventTable, 'CHAT_MSG_SYSTEM')
  34. table.insert(eventTable, 'CHAT_MSG_SKILL')
  35. table.insert(eventTable, 'CHAT_MSG_ACHIEVEMENT')
  36. table.insert(eventTable, 'CHAT_MSG_GUILD_ACHIEVEMENT')
  37. table.insert(eventTable, 'CHAT_MSG_LOOT')
  38. table.insert(eventTable, 'CHAT_MSG_CURRENCY')
  39. table.insert(eventTable, 'CHAT_MSG_MONEY')
  40. table.insert(eventTable, 'CHAT_MSG_COMBAT_FACTION_CHANGE')
  41. table.insert(eventTable, 'CHAT_MSG_COMBAT_HONOR_GAIN')
  42. table.insert(eventTable, 'CHAT_MSG_BG_SYSTEM_NEUTRAL')
  43. table.insert(eventTable, 'CHAT_MSG_BG_SYSTEM_ALLIANCE')
  44. table.insert(eventTable, 'CHAT_MSG_BG_SYSTEM_HORDE')
  45.  
  46. local f = CreateFrame('frame')
  47. for i = 1, #eventTable do
  48.     f:RegisterEvent(eventTable[i])
  49.     ChatFrame_AddMessageEventFilter(eventTable[i], function() return true end)
  50. end
  51.  
  52. local g = CreateFrame('frame')
  53. g:RegisterEvent('UPDATE_CHAT_COLOR')
  54. --this will find any channels that are associated with numbers, that is custom channels
  55. --it does this by first removing the 'CHANNEL' before the number, and converting the string to a number
  56. --since there are many strings that don't get converted, we find only the ones that are numbers by our if check
  57. --we then make a table entry for the color rgb so when a player leaves that channel, and no color is associated anymore,
  58. --the leaving text still matches the color they left
  59. local channelColorHolderTable = {}
  60. g:SetScript('OnEvent', function(self, event, ...)
  61.     local channelNumber, r, g, b = ...
  62.     channelNumber = channelNumber:gsub('CHANNEL', '')
  63.     channelNumber = tonumber(channelNumber)
  64.     if channelNumber then
  65.         channelColorHolderTable[channelNumber] = {}
  66.         channelColorHolderTable[channelNumber].r, channelColorHolderTable[channelNumber].g, channelColorHolderTable[channelNumber].b = r, g, b
  67.     end
  68. end)
  69.  
  70. local function rgbPercToHex(r, g, b) --converts decimal rgb to a hexcode
  71.     r = r <= 1 and r >= 0 and r or 0
  72.     g = g <= 1 and g >= 0 and g or 0
  73.     b = b <= 1 and b >= 0 and b or 0
  74.     return string.format('ff%02x%02x%02x', r*255, g*255, b*255)
  75. end
  76.  
  77. --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
  78. local channelAbbreviationsTable = {
  79.     ['SAY']                 = ' [S] ',
  80.     ['YELL']                = ' [Y] ',
  81.     ['EMOTE']               = ' [E] ',
  82.     ['TEXT_EMOTE']          = ' [E] ',
  83.     ['PARTY']               = ' [P] ',
  84.     ['PARTY_LEADER']        = ' [L] ',
  85.     ['INSTANCE_CHAT']       = ' [I] ',
  86.     ['INSTANCE_CHAT_LEADER']= ' [L] ',
  87.     ['RAID']                = ' [R] ',
  88.     ['RAID_LEADER']         = ' [L] ',
  89.     ['RAID_WARNING']        = ' [W] ',
  90.     ['OFFICER']             = ' [O] ',
  91.     ['GUILD']               = ' [G] ',
  92.     ['MONSTER_SAY']         = ' [S] ',
  93.     ['MONSTER_YELL']        = ' [Y] ',
  94.     ['MONSTER_WHISPER']     = ' [F] ',
  95. }
  96.  
  97. 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
  98. local function hexColorNames(chatMessage, modChatColor)
  99.     wipe(coloredMessage) --blizzard function that will clear our table
  100.     for word in gmatch(chatMessage, '%S+') do --look at each word individually, separating them by spaces (we look for non-whitespace)
  101.         placeHolderWord = word
  102.         placeHolderWord = placeHolderWord:gsub('%b{}', '') --we immediately remove all instances of {skull} etc for addons that glue it to people's names
  103.         local _
  104.         local class, name, coloredName = nil, nil, nil
  105.         wipe(letterTable) --wipe our letterTable from any previous entries
  106.         while strfind(placeHolderWord, '%a') do --we're going to be removing all blocks of letters from our word
  107.             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
  108.             if holder then --safety so we don't throw an error inserting nil into a table
  109.                 table.insert(letterTable, holder) --put our letter block into our letterTable holder
  110.                 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
  111.             end
  112.         end
  113.        
  114.         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
  115.             name = letterTable[1]
  116.             _, class = UnitClass(letterTable[1])
  117.         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
  118.             if strfind(word, 'Area52') then
  119.                 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
  120.                 _, class = UnitClass(letterTable[1]..'-'..letterTable[2]..'52')
  121.             else
  122.                 name = letterTable[1]..'%-'..letterTable[2] --we use the % so we can gsub
  123.                 _, class = UnitClass(letterTable[1]..'-'..letterTable[2])
  124.             end
  125.         elseif #letterTable >= 3 then --we use >= rather than == incase someone adds letters afterwards to try and catch more names this way
  126.             name = letterTable[1]..'%-'..letterTable[2].."%'"..letterTable[3] --we use the % in front of the magic characters so we can gsub
  127.             _, class = UnitClass(letterTable[1]..'-'..letterTable[2].."'"..letterTable[3])
  128.         end
  129.        
  130.         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
  131.             coloredName = '|c'..RAID_CLASS_COLORS[class].colorStr..name..'|c'..modChatColor
  132.             word = word:gsub(name, coloredName)
  133.         end
  134.        
  135.         table.insert(coloredMessage, word)
  136.     end
  137.  
  138.     return(table.concat(coloredMessage, ' '))
  139. end
  140.  
  141. local function modHexColorNames(chatMessage, modChatColor) --differs from hexColorNames because it class colors 'You' and 'you' and 'Your' and 'your' and removes realmNames from players
  142.     wipe(coloredMessage) --blizzard function that will clear our table
  143.     local class, name, coloredName
  144.     for word in gmatch(chatMessage, '%S+') do --look at each word individually, separating them by spaces (we look for non-whitespace)
  145.         placeHolderWord = word
  146.         placeHolderWord = placeHolderWord:gsub('%b{}', '') --we immediately remove all instances of '{skull}' etc for addons that glue it to people's names
  147.         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
  148.         local _
  149.         class, name, coloredName = nil, nil, nil
  150.         wipe(letterTable) --wipe our letterTable from any previous entries
  151.         while strfind(placeHolderWord, '%a') do --we're going to be removing all blocks of letters from our word
  152.             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
  153.             if holder then --safety so we don't throw an error inserting nil into a table
  154.                 table.insert(letterTable, holder) --put our letter block into our letterTable holder
  155.                 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
  156.             end
  157.         end
  158.  
  159.         for i = 1, 3 do
  160.             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
  161.  
  162.             if (i == 1 and letterTable[i]) then --the potential name doesn't have a realm
  163.                 _, class = UnitClass(letterTable[1])
  164.                 if (class and class ~= '') then break end
  165.             elseif (i == 2 and letterTable[i]) then --the potential name has at least a realm name
  166.                 if strfind(word, 'Area52') then --hack because our match specifically avoids numbers, Area 52 is the only realm with numbers
  167.                     _, class = UnitClass(letterTable[1]..'-'..letterTable[2]..'52')
  168.                     if (class and class ~= '') then break end
  169.                 else
  170.                     _, class = UnitClass(letterTable[1]..'-'..letterTable[2])
  171.                     if (class and class ~= '') then break end
  172.                 end
  173.             elseif (i == 3 and letterTable[i]) then --the potential name might have a realm and an ' in the realmName
  174.                 _, class = UnitClass(letterTable[1]..'-'..letterTable[2].."'"..letterTable[3])
  175.             end
  176.         end
  177.  
  178.         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
  179.             if #letterTable == 2 then
  180.                 word = word:gsub('%-%P+', '') --remove the realm name but preserve any punctuation attached at the end
  181.             elseif #letterTable == 3 then
  182.                 word = word:gsub('%-%P+', '') --remove the realm name, but we're going to get stuck on the '
  183.                 word = word:gsub("%'%P+", '') --remove the rest of the realm name
  184.             end
  185.             coloredName = '|c'..RAID_CLASS_COLORS[class].colorStr..letterTable[1]..'|c'..modChatColor --color the name
  186.             word = word:gsub(letterTable[1], coloredName) --replace the name with the colored name
  187.         end
  188.  
  189.         if (letterTable[1] and (letterTable[1]:lower() == 'you' or letterTable[1]:lower() == 'your')) then --color this
  190.             coloredName = '|c'..playerClassColorTable.colorStr..letterTable[1]..'|c'..modChatColor --this is an addon-wide static formed at the beginning of the addon
  191.             word = word:gsub(letterTable[1], coloredName)
  192.         end
  193.        
  194.         table.insert(coloredMessage, word)
  195.     end
  196.  
  197.     return(table.concat(coloredMessage, ' '))
  198. end
  199.  
  200. local function formatChatMessage(chatMessage, modChatColor)
  201.     chatMessage = chatMessage:gsub('^%s*(.-)%s*$', '%1') --remove trailing and leading spaces
  202.     chatMessage = chatMessage:gsub('   +', '  ') --condense down excessive spacing (3 or more) to 2 spaces
  203.     chatMessage = chatMessage:gsub('\n', '') --remove those pesky people typing \n into chat
  204.     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
  205.     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
  206.     return chatMessage
  207. end
  208.  
  209. local function createPlayerLinks(event, chatType, ...) --this creates the clickable hyperlink found for the names of players in chat
  210.     local senderLinkDisplay = GetColoredName(event, ...) --blizzard function
  211.     local _, playerName, _, _, _, _, _, channelNumber, _, _, chatLineID = ...
  212.     if strfind(senderLinkDisplay, '-') then
  213.         senderLinkDisplay = strsub(senderLinkDisplay, 1, strfind(senderLinkDisplay, '-') - 1) --removes realms from players on different realms
  214.     end
  215.    
  216.     if chatType == 'WHISPER' then --makes both the [F] and [T] in whispers part of the hyperlinks for whispers
  217.         senderLinkDisplay = '|c00FF80FF [F] '..senderLinkDisplay --the hex color in front of F is the default whisper color
  218.     elseif chatType == 'WHISPER_INFORM' then
  219.         senderLinkDisplay = '|c00FF80FF [T] '..senderLinkDisplay --the hex color in front of T is the default whisper color
  220.     end
  221.    
  222.     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
  223.     return playerLink
  224. end
  225.  
  226. local function createChannelLinks(chatType, modChatColor)
  227.     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
  228.     local channel
  229.     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
  230.         chatType = 'PARTY'
  231.         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
  232.     elseif chatType == 'INSTANCE_CHAT_LEADER' then
  233.         chatType = 'INSTANCE_CHAT'
  234.         channel = '|Hchannel:'..chatType..'|h'..channelAbbreviationsTable['INSTANCE_CHAT_LEADER']..'|h'
  235.     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
  236.         chatType = 'RAID'
  237.         channel = '|Hchannel:'..chatType..'|h'..channelAbbreviationsTable['RAID_LEADER']..'|h'
  238.     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
  239.         chatType = 'RAID'
  240.         channel = '|Hchannel:'..chatType..'|h'..channelAbbreviationsTable['RAID_WARNING']..'|h'
  241.     elseif chatType == 'TEXT_EMOTE' then
  242.         chatType = 'EMOTE'
  243.         channel = '|Hchannel:'..chatType..'|h'..channelAbbreviationsTable['EMOTE']..'|h'
  244.     elseif channelAbbreviationsTable[chatType] then --if we set up an abbreviation, use it
  245.         channel = '|Hchannel:'..chatType..'|h'..channelAbbreviationsTable[chatType]..'|h'
  246.     else --if not, it is likely a number like our general, trade, local defence, etc channels
  247.         channel = '|Hchannel:'..chatType..'|h'..' ['..chatType..'] '..'|h'
  248.     end
  249.  
  250.     channel = WrapTextInColorCode(channel, modChatColor)
  251.     return channel
  252. end
  253.  
  254. local function commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...)
  255.     local chatMessage = ...
  256.     chatMessage = hexColorNames(chatMessage, modChatColor)
  257.     chatMessage = formatChatMessage(chatMessage, modChatColor)
  258.     chatMessage = C_ChatInfo.ReplaceIconAndGroupExpressions(chatMessage) --blizzard function that puts the target markers in chat
  259.     local playerLink = createPlayerLinks(event, chatType, ...)
  260.     local channelLink = createChannelLinks(chatType, modChatColor)
  261.     return timeStamp..channelLink..playerLink..' '..WrapTextInColorCode(chatMessage, modChatColor)
  262. end
  263.  
  264. local function handleBNWhispers(event, chatType, modChatColor, ...)
  265.     local chatMessage, bTag, _, _, _, flags, _, _, _, _, lineID, _, bNetPresenceID = ...
  266.     chatMessage = hexColorNames(chatMessage, modChatColor)
  267.     chatMessage = formatChatMessage(chatMessage, modChatColor)
  268.     chatMessage = C_ChatInfo.ReplaceIconAndGroupExpressions(chatMessage)
  269.  
  270.     local _, _, bTagName = BNGetFriendInfoByID(bNetPresenceID)
  271.     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
  272.  
  273.     local friendIndex = BNGetFriendIndex(bNetPresenceID)
  274.     local accountIndex = BNGetNumFriendGameAccounts(friendIndex)
  275.     local linkDisplayText, playerLink
  276.     local wowCharacter = false
  277.     --there's actually something not completely right with this strategy, and that's if you're whispering someone who has
  278.     --multiple bnet accounts simultaneously logged in, you'll always get the first account's characterName the for loop encounters
  279.     local _, characterName, class
  280.     for i = 1, accountIndex do
  281.         _, characterName, _, _, _, _, _, class = BNGetFriendGameAccountInfo(friendIndex, i)
  282.         if (characterName and characterName ~= '') then
  283.             wowCharacter = true
  284.             break
  285.         end
  286.     end
  287.    
  288.     if event == 'CHAT_MSG_BN_WHISPER' then
  289.         linkDisplayText = '|c'..modChatColor..' [F] '
  290.     elseif event == 'CHAT_MSG_BN_WHISPER_INFORM' then
  291.         linkDisplayText = '|c'..modChatColor..' [T] '
  292.     end
  293.  
  294.     if wowCharacter then
  295.         class = class:upper()
  296.         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
  297.         linkDisplayText = linkDisplayText..'['..bTagName..' ('..'|c'..bNetClassColors.colorStr..characterName..'|c'..modChatColor..')]'
  298.         playerLink = GetBNPlayerLink(bTag, linkDisplayText, bNetPresenceID, lineID, Chat_GetChatCategory(chatType), 0)
  299.     else
  300.         linkDisplayText = linkDisplayText..'['..bTagName..']'
  301.         playerLink = GetBNPlayerLink(bTag, linkDisplayText, bNetPresenceID, lineID, Chat_GetChatCategory(chatType), 0)
  302.     end
  303.  
  304.     return playerLink, chatMessage
  305. end
  306.  
  307. local function commonMonsterChatEventHandler(event, chatType, modChatColor, timeStamp, ...)
  308.     local chatMessage, npcName = ...
  309.     chatMessage = hexColorNames(chatMessage, modChatColor)
  310.     return timeStamp..WrapTextInColorCode(channelAbbreviationsTable[chatType]..npcName..' '..chatMessage, modChatColor)
  311. end
  312.  
  313. local function commonRaidBossEventHandler(event, chatType, modChatColor, timeStamp, ...)
  314.     local chatMessage, monsterName = ...
  315.     chatMessage = chatMessage:gsub('%%s', monsterName)
  316.     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
  317.     chatMessage = chatMessage:gsub('%:20|t', ':14|t') --this is an alternate way sometimes blizzard puts icons into chat
  318.     chatMessage = chatMessage:gsub('%|r', '|r|c'..modChatColor) --make sure hyperlinks don't cause the rest of our chat to turn white afterwards
  319.     chatMessage = modHexColorNames(chatMessage, modChatColor)
  320.     return timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor)
  321. end
  322.  
  323. local function commonAchievementEventHandler(event, chatType, modChatColor, timeStamp, ...)
  324.     local achievementString, achieverName = ...
  325.     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
  326.         return
  327.     end
  328.  
  329.     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
  330.     achievementString = achievementString:gsub('%!', '')
  331.     local playerLink = createPlayerLinks(event, chatType, ...)
  332.     return timeStamp..' '..playerLink..' '..WrapTextInColorCode(achievementString, modChatColor)
  333. end
  334.  
  335. local function commonBattlegroundEventHandler(event, chatType, modChatColor, timeStamp, ...)
  336.     local chatMessage = ...
  337.     chatMessage = modHexColorNames(chatMessage, modChatColor)
  338.     chatMessage = chatMessage:gsub('%|r', '|r|c'..modChatColor)
  339.     return timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor)
  340. end
  341.  
  342. local chatColor = {} --this will hold the color for our channel to be accesssed
  343. 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
  344.     local message, _, _, _, _, _, _, channelNumber = ...
  345.     if strfind(message, "[\227-\237]") then --blocks random asian shit
  346.         return true
  347.     end
  348.  
  349.     local chatType = strsub(event, 10) --chop off first 'CHAT_MSG_' to get the event
  350.     if strsub(event, 10, 16) == 'CHANNEL' then --this will color chats by their proper color since they're user editable
  351.         chatColor = channelColorHolderTable[channelNumber]
  352.     else
  353.         chatColor = ChatTypeInfo[chatType] or channelColorHolderTable[1] --or just makes the color the generic general chat color
  354.     end
  355.  
  356.     local timeStamp --this will be used to make our own time stamp for each line
  357.     timeStamp = BetterDate(CHAT_TIMESTAMP_FORMAT, time())
  358.     timeStamp = rgbPercToHex(0.5, 0.5, 0.5)..'['..timeStamp..']|r' --this colors the brackets and text grey and adds them around the text
  359.     timeStamp = gsub(timeStamp, ' ', '') --this removes the random space that gets added between the end of the time string and the ]
  360.     timeStamp = '|c'..timeStamp
  361.     local modChatColor = rgbPercToHex(chatColor.r, chatColor.g, chatColor.b)
  362.     if self[event] then --handle our event
  363.         self[event](self, event, chatType, modChatColor, timeStamp, ...)
  364.     end
  365. end)
  366.  
  367. function f:CHAT_MSG_SAY(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player says something
  368.     ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  369. end
  370.  
  371. function f:CHAT_MSG_YELL(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player yells something
  372.     ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  373. end
  374.  
  375. function f:CHAT_MSG_EMOTE(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player performs a custom emote using /e
  376.     local chatMessage = ...
  377.     local channelLink = createChannelLinks(chatType, modChatColor)
  378.     local playerLink = createPlayerLinks(event, chatType, ...)
  379.     chatMessage = modHexColorNames(chatMessage, modChatColor)
  380.     chatMessage = C_ChatInfo.ReplaceIconAndGroupExpressions(chatMessage)
  381.     chatMessage = formatChatMessage(chatMessage, modChatColor)
  382.     ChatFrame1:AddMessage(timeStamp..channelLink..playerLink..' '..WrapTextInColorCode(chatMessage, modChatColor))
  383. end
  384.  
  385. function f:CHAT_MSG_TEXT_EMOTE(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player types in a 'preset' emote
  386.     --so blizzard in their infinite wisdom uses a short name for argument 2 of TEXT_EMOTE
  387.     --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
  388.     --we have to instead get the emoteGUID and from that get the name and realm
  389.     local chatMessage, playerName, _, _, _, _, _, _, _, _, chatLineID, emoteGUID = ...
  390.     local _, _, _, _, _, nameFromGUID, realm = GetPlayerInfoByGUID(emoteGUID)
  391.     if realm then --the player is off realm and has a hyphenated name
  392.         playerName = nameFromGUID..'%-'..realm --rejoin the strings with a % before the - so our gsub can actually look for it
  393.     end
  394.    
  395.     local channelLink = createChannelLinks(chatType, modChatColor)
  396.     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
  397.     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.
  398.         playerLink = createPlayerLinks(event, chatType, _, nameFromGUID..'-'..realm, _, _, _, _, _, 0, _, _, chatLineID, emoteGUID)
  399.         chatMessage = chatMessage:gsub(playerName, playerLink..'|c'..modChatColor)
  400.     end
  401.    
  402.     chatMessage = modHexColorNames(chatMessage, modChatColor)
  403.     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
  404.     ChatFrame1:AddMessage(timeStamp..channelLink..WrapTextInColorCode(chatMessage, modChatColor))
  405. end
  406.  
  407. function f:CHAT_MSG_PARTY(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player in your party says something
  408.     ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  409. end
  410.  
  411. function f:CHAT_MSG_PARTY_LEADER(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player in your party who is leader says something
  412.     ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  413. end
  414.  
  415. function f:CHAT_MSG_INSTANCE_CHAT(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player says something in instance chat
  416.     ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  417. end
  418.  
  419. function f:CHAT_MSG_INSTANCE_CHAT_LEADER(event, chatType, modChatColor, timeStamp, ...) --fires when the party leader says something in instance chat
  420.     ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  421. end
  422.  
  423. function f:CHAT_MSG_RAID(event, chatType, modChatColor, timeStamp, ...) --fires when the you or another player says something in raid chat
  424.     ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  425. end
  426.  
  427. function f:CHAT_MSG_RAID_LEADER(event, chatType, modChatColor, timeStamp, ...) --fires when the raid leader says something in raid chat
  428.     ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  429. end
  430.  
  431. function f:CHAT_MSG_RAID_WARNING(event, chatType, modChatColor, timeStamp, ...) --fires when you or another player issues a raid warning
  432.     ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  433. end
  434.  
  435. function f:CHAT_MSG_WHISPER(event, chatType, modChatColor, timeStamp, ...) --fires when you receive a whisper from another player
  436.     ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  437. end
  438.  
  439. function f:CHAT_MSG_WHISPER_INFORM(event, chatType, modChatColor, timeStamp, ...) --fires when you send a whisper to another player
  440.     ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  441. end
  442.  
  443. function f:CHAT_MSG_BN_WHISPER(event, chatType, modChatColor, timeStamp, ...)
  444.     local playerLink, chatMessage = handleBNWhispers(event, chatType, modChatColor, ...)
  445.     ChatFrame1:AddMessage(timeStamp..playerLink..' '..WrapTextInColorCode(chatMessage, modChatColor))
  446. end
  447.  
  448. function f:CHAT_MSG_BN_WHISPER_INFORM(event, chatType, modChatColor, timeStamp, ...)
  449.     local playerLink, chatMessage = handleBNWhispers(event, chatType, modChatColor, ...)
  450.     ChatFrame1:AddMessage(timeStamp..playerLink..' '..WrapTextInColorCode(chatMessage, modChatColor))
  451. end
  452.  
  453. function f:CHAT_MSG_GUILD(event, chatType, modChatColor, timeStamp, ...) --fires when you or a guildmate says something in guild chat
  454.     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
  455. end
  456.  
  457. function f:CHAT_MSG_OFFICER(event, chatType, modChatColor, timeStamp, ...) --fires when you or a guildmate says something in officer chat
  458.     ChatFrame1:AddMessage(commonChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  459. end
  460.  
  461. function f:CHAT_MSG_MONSTER_SAY(event, chatType, modChatColor, timeStamp, ...) --fires when an NPC says something
  462.     ChatFrame1:AddMessage(commonMonsterChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  463. end
  464.  
  465. function f:CHAT_MSG_MONSTER_YELL(event, chatType, modChatColor, timeStamp, ...) --fires when an NPC yells something
  466.     ChatFrame1:AddMessage(commonMonsterChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  467. end
  468.  
  469. function f:CHAT_MSG_MONSTER_EMOTE(event, chatType, modChatColor, timeStamp, ...) --fires when an NPC performs an emote
  470.     ChatFrame1:AddMessage(commonRaidBossEventHandler(event, chatType, modChatColor, timeStamp, ...))
  471. end
  472.  
  473. function f:CHAT_MSG_MONSTER_WHISPER(event, chatType, modChatColor, timeStamp, ...) --fires when an NPC whispers something to you
  474.     ChatFrame1:AddMessage(commonMonsterChatEventHandler(event, chatType, modChatColor, timeStamp, ...))
  475. end
  476.  
  477. function f:CHAT_MSG_RAID_BOSS_WHISPER(event, chatType, modChatColor, timeStamp, ...) --fires with various events in game, sometimes even in BGs
  478.     ChatFrame1:AddMessage(commonRaidBossEventHandler(event, chatType, modChatColor, timeStamp, ...))
  479. end
  480.  
  481. function f:CHAT_MSG_RAID_BOSS_EMOTE(event, chatType, modChatColor, timeStamp, ...) --fires when a raid boss performs an emote
  482.     ChatFrame1:AddMessage(commonRaidBossEventHandler(event, chatType, modChatColor, timeStamp, ...))
  483. end
  484.  
  485. function f:CHAT_MSG_ACHIEVEMENT(event, chatType, modChatColor, timeStamp, ...) --fires when you earn an achievement
  486.     ChatFrame1:AddMessage(commonAchievementEventHandler(event, chatType, modChatColor, timeStamp, ...))
  487. end
  488.  
  489. function f:CHAT_MSG_GUILD_ACHIEVEMENT(event, chatType, modChatColor, timeStamp, ...) --fires when you (when in a guild) or a guild mate earns an achievement
  490.     ChatFrame1:AddMessage(commonAchievementEventHandler(event, chatType, modChatColor, timeStamp, ...))
  491. end
  492.  
  493. function f:CHAT_MSG_SYSTEM(event, chatType, modChatColor, timeStamp, ...) --fires during a multitude of system events
  494.     local chatMessage = ...
  495.     chatMessage = modHexColorNames(chatMessage, modChatColor)
  496.     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
  497.     ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
  498. end
  499.  
  500. function f:CHAT_MSG_SKILL(event, chatType, modChatColor, timeStamp, ...)
  501.     local chatMessage = ...
  502.     ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
  503. end
  504.  
  505. function f:CHAT_MSG_MONEY(event, chatType, modChatColor, timeStamp, ...) --fires when you gain money
  506.     local chatMessage = ...
  507.     ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
  508. end
  509.  
  510. function f:CHAT_MSG_CURRENCY(event, chatType, modChatColor, timeStamp, ...) --fires when you gain currency
  511.     local chatMessage = ...
  512.     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
  513.     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
  514.     ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
  515. end
  516.  
  517. function f:CHAT_MSG_COMBAT_HONOR_GAIN(event, chatType, modChatColor, timeStamp, ...) --fires when you gain honor
  518.     local chatMessage = ...
  519.     ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
  520. end
  521.  
  522. function f:CHAT_MSG_BG_SYSTEM_NEUTRAL(event, chatType, modChatColor, timeStamp, ...) --fires in a BG when neutral events happen like the match starting
  523.     ChatFrame1:AddMessage(commonBattlegroundEventHandler(event, chatType, modChatColor, timeStamp, ...))
  524. end
  525.  
  526. function f:CHAT_MSG_BG_SYSTEM_ALLIANCE(event, chatType, modChatColor, timeStamp, ...) --fires in a BG when the allianace do stuff
  527.     ChatFrame1:AddMessage(commonBattlegroundEventHandler(event, chatType, modChatColor, timeStamp, ...))
  528. end
  529.  
  530. function f:CHAT_MSG_BG_SYSTEM_HORDE(event, chatType, modChatColor, timeStamp, ...) --fires in a BG when the horde do stuff
  531.     ChatFrame1:AddMessage(commonBattlegroundEventHandler(event, chatType, modChatColor, timeStamp, ...))
  532. end
  533.  
  534. local chatLootMessage = {}
  535. function f:CHAT_MSG_LOOT(event, chatType, modChatColor, timeStamp, ...) --fires when you or a group member loot an item/creates an item
  536.     local chatMessage, playerName, _, _, _, _, _, channelNumber, _, _, chatLineID = ...
  537.     if playerName ~= playerCharacterName then --we don't do this for the player, we don't want to make a hyperlink for ourselves
  538.         local playerLink = createPlayerLinks(event, chatType, ...)
  539.         local playerNameNoRealm = strsub(playerName, 1, strfind(playerName, '-') - 1) --removes realms from players on different realms
  540.  
  541.         chatLootMessage = {strsplit(' ', chatMessage)} --split the message into individual words by spaces, all we care about is the first word (the player's name)
  542.         local w = chatLootMessage[1]
  543.         if (w and strfind(w, '-')) then --the player is off realm and has a hyphenated name
  544.             local a, b = strsplit('-', w) --split the hyphenated name into two strings
  545.             playerName = a..'%-'..b --rejoin the strings with a % before the - so our gsub can actually look for it
  546.         end
  547.        
  548.         if strfind(chatMessage, playerName) then --the person is off realm, we need to look for the full name to gsub
  549.             chatMessage = chatMessage:gsub(playerName, playerLink..'|c'..modChatColor)
  550.         else --the player is on realm, we need to look for the player name without realm to properly replace it
  551.             chatMessage = chatMessage:gsub(playerNameNoRealm, playerLink..'|c'..modChatColor)
  552.         end
  553.     else --playerName == playerCharacterName, so this is the player "You" looting
  554.         chatMessage = chatMessage:gsub('You ', '|c'..playerClassColorTable.colorStr..'You '..'|c'..modChatColor):gsub('Your', '|c'..playerClassColorTable.colorStr..'Your'..'|c'..modChatColor)
  555.     end
  556.    
  557.     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
  558.     ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
  559. end
  560.  
  561. function f:CHAT_MSG_COMBAT_FACTION_CHANGE(event, chatType, modChatColor, timeStamp, ...) --fires when you gain/lose reputation
  562.     local chatMessage = ...
  563.     ChatFrame1:AddMessage(timeStamp..' '..WrapTextInColorCode(chatMessage, modChatColor))
  564. end
  565.  
  566. 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
  567.     local chatMessage, _, _, _, _, _, _, channelNumber, _, _, _, senderGUID = ...
  568.     chatMessage = hexColorNames(chatMessage, modChatColor)
  569.     chatMessage = formatChatMessage(chatMessage, modChatColor)
  570.     channelNumber = createChannelLinks(channelNumber, modChatColor)
  571.     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
  572.         local playerLink = createPlayerLinks(event, chatType, ...)
  573.         chatMessage = timeStamp..channelNumber..playerLink..' |c'..modChatColor..chatMessage
  574.     else
  575.         chatMessage = timeStamp..channelNumber..' '..chatMessage
  576.     end
  577.  
  578.     ChatFrame1:AddMessage(chatMessage)
  579. end
  580.  
  581. function f:CHAT_MSG_CHANNEL_NOTICE(event, chatType, modChatColor, timeStamp, ...) --fires when you change channels
  582.     local notice, _, _, _, _, _, _, _, channelName = ...
  583.     if notice then
  584.         local You = '|c'..playerClassColorTable.colorStr..'You|c' --color the word 'You' by your class color
  585.         if notice == 'YOU_CHANGED' then
  586.             ChatFrame1:AddMessage(timeStamp..' '..You..modChatColor..' + '..channelName..'.')
  587.         elseif (notice == 'YOU_LEFT' or notice == 'SUSPENDED') then
  588.             ChatFrame1:AddMessage(timeStamp..' '..You..modChatColor..' - '..channelName..'.')
  589.         elseif notice == 'THROTTLED' then
  590.             ChatFrame1:AddMessage(timeStamp..' '..You..modChatColor..' were throttled in '..channelName..'.')
  591.         elseif notice == 'TRIAL_RESTRICTED' then
  592.             ChatFrame1:AddMessage(timeStamp..' '..modChatColor..CHAT_TRIAL_RESTRICTED_NOTICE)
  593.         end
  594.     end
  595. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top