PHP код:
local Throttle, UnusedTimers = {}, {}
local f = CreateFrame"frame"
local ThrottleTime = 5
local events = {
["CHAT_MSG_CHANNEL"] = true,
["CHAT_MSG_YELL"] = true,
["CHAT_MSG_OFFICER"] = true,
["CHAT_MSG_PARTY"] = true,
["CHAT_MSG_PARTY_LEADER"] = true,
["CHAT_MSG_RAID"] = true,
["CHAT_MSG_RAID_LEADER"] = true,
["CHAT_MSG_BATTLEGROUND"] = true,
["CHAT_MSG_BATTLEGROUND_LEADER"] = true,
["CHAT_MSG_WHISPER"] = true,
}
local TimerOnFinished = function(self)
self.Func(unpack(self.Args))
tinsert(UnusedTimers, self)
end
function f:NewTimer()
local Parent = self:CreateAnimationGroup()
local Timer = Parent:CreateAnimation("Alpha")
Timer:SetScript("OnFinished", TimerOnFinished)
Timer.Parent = Parent
return Timer
end
function f:StartTimer(delay, func, ...)
if (type(delay) ~= "number" or type(func) ~= "function") then
return
end
local Timer
if UnusedTimers[1] then
Timer = tremove(UnusedTimers, 1)
else
Timer = self:NewTimer()
end
Timer.Args = {...}
Timer.Func = func
Timer:SetDuration(delay)
Timer.Parent:Play()
end
local RemoveMessage = function(msg)
for i = 1, #Throttle do
if (Throttle[i] == msg) then
table.remove(Throttle, i)
break
end
end
end
local IsThrottled = function(msg)
local Found
for i = 1, #Throttle do
if (Throttle[i] == msg) then
Found = true
end
end
if Found then
return true
else
return false
end
end
local GetString = function(msg, Author)
local NewMessage = ""
local Char = ""
local LastChar = ""
local BuiltMsg = ""
local Index = 35
if (not msg) then
return
end
NewMessage = msg:gsub("...hic!", ""):gsub("%d", ""):gsub("%c", ""):gsub("%p", ""):gsub("%s", ""):upper():gsub("SH", "S")
if (Author ~= nil) then
Index = Index + Author:len()
end
for Char in NewMessage:gmatch("%u") do
if (Char ~= LastChar and Index > 0) then
BuiltMsg = BuiltMsg .. Char
end
LastChar = Char
Index = Index - 1
end
NewMessage = BuiltMsg
if (Author ~= nil) then
NewMessage = Author:upper() .. NewMessage
end
return NewMessage
end
local ThrottleFilter = function(self, event, msg, sender, ...)
local Msg = GetString(msg, sender)
if (not Msg) then
return
end
local Throttled = IsThrottled(Msg)
if Throttled then
return true
else
return false
end
end
local CheckMessage = function(self, event, msg, sender)
local Message = GetString(msg, sender)
table.insert(Throttle, Message)
f:StartTimer(ThrottleTime, RemoveMessage, Message)
end
f:SetScript("OnEvent", CheckMessage)
for event, cfg in pairs(events) do
if cfg then
f:RegisterEvent(event)
ChatFrame_AddMessageEventFilter(event, ThrottleFilter)
end
end
Так это работает: