Commit ff6451f8 authored by Simpy's avatar Simpy 🐹

ver check: prevent setting multiple timers

parent 8fa8a6ac
......@@ -180,7 +180,9 @@ function lib:VersionCheck(event, prefix, message, _, sender)
lib.E.SendPluginVersionCheck = SendPluginVersionCheck
end
lib.E:ScheduleTimer("SendPluginVersionCheck", 10)
if not lib.SendMessageTimer then
lib.SendMessageTimer = lib.E:ScheduleTimer("SendPluginVersionCheck", 10)
end
end
end
......@@ -206,6 +208,10 @@ function lib:GeneratePluginList()
return list
end
local clearSendMessageTimer = function()
lib.SendMessageTimer = nil
end
function lib:SendPluginVersionCheck(message)
if (not message) or strmatch(message, "^%s-$") then return end
local ChatType, Channel
......@@ -217,7 +223,10 @@ function lib:SendPluginVersionCheck(message)
ChatType = "GUILD"
end
if not ChatType then return end
if not ChatType then
clearSendMessageTimer()
return
end
local delay, maxChar, msgLength = 0, 250, strlen(message)
if msgLength > maxChar then
......@@ -228,10 +237,12 @@ function lib:SendPluginVersionCheck(message)
message = gsub(message, "^"..gsub(splitMessage, '([%(%)%.%%%+%-%*%?%[%^%$])','%%%1'), "")
lib.E:Delay(delay, C_ChatInfo_SendAddonMessage, lib.prefix, splitMessage, ChatType, Channel)
delay = delay + 1
lib.E:Delay(delay, clearSendMessageTimer) -- keep this after `delay = delay + 1`
end
end
else
C_ChatInfo_SendAddonMessage(lib.prefix, message, ChatType, Channel)
clearSendMessageTimer()
end
end
......
......@@ -904,6 +904,7 @@ function E:SplitString(s, delim)
return unpack(t)
end
local SendMessageTimer -- prevent setting multiple timers at once
function E:SendMessage()
local ElvUIGVC = GetChannelName('ElvUIGVC')
if ElvUIGVC and ElvUIGVC > 0 then
......@@ -911,6 +912,8 @@ function E:SendMessage()
elseif IsInGuild() then
C_ChatInfo_SendAddonMessage("ELVUI_VERSIONCHK", E.version, "GUILD")
end
SendMessageTimer = nil
end
local myRealm = gsub(E.myrealm,'[%s%-]','')
......@@ -929,11 +932,13 @@ local function SendRecieve(_, event, prefix, message, _, sender)
E.recievedOutOfDateMessage = true
elseif msg ~= nil and (msg < ver) then -- Send Message Back if you intercept and are higher revision
E:ScheduleTimer('SendMessage', 10)
if not SendMessageTimer then
SendMessageTimer = E:ScheduleTimer('SendMessage', 10)
end
end
end
else
E:ScheduleTimer('SendMessage', 10)
elseif not SendMessageTimer then
SendMessageTimer = E:ScheduleTimer('SendMessage', 10)
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment