Quantcast
local A, L = ...

local DefaultSetItemRef = SetItemRef

--we replace the default setitemref and use it to parse links for alt invite and url copy
function SetItemRef(link, ...)
  local type, value = link:match("(%a+):(.+)")
  if IsAltKeyDown() and type == "player" then
    InviteUnit(value:match("([^:]+)"))
  elseif (type == "url") then
    local eb = LAST_ACTIVE_CHAT_EDIT_BOX or ChatFrame1EditBox
    if not eb then return end
    eb:SetText(value)
    eb:SetFocus()
    eb:HighlightText()
    if not eb:IsShown() then eb:Show() end
  else
    return DefaultSetItemRef(link, ...)
  end
end

--生成新的ICON超链接
local function GetHyperlink(Hyperlink, texture)
  if not texture then
    return Hyperlink
  else
    return "|T" .. texture .. ":0|t|h" .. Hyperlink
  end
end

--等级图标显示
local function SetChatLinkIcon(Hyperlink)
  local schema, id = string.match(Hyperlink, "|H(%w+):(%d+):")
  local texture
  if (schema == "item") then
    texture = select(10, GetItemInfo(tonumber(id)))
  elseif (schema == "currency") then
    texture = C_CurrencyInfo.GetCurrencyInfo(tonumber(id)).iconFileID
  elseif (schema == "spell") then
    texture = select(3, GetSpellInfo(tonumber(id)))
  elseif (schema == "achievement") then
    texture = select(10, GetAchievementInfo(tonumber(id)))
  end
  return GetHyperlink(Hyperlink, texture)
end

--过滤器
local function ChatLinkFilter(self, event, msg, ...)
  msg = msg:gsub("(|H%w+:%d+:.-|h.-|h)", SetChatLinkIcon)
  return false, msg, ...
end

ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL", ChatLinkFilter)-- 公共频道
ChatFrame_AddMessageEventFilter("CHAT_MSG_SAY", ChatLinkFilter)-- 说
ChatFrame_AddMessageEventFilter("CHAT_MSG_YELL", ChatLinkFilter)-- 大喊
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID", ChatLinkFilter)-- 团队
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_LEADER", ChatLinkFilter)-- 团队领袖
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY", ChatLinkFilter)-- 队伍
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY_LEADER", ChatLinkFilter)-- 队伍领袖
ChatFrame_AddMessageEventFilter("CHAT_MSG_GUILD", ChatLinkFilter)-- 公会

ChatFrame_AddMessageEventFilter("CHAT_MSG_AFK", ChatLinkFilter)-- AFK玩家自动回复
ChatFrame_AddMessageEventFilter("CHAT_MSG_DND", ChatLinkFilter)-- 切勿打扰自动回复
-- 副本和副本领袖
ChatFrame_AddMessageEventFilter("CHAT_MSG_INSTANCE_CHAT", ChatLinkFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_INSTANCE_CHAT_LEADER", ChatLinkFilter)
-- 解析战网私聊
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", ChatLinkFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", ChatLinkFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_WHISPER", ChatLinkFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_WHISPER_INFORM", ChatLinkFilter)
-- 解析社区聊天内容
ChatFrame_AddMessageEventFilter("CHAT_MSG_COMMUNITIES_CHANNEL", ChatLinkFilter)
--拾取信息
ChatFrame_AddMessageEventFilter("CHAT_MSG_LOOT", ChatLinkFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_CURRENCY", ChatLinkFilter)