Harden chat level player link handling

This commit is contained in:
Dusk-92
2026-08-25 11:26:09 +02:00
parent 77ab1c6d91
commit 3081d33145
+13 -5
View File
@@ -2,6 +2,7 @@ local _G = ShaguTweaks.GetGlobalEnv()
local T = ShaguTweaks.T
local gfind = string.gmatch or string.gfind
local rgbhex = ShaguTweaks.rgbhex
local strsplit = ShaguTweaks.strsplit
local module = ShaguTweaks:register({
title = T["Chat Levels"],
@@ -26,18 +27,25 @@ module.enable = function(self)
frame.HookAddMessageLevel = frame.AddMessage
frame.AddMessage = function(f, text, a1, a2, a3, a4, a5)
if text and playerdb then
for name in gfind(text, "|Hplayer:(.-)|h") do
local data = playerdb[name]
for linkName in gfind(text, "|Hplayer:(.-)|h") do
-- Turtle/other chat handlers may append metadata after the
-- actual player name in the hyperlink payload. Keep the full
-- payload in the link, but use only the real name for our cache.
local real = strsplit(":", linkName)
local data = real and playerdb[real]
if data and data.level then
local level = data.level
local color = rgbhex(GetDifficultyColor(level))
text = string.gsub(text,
"|Hplayer:" .. name .. "|h%[" .. name .. "%]|h|r",
"|Hplayer:" .. name .. "|h[" .. name .. "]|h|r " .. color .. level .. "|r")
"|Hplayer:" .. linkName .. "|h%[" .. real .. "%]|h|r",
"|Hplayer:" .. linkName .. "|h[" .. real .. "]|h|r " .. color .. level .. "|r")
end
end
end
frame.HookAddMessageLevel(f, text, a1, a2, a3, a4, a5)
-- Call the wrapper owned by the frame being invoked. This keeps the
-- hook chain correct even if another chat addon wraps frames later.
f.HookAddMessageLevel(f, text, a1, a2, a3, a4, a5)
end
end
end