Gladdy-TBC/Modules/VersionCheck.lua

59 lines
2.3 KiB
Lua
Raw Normal View History

2022-03-26 00:11:34 +01:00
local tonumber, tostring, str_format = tonumber, tostring, string.format
2021-05-17 16:49:54 +02:00
local UnitName = UnitName
2021-06-15 09:05:50 +02:00
local IsInGroup, IsInRaid = IsInGroup, IsInRaid
local LE_PARTY_CATEGORY_HOME, LE_PARTY_CATEGORY_INSTANCE = LE_PARTY_CATEGORY_HOME, LE_PARTY_CATEGORY_INSTANCE
2021-05-17 16:49:54 +02:00
local Gladdy = LibStub("Gladdy")
2021-07-29 15:53:34 +02:00
2021-05-17 16:49:54 +02:00
local VersionCheck = Gladdy:NewModule("VersionCheck", 1, {
})
LibStub("AceComm-3.0"):Embed(VersionCheck)
function VersionCheck:Initialize()
self.frames = {}
self:RegisterMessage("JOINED_ARENA")
self.playerName = UnitName("player")
end
function VersionCheck:Reset()
self:UnregisterComm("GladdyVCheck")
end
function VersionCheck:JOINED_ARENA()
self:RegisterComm("GladdyVCheck", VersionCheck.OnCommReceived)
2021-06-15 09:05:50 +02:00
if IsInRaid(LE_PARTY_CATEGORY_HOME) then
2022-03-26 00:11:34 +01:00
self:SendCommMessage("GladdyVCheck", str_format("%.2f", Gladdy.version_num), "RAID", self.playerName)
2021-06-15 09:05:50 +02:00
elseif IsInGroup(LE_PARTY_CATEGORY_INSTANCE) or IsInRaid(LE_PARTY_CATEGORY_INSTANCE) then
2022-03-26 00:11:34 +01:00
self:SendCommMessage("GladdyVCheck", str_format("%.2f", Gladdy.version_num), "INSTANCE_CHAT", self.playerName)
2021-06-15 09:05:50 +02:00
elseif IsInGroup(LE_PARTY_CATEGORY_HOME) then
2022-03-26 00:11:34 +01:00
self:SendCommMessage("GladdyVCheck", str_format("%.2f", Gladdy.version_num), "PARTY", self.playerName)
2021-06-15 09:05:50 +02:00
end
2021-05-17 16:49:54 +02:00
end
function VersionCheck:Test(unit)
if unit == "arena1" then
self:RegisterComm("GladdyVCheck", VersionCheck.OnCommReceived)
self:SendCommMessage("GladdyVCheck", tostring(Gladdy.version_num), "RAID", self.playerName)
2021-05-17 16:49:54 +02:00
end
end
function VersionCheck.OnCommReceived(prefix, message, distribution, sender)
if sender ~= VersionCheck.playerName then
2022-03-26 00:11:34 +01:00
local addonVersion = str_format("%.2f", Gladdy.version_num)
local message_num = tonumber(message) or 0
if message and message_num <= Gladdy.version_num then
2021-05-17 16:49:54 +02:00
--Gladdy:Print("Version", "\"".. addonVersion.."\"", "is up to date")
else
Gladdy:Warn("Current version", "\"".. addonVersion.."\"", "is outdated. Most recent version is", "\"".. message.."\"")
Gladdy:Warn("Please download the latest Gladdy version at:")
2021-06-15 09:05:50 +02:00
Gladdy:Warn("https://www.curseforge.com/wow/addons/gladdy-tbc or https://github.com/XiconQoo/Gladdy-TBC")
2021-05-17 16:49:54 +02:00
end
end
end
function VersionCheck:GetOptions()
return nil
end