Add more error checks and logs to whoer

This commit is contained in:
2024-12-12 15:10:19 +01:00
parent 801559a25d
commit f51ce68b2e

View File

@@ -2,6 +2,11 @@ local _, data = ...
---@cast data HeimdallData ---@cast data HeimdallData
if not data.config.who.enabled then return end if not data.config.who.enabled then return end
if not Heimdall_Data.who then Heimdall_Data.who = {} end
if not Heimdall_Data.who.data then Heimdall_Data.who.data = {} end
print(Heimdall_Data)
print(Heimdall_Data.who)
print(Heimdall_Data.who.data)
---@type table<string, Player> ---@type table<string, Player>
local players = {} local players = {}
@@ -126,6 +131,8 @@ 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
local text = player:NotifyMessage() local text = player:NotifyMessage()
---@type Message ---@type Message
local msg = { local msg = {
@@ -189,6 +196,9 @@ end
---@param player Player ---@param player Player
---@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 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,
player.class, player.class,
@@ -244,6 +254,8 @@ frame:SetScript("OnEvent", function(self, event, ...)
local player = players[name] local player = players[name]
if not player then if not player then
player = Player.new(name, guild, race, class, zone) 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] local existing = Heimdall_Data.who.data[name]
if existing then if existing then
@@ -282,10 +294,15 @@ frame:SetScript("OnEvent", function(self, event, ...)
player.zone = zone player.zone = zone
player.lastSeen = timestamp player.lastSeen = timestamp
players[name] = player 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
end) end)
if not data.who.updateTicker then if not data.who.updateTicker then
@@ -315,7 +332,8 @@ if not data.who.whoTicker then
whoQueryIdx = 1 whoQueryIdx = 1
end end
lastQuery = query lastQuery = query
print("Running who query: " .. tostring(query.query)) print(string.format("Running who query: %s", tostring(query.query)))
SetWhoToUI(1)
SendWho(query.query) SendWho(query.query)
end) end)
end end