Fix issue with whoer getting stuck on queries because of return

This commit is contained in:
2024-12-12 15:32:36 +01:00
parent f51ce68b2e
commit ce03160faa

121
Whoer.lua
View File

@@ -131,7 +131,10 @@ local lastQuery = nil
---@return string? ---@return string?
local function Notify(player) local function Notify(player)
if not player then return string.format("Cannot notify for nil player %s", tostring(player)) end if not player then return string.format("Cannot notify for nil player %s", tostring(player)) end
if not data.config.who.zoneNotifyFor[player.zone] then return string.format("Not notifying for zone %s", tostring(player.zone)) end if not data.config.who.zoneNotifyFor[player.zone] then
return string.format("Not notifying for zone %s",
tostring(player.zone))
end
local text = player:NotifyMessage() local text = player:NotifyMessage()
---@type Message ---@type Message
@@ -197,7 +200,10 @@ end
---@return string? ---@return string?
local function NotifyGone(player) local function NotifyGone(player)
if not player then return string.format("Cannot notify for nil player %s", tostring(player)) end if not player then return string.format("Cannot notify for nil player %s", tostring(player)) end
if not data.config.who.zoneNotifyFor[player.zone] then return string.format("Not notifying for zone %s", tostring(player.zone)) end if not data.config.who.zoneNotifyFor[player.zone] then
return string.format("Not notifying for zone %s",
tostring(player.zone))
end
local text = string.format("%s of class %s and guild %s left %s", local text = string.format("%s of class %s and guild %s left %s",
player.name, player.name,
@@ -231,78 +237,83 @@ end
local frame = CreateFrame("Frame") local frame = CreateFrame("Frame")
frame:RegisterEvent("WHO_LIST_UPDATE") frame:RegisterEvent("WHO_LIST_UPDATE")
frame:SetScript("OnEvent", function(self, event, ...) frame:SetScript("OnEvent", function(self, event, ...)
---@type WHOQuery?
local query = lastQuery
if not query then
print("No query wtf?")
return
end
for i = 1, GetNumWhoResults() do for i = 1, GetNumWhoResults() do
local name, guild, level, race, class, zone = GetWhoInfo(i) local name, guild, level, race, class, zone = GetWhoInfo(i)
if data.who.ignored[name] then return end if data.who.ignored[name] then return end
local continue = false
---@type WHOQuery?
local query = lastQuery
if not query then
print("No query wtf?")
return
end
---@type WHOFilter[] ---@type WHOFilter[]
local filters = query.filters local filters = query.filters
for _, filter in pairs(filters) do for _, filter in pairs(filters) do
if not filter(name, guild, level, race, class, zone) then if not filter(name, guild, level, race, class, zone) then
return -- Mega scuffed, yes...
-- But wow does not have gotos
continue = true
end end
end end
local timestamp = date("%Y-%m-%dT%H:%M:%S") if not continue then
local player = players[name] local timestamp = date("%Y-%m-%dT%H:%M:%S")
if not player then local player = players[name]
player = Player.new(name, guild, race, class, zone) if not player then
player = Player.new(name, guild, race, class, zone)
if not Heimdall_Data.who then Heimdall_Data.who = {} end
if not Heimdall_Data.who.data then Heimdall_Data.who.data = {} end
local existing = Heimdall_Data.who.data[name]
if existing then
player.lastSeen = existing.lastSeen or "never"
player.firstSeen = existing.firstSeen or "never"
player.seenCount = existing.seenCount or 0
end
if player.firstSeen == "never" then
player.firstSeen = timestamp
end
local stinky = data.stinkies[name]
if stinky then
PlaySoundFile("Interface\\Sounds\\Domination.ogg", "Master")
else
PlaySoundFile("Interface\\Sounds\\Cloak.ogg", "Master")
end
local err = Notify(player)
if err then
print(string.format("Error notifying for %s: %s", tostring(name), tostring(err)))
end
player.lastSeen = timestamp
player.seenCount = player.seenCount + 1
players[name] = player
end
player.lastSeenInternal = GetTime()
if player.zone ~= zone then
local err = NotifyZoneChanged(player, zone)
if err then
print(string.format("Error notifying for %s: %s", tostring(name), tostring(err)))
end
end
player.zone = zone
player.lastSeen = timestamp
players[name] = player
if not Heimdall_Data.who then Heimdall_Data.who = {} end if not Heimdall_Data.who then Heimdall_Data.who = {} end
if not Heimdall_Data.who.data then Heimdall_Data.who.data = {} end if not Heimdall_Data.who.data then Heimdall_Data.who.data = {} end
local existing = Heimdall_Data.who.data[name] Heimdall_Data.who.data[name] = player
if existing then
player.lastSeen = existing.lastSeen or "never"
player.firstSeen = existing.firstSeen or "never"
player.seenCount = existing.seenCount or 0
end
if player.firstSeen == "never" then
player.firstSeen = timestamp
end
local stinky = data.stinkies[name]
if stinky then
PlaySoundFile("Interface\\Sounds\\Domination.ogg", "Master")
else
PlaySoundFile("Interface\\Sounds\\Cloak.ogg", "Master")
end
local err = Notify(player)
if err then
print(string.format("Error notifying for %s: %s", tostring(name), tostring(err)))
end
player.lastSeen = timestamp
player.seenCount = player.seenCount + 1
players[name] = player
end end
player.lastSeenInternal = GetTime()
if player.zone ~= zone then
local err = NotifyZoneChanged(player, zone)
if err then
print(string.format("Error notifying for %s: %s", tostring(name), tostring(err)))
end
end
player.zone = zone
player.lastSeen = timestamp
players[name] = player
if not Heimdall_Data.who then Heimdall_Data.who = {} end
if not Heimdall_Data.who.data then Heimdall_Data.who.data = {} end
Heimdall_Data.who.data[name] = player
end end
print("Done?")
-- Turns out WA cannot do this ( -- Turns out WA cannot do this (
-- aura_env.UpdateMacro() -- aura_env.UpdateMacro()
_G["FriendsFrameCloseButton"]:Click() _G["FriendsFrameCloseButton"]:Click()
queryPending = false queryPending = false
print(queryPending)
end) end)
if not data.who.updateTicker then if not data.who.updateTicker then