120 lines
4.0 KiB
Lua
120 lines
4.0 KiB
Lua
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
|
|
|
|
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
|
|
if Heimdall_Data.config.agentTracker.debug then
|
|
print(
|
|
string.format(
|
|
"[%s] %s agent: %s",
|
|
ModuleName,
|
|
isNewAgent and "Added new" or "Updated existing",
|
|
name
|
|
)
|
|
)
|
|
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
|
|
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))
|
|
end
|
|
return
|
|
end
|
|
if Heimdall_Data.config.agentTracker.debug then
|
|
print(string.format("[%s] Processing message from master channel: %s", ModuleName, sender))
|
|
shared.dump(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")
|
|
|
|
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
|
|
)
|
|
)
|
|
end
|
|
end)
|
|
|
|
if Heimdall_Data.config.agentTracker.debug then
|
|
local count = 0
|
|
for _ in pairs(Heimdall_Data.config.agents) do
|
|
count = count + 1
|
|
end
|
|
print(string.format("[%s] Module initialized - Tracking %d agents", ModuleName, count))
|
|
end
|
|
print("[Heimdall] AgentTracker loaded")
|
|
end
|