Refactor AgentTracker and related modules to improve agent management and logging
This commit is contained in:
17
Heimdall.lua
17
Heimdall.lua
@@ -18,7 +18,8 @@ local function init()
|
||||
---@field classColors table<string, string>
|
||||
---@field messenger HeimdallMessengerData
|
||||
---@field who HeimdallWhoData
|
||||
---@field stinkyTracker HeimdallStinkyTrackerData
|
||||
---@field stinkyTracker StinkyTrackerData
|
||||
---@field agentTracker AgentTrackerData
|
||||
---@field networkNodes string[]
|
||||
---@field network HeimdallNetworkData
|
||||
---@field networkMessenger HeimdallNetworkMessengerData
|
||||
@@ -26,7 +27,7 @@ local function init()
|
||||
---@field _L fun(key: string, locale: string): string
|
||||
---@field _Locale Localization
|
||||
---@field VERSION string
|
||||
---@field dumpTable fun(table: any, depth?: number): nil
|
||||
---@field dumpTable fun(table: any, msg?: string, depth?: number): nil
|
||||
---@field utf8len fun(input: string): number
|
||||
---@field padString fun(input: string, targetLength: number, left?: boolean): string
|
||||
---@field GetOrDefault fun(table: table<any, any>, keys: string[], default: any): any
|
||||
@@ -42,7 +43,7 @@ local function init()
|
||||
---@field Inviter InitTable
|
||||
---@field Dueler InitTable
|
||||
---@field Bully InitTable
|
||||
---@field AgentTracker InitTable
|
||||
---@field AgentTracker AgentTracker
|
||||
---@field Emoter InitTable
|
||||
---@field Echoer InitTable
|
||||
---@field Macroer InitTable
|
||||
@@ -279,16 +280,12 @@ local function init()
|
||||
---@field ticker Timer?
|
||||
|
||||
---@class HeimdallWhoData
|
||||
---@field updateTicker number?
|
||||
---@field whoTicker number?
|
||||
---@field updateTicker Timer?
|
||||
---@field whoTicker Timer?
|
||||
---@field ignored table<string, boolean>
|
||||
|
||||
---@class HeimdallStinkyTrackerData
|
||||
---@field stinkies ReactiveValue<table<string, Stinky>>
|
||||
---@field ignored ReactiveValue<table<string, number>>
|
||||
|
||||
---@class HeimdallNetworkData
|
||||
---@field ticker number?
|
||||
---@field ticker Timer?
|
||||
|
||||
---@class HeimdallStinkyCacheData
|
||||
---@field stinkies table<string, {value: number, timestamp: number}>
|
||||
|
@@ -2,118 +2,136 @@ local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
local ModuleName = "AgentTracker"
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.AgentTracker = {}
|
||||
function shared.AgentTracker.Init()
|
||||
--/run Heimdall_Data.config.agents["Cyheuraeth"]=date("%Y-%m-%dT%H:%M:%S")
|
||||
---@type table<string, boolean>
|
||||
local channelRosterFrame = CreateFrame("Frame")
|
||||
channelRosterFrame:RegisterEvent("CHANNEL_ROSTER_UPDATE")
|
||||
channelRosterFrame:SetScript("OnEvent", function(self, event, index)
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Channel roster update received", ModuleName))
|
||||
end
|
||||
if not Heimdall_Data.config.agentTracker.enabled then
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Module disabled, ignoring roster update", ModuleName))
|
||||
end
|
||||
return
|
||||
end
|
||||
local name = GetChannelDisplayInfo(index)
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Processing channel update: %s (index: %d)", ModuleName, name or "nil", index))
|
||||
end
|
||||
if name ~= Heimdall_Data.config.agentTracker.masterChannel then
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Ignoring non-master channel: %s", ModuleName, name or "nil"))
|
||||
end
|
||||
return
|
||||
end
|
||||
local count = select(5, GetChannelDisplayInfo(index))
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Processing %d members in channel", ModuleName, count))
|
||||
end
|
||||
---@class AgentTracker
|
||||
---@field Init fun(): nil
|
||||
---@field Track fun(name: string): boolean
|
||||
---@field IsAgent fun(name: string): boolean
|
||||
---@field OnChange fun(callback: fun(name: string)): nil
|
||||
---@field ForEach fun(callback: fun(name: string)): nil
|
||||
|
||||
local newAgents = 0
|
||||
for i = 1, count do
|
||||
name = GetChannelRosterInfo(index, i)
|
||||
if name then
|
||||
local isNewAgent = not Heimdall_Data.config.agents[name]
|
||||
Heimdall_Data.config.agents[name] = date("%Y-%m-%dT%H:%M:%S")
|
||||
if isNewAgent then newAgents = newAgents + 1 end
|
||||
---@class AgentTrackerData
|
||||
---@field agents ReactiveValue<table<string, string>>
|
||||
|
||||
shared.agentTracker.agents = ReactiveValue(Heimdall_Data.config.agents)
|
||||
|
||||
---@class AgentTracker
|
||||
shared.AgentTracker = {
|
||||
Track = function(name)
|
||||
if not name then return false end
|
||||
local exists = shared.AgentTracker.IsAgent(name)
|
||||
if exists then return false end
|
||||
shared.agentTracker.agents[name] = date("%Y-%m-%dT%H:%M:%S")
|
||||
-- Heimdall_Data.config.agents[name] = date("%Y-%m-%dT%H:%M:%S")
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Tracking new agent: %s", ModuleName, name))
|
||||
shared.dumpTable(shared.agentTracker.agents)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
IsAgent = function(name)
|
||||
if not name then return false end
|
||||
return shared.agentTracker.agents[name] ~= nil
|
||||
end,
|
||||
OnChange = function(callback) shared.agentTracker.agents:onChange(callback) end,
|
||||
ForEach = function(callback)
|
||||
---@type table<string, string>
|
||||
local agents = shared.agentTracker.agents:get()
|
||||
for name, _ in pairs(agents) do
|
||||
callback(name)
|
||||
end
|
||||
end,
|
||||
Init = function()
|
||||
--/run Heimdall_Data.config.agents["Cyheuraeth"]=date("%Y-%m-%dT%H:%M:%S")
|
||||
---@type table<string, boolean>
|
||||
local channelRosterFrame = CreateFrame("Frame")
|
||||
channelRosterFrame:RegisterEvent("CHANNEL_ROSTER_UPDATE")
|
||||
channelRosterFrame:SetScript("OnEvent", function(self, event, index)
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Channel roster update received", ModuleName))
|
||||
end
|
||||
if not Heimdall_Data.config.agentTracker.enabled then
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(
|
||||
string.format(
|
||||
"[%s] %s agent: %s",
|
||||
ModuleName,
|
||||
isNewAgent and "Added new" or "Updated existing",
|
||||
name
|
||||
)
|
||||
)
|
||||
print(string.format("[%s] Module disabled, ignoring roster update", ModuleName))
|
||||
end
|
||||
return
|
||||
end
|
||||
local name = GetChannelDisplayInfo(index)
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Processing channel update: %s (index: %d)", ModuleName, name or "nil", index))
|
||||
end
|
||||
if name ~= Heimdall_Data.config.agentTracker.masterChannel then
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Ignoring non-master channel: %s", ModuleName, name or "nil"))
|
||||
end
|
||||
return
|
||||
end
|
||||
local count = select(5, GetChannelDisplayInfo(index))
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Processing %d members in channel", ModuleName, count))
|
||||
end
|
||||
|
||||
local newAgents = 0
|
||||
for i = 1, count do
|
||||
name = GetChannelRosterInfo(index, i)
|
||||
shared.AgentTracker.Track(name)
|
||||
end
|
||||
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Roster update complete - Added %d new agents", ModuleName, newAgents))
|
||||
end
|
||||
end)
|
||||
|
||||
local agentTrackerChannelSniffer = CreateFrame("Frame")
|
||||
agentTrackerChannelSniffer:RegisterEvent("CHAT_MSG_CHANNEL")
|
||||
agentTrackerChannelSniffer:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
||||
-- if Heimdall_Data.config.agentTracker.debug then
|
||||
-- print(string.format("[%s] Channel message received from: %s", ModuleName, sender))
|
||||
-- end
|
||||
if not Heimdall_Data.config.agentTracker.enabled then
|
||||
-- if Heimdall_Data.config.agentTracker.debug then
|
||||
-- print(string.format("[%s] Module disabled, ignoring channel message", ModuleName))
|
||||
-- end
|
||||
return
|
||||
end
|
||||
|
||||
local channelId = select(6, ...)
|
||||
local _, channelname = GetChannelName(channelId)
|
||||
local ok = false
|
||||
for _, channel in pairs(Heimdall_Data.config.agentTracker.channels) do
|
||||
if channel == channelname then
|
||||
ok = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Roster update complete - Added %d new agents", ModuleName, newAgents))
|
||||
end
|
||||
end)
|
||||
|
||||
local agentTrackerChannelSniffer = CreateFrame("Frame")
|
||||
agentTrackerChannelSniffer:RegisterEvent("CHAT_MSG_CHANNEL")
|
||||
agentTrackerChannelSniffer:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
||||
-- if Heimdall_Data.config.agentTracker.debug then
|
||||
-- print(string.format("[%s] Channel message received from: %s", ModuleName, sender))
|
||||
-- end
|
||||
if not Heimdall_Data.config.agentTracker.enabled then
|
||||
-- if Heimdall_Data.config.agentTracker.debug then
|
||||
-- print(string.format("[%s] Module disabled, ignoring channel message", ModuleName))
|
||||
-- end
|
||||
return
|
||||
end
|
||||
|
||||
local channelId = select(6, ...)
|
||||
local _, channelname = GetChannelName(channelId)
|
||||
local ok = false
|
||||
for _, channel in pairs(Heimdall_Data.config.agentTracker.channels) do
|
||||
if channel == channelname then
|
||||
ok = true
|
||||
break
|
||||
if not ok then
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Channel name does not match any of the channels", ModuleName))
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
if not ok then
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Channel name does not match any of the channels", ModuleName))
|
||||
print(string.format("[%s] Processing message from master channel: %s", ModuleName, sender))
|
||||
end
|
||||
return
|
||||
end
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Processing message from master channel: %s", ModuleName, sender))
|
||||
shared.dumpTable(Heimdall_Data.config.agentTracker)
|
||||
end
|
||||
|
||||
sender = string.match(sender, "^[^-]+")
|
||||
local isNewAgent = not Heimdall_Data.config.agents[sender]
|
||||
Heimdall_Data.config.agents[sender] = date("%Y-%m-%dT%H:%M:%S")
|
||||
sender = string.match(sender, "^[^-]+")
|
||||
local new = shared.AgentTracker.Track(sender)
|
||||
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(
|
||||
string.format(
|
||||
"[%s] %s agent from message: %s",
|
||||
ModuleName,
|
||||
isNewAgent and "Added new" or "Updated existing",
|
||||
sender
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(
|
||||
string.format(
|
||||
"[%s] %s agent from message: %s",
|
||||
ModuleName,
|
||||
new and "Added new" or "Updated existing",
|
||||
sender
|
||||
)
|
||||
)
|
||||
)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
local count = 0
|
||||
for _ in pairs(Heimdall_Data.config.agents) do
|
||||
count = count + 1
|
||||
if Heimdall_Data.config.agentTracker.debug then
|
||||
print(string.format("[%s] Module initialized", ModuleName))
|
||||
shared.dumpTable(shared.agentTracker.agents:get(), "Agents")
|
||||
end
|
||||
print(string.format("[%s] Module initialized - Tracking %d agents", ModuleName, count))
|
||||
end
|
||||
print("[Heimdall] AgentTracker loaded")
|
||||
end
|
||||
print("[Heimdall] AgentTracker loaded")
|
||||
end,
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ function shared.Dueler.Init()
|
||||
print(string.format("[%s] Checking if sender '%s' is in agents list", ModuleName, sender))
|
||||
end
|
||||
|
||||
local allow = Heimdall_Data.config.agents[sender]
|
||||
local allow = shared.AgentTracker.IsAgent(sender)
|
||||
if allow then
|
||||
if Heimdall_Data.config.dueler.debug then
|
||||
print(string.format("[%s] Accepting duel from trusted agent: %s", ModuleName, sender))
|
||||
|
@@ -35,29 +35,25 @@ function shared.Inviter.Init()
|
||||
|
||||
if Heimdall_Data.config.inviter.agentsAssist then
|
||||
if Heimdall_Data.config.inviter.debug then
|
||||
local agentCount = 0
|
||||
for _ in pairs(Heimdall_Data.config.agents) do
|
||||
agentCount = agentCount + 1
|
||||
end
|
||||
print(string.format("[%s] Processing %d agents for assistant promotion", ModuleName, agentCount))
|
||||
print(string.format("[%s] Processing agents for assistant promotion", ModuleName))
|
||||
end
|
||||
|
||||
for name, _ in pairs(Heimdall_Data.config.agents) do
|
||||
if UnitInParty(name) and not UnitIsGroupLeader(name) and not UnitIsRaidOfficer(name) then
|
||||
shared.AgentTracker.ForEach(function(agent)
|
||||
if UnitInParty(agent) and not UnitIsGroupLeader(agent) and not UnitIsRaidOfficer(agent) then
|
||||
if Heimdall_Data.config.inviter.debug then
|
||||
print(string.format("[%s] Promoting agent to assistant: %s", ModuleName, name))
|
||||
print(string.format("[%s] Promoting agent to assistant: %s", ModuleName, agent))
|
||||
end
|
||||
PromoteToAssistant(name, true)
|
||||
PromoteToAssistant(agent, true)
|
||||
elseif Heimdall_Data.config.inviter.debug then
|
||||
if not UnitInParty(name) then
|
||||
print(string.format("[%s] Agent not in party: %s", ModuleName, name))
|
||||
elseif UnitIsGroupLeader(name) then
|
||||
print(string.format("[%s] Agent is already leader: %s", ModuleName, name))
|
||||
elseif UnitIsRaidOfficer(name) then
|
||||
print(string.format("[%s] Agent is already assistant: %s", ModuleName, name))
|
||||
if not UnitInParty(agent) then
|
||||
print(string.format("[%s] Agent not in party: %s", ModuleName, agent))
|
||||
elseif UnitIsGroupLeader(agent) then
|
||||
print(string.format("[%s] Agent is already leader: %s", ModuleName, agent))
|
||||
elseif UnitIsRaidOfficer(agent) then
|
||||
print(string.format("[%s] Agent is already assistant: %s", ModuleName, agent))
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
if Heimdall_Data.config.inviter.debug then
|
||||
|
@@ -5,12 +5,6 @@ local ModuleName = "Macroer"
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.Macroer = {}
|
||||
function shared.Macroer.Init()
|
||||
---@class stinky
|
||||
---@field name string
|
||||
---@field class string
|
||||
---@field seenAt number
|
||||
---@field hostile boolean
|
||||
|
||||
local function FindOrCreateMacro(macroName)
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Finding or creating macro: %s", ModuleName, macroName))
|
||||
@@ -27,7 +21,7 @@ function shared.Macroer.Init()
|
||||
return idx
|
||||
end
|
||||
|
||||
---@param stinkies table<string, stinky>
|
||||
---@param stinkies table<string, Stinky>
|
||||
local function FixMacro(stinkies)
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Fixing macro with %d stinkies", ModuleName, #stinkies))
|
||||
@@ -53,7 +47,7 @@ function shared.Macroer.Init()
|
||||
|
||||
local sortedStinkies = {}
|
||||
for _, stinky in pairs(stinkies) do
|
||||
if not Heimdall_Data.config.agents[stinky.name] then sortedStinkies[#sortedStinkies + 1] = stinky end
|
||||
if not shared.AgentTracker.IsAgent(stinky.name) then sortedStinkies[#sortedStinkies + 1] = stinky end
|
||||
end
|
||||
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
@@ -89,12 +83,12 @@ function shared.Macroer.Init()
|
||||
EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body)
|
||||
end
|
||||
|
||||
shared.stinkyTracker.stinkies:onChange(function(value)
|
||||
shared.StinkyTracker.OnChange(function(stinkies)
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Stinkies changed, updating macro", ModuleName))
|
||||
shared.dumpTable(value)
|
||||
shared.dumpTable(stinkies)
|
||||
end
|
||||
FixMacro(value)
|
||||
FixMacro(stinkies)
|
||||
end)
|
||||
|
||||
if Heimdall_Data.config.macroer.debug then print(string.format("[%s] Module initialized", ModuleName)) end
|
||||
|
@@ -31,7 +31,7 @@ function shared.Spotter.Init()
|
||||
print(string.format("[%s] Checking notification criteria for %s (%s)", ModuleName, name, faction))
|
||||
end
|
||||
|
||||
if Heimdall_Data.config.agents[name] then
|
||||
if shared.AgentTracker.IsAgent(name) then
|
||||
if Heimdall_Data.config.spotter.debug then
|
||||
print(string.format("[%s] Skipping agent: %s", ModuleName, name))
|
||||
end
|
||||
|
@@ -2,13 +2,16 @@ local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
local ModuleName = "StinkyTracker"
|
||||
|
||||
|
||||
---@class Stinky
|
||||
---@field name string
|
||||
---@field class string
|
||||
---@field seenAt number
|
||||
---@field hostile boolean
|
||||
|
||||
---@class StinkyTrackerData
|
||||
---@field stinkies ReactiveValue<table<string, Stinky>>
|
||||
---@field ignored ReactiveValue<table<string, number>>
|
||||
|
||||
---@class StinkyTracker
|
||||
shared.StinkyTracker = {
|
||||
---@param stinky Stinky
|
||||
@@ -68,6 +71,20 @@ shared.StinkyTracker = {
|
||||
return true
|
||||
end,
|
||||
|
||||
---@param callback fun(stinkies: table<string, Stinky>)
|
||||
---@return nil
|
||||
OnChange = function(callback) shared.stinkyTracker.stinkies:onChange(callback) end,
|
||||
|
||||
---@param callback fun(name: string, stinky: Stinky)
|
||||
---@return nil
|
||||
ForEach = function(callback)
|
||||
---@type table<string, Stinky>
|
||||
local stinkies = shared.stinkyTracker.stinkies:get()
|
||||
for name, stinky in pairs(stinkies) do
|
||||
callback(name, stinky)
|
||||
end
|
||||
end,
|
||||
|
||||
Init = function()
|
||||
shared.stinkyTracker = {
|
||||
stinkies = ReactiveValue.new({}),
|
||||
@@ -273,7 +290,7 @@ shared.StinkyTracker = {
|
||||
end
|
||||
|
||||
for name, stinky in pairs(shared.stinkyTracker.stinkies) do
|
||||
if Heimdall_Data.config.agents[name] then
|
||||
if shared.AgentTracker.IsAgent(name) then
|
||||
shared.stinkyTracker.stinkies[name] = nil
|
||||
if Heimdall_Data.config.stinkyTracker.debug then
|
||||
print(string.format("[%s] Removed agent from stinkies: %s", ModuleName, name))
|
||||
|
Reference in New Issue
Block a user