From d3004019c6b3009af315b3f39bfb8ce00d12e7bc Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Wed, 8 Jan 2025 17:11:07 +0100 Subject: [PATCH] Fix up the log messages a lil Unbutcher inviter --- Modules/AgentTracker.lua | 73 ++++++++-------- Modules/Bully.lua | 6 +- Modules/CombatAlerter.lua | 73 ++++++++++++---- Modules/Commander.lua | 36 ++++---- Modules/DeathReporter.lua | 178 ++++++++++++++++++++++++-------------- Modules/Dueler.lua | 28 ++++-- Modules/Echoer.lua | 33 +++++-- Modules/Emoter.lua | 34 ++++++-- Modules/Inviter.lua | 83 +++++++++++------- Modules/Macroer.lua | 46 ++++++---- Modules/Messenger.lua | 88 +++++++++++++------ Modules/Spotter.lua | 107 ++++++++++++++--------- Modules/StinkyTracker.lua | 55 ++++++++---- Modules/Whoer.lua | 104 ++++++++++++++++++---- scratch.lua | 8 ++ 15 files changed, 647 insertions(+), 305 deletions(-) create mode 100644 scratch.lua diff --git a/Modules/AgentTracker.lua b/Modules/AgentTracker.lua index 2f9f4cf..6b1b5f6 100644 --- a/Modules/AgentTracker.lua +++ b/Modules/AgentTracker.lua @@ -11,79 +11,84 @@ function shared.AgentTracker.Init() channelRosterFrame:RegisterEvent("CHANNEL_ROSTER_UPDATE") channelRosterFrame:SetScript("OnEvent", function(self, event, index) if Heimdall_Data.config.agentTracker.debug then - print(string.format("%s: Received event: %s", ModuleName, event)) - shared.dumpTable(Heimdall_Data.config.agentTracker) + 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: AgentTracker disabled", ModuleName)) + 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: %s", ModuleName, name)) + 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: Channel is not master channel: %s", ModuleName, name)) + 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 local name = GetChannelRosterInfo(index, i) if name then - if Heimdall_Data.config.agentTracker.debug then - print(string.format("%s: Tracking agent in channel: %s", ModuleName, name)) - end + 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: Received event: %s", ModuleName, event)) - shared.dumpTable(Heimdall_Data.config.agentTracker) + 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: AgentTracker disabled", ModuleName)) + print(string.format("[%s] Module disabled, ignoring channel message", ModuleName)) end return end + local channelId = select(6, ...) - local channelname = GetChannelName(channelId) - if Heimdall_Data.config.agentTracker.debug then - print(string.format("%s: Processing message from: %s", ModuleName, sender)) - end - if not channelname then + local _, channelname = GetChannelName(channelId) + if channelname ~= Heimdall_Data.config.agentTracker.masterChannel then if Heimdall_Data.config.agentTracker.debug then - print(string.format("%s: No channel name found", ModuleName)) + print(string.format("[%s] Ignoring message from non-master channel: %s", ModuleName, channelname)) end return end - if channelname ~= Heimdall_Data.config.who.notifyChannel then - if Heimdall_Data.config.agentTracker.debug then - print(string.format("%s: Message not in notify channel: %s", ModuleName, channelname)) - end - return + + 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 - local agentName = sender - if Heimdall_Data.config.agentTracker.debug then - print(string.format("%s: Tracking agent from message: %s", ModuleName, agentName)) - end - if not agentName then - if Heimdall_Data.config.agentTracker.debug then - print(string.format("%s: No agent name found", ModuleName)) - end - return - end - Heimdall_Data.config.agents[agentName] = date("%Y-%m-%dT%H:%M:%S") end) - print("Heimdall - AgentTracker loaded") + 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 diff --git a/Modules/Bully.lua b/Modules/Bully.lua index df54660..918cd2d 100644 --- a/Modules/Bully.lua +++ b/Modules/Bully.lua @@ -1,9 +1,13 @@ local addonname, shared = ... ---@cast shared HeimdallShared ---@cast addonname string +local ModuleName = "Bully" ---@diagnostic disable-next-line: missing-fields shared.Bully = {} function shared.Bully.Init() - print("Heimdall - Bully loaded") + if Heimdall_Data.config.bully.debug then + print(string.format("[%s] Module initialized", ModuleName)) + end + print("[Heimdall] Bully loaded") end diff --git a/Modules/CombatAlerter.lua b/Modules/CombatAlerter.lua index 45140b6..4818c8f 100644 --- a/Modules/CombatAlerter.lua +++ b/Modules/CombatAlerter.lua @@ -11,47 +11,77 @@ function shared.CombatAlerter.Init() combatAlerterFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") combatAlerterFrame:SetScript("OnEvent", function(self, event, ...) if Heimdall_Data.config.combatAlerter.debug then - print(string.format("%s: Received event: %s", ModuleName, event)) - shared.dumpTable(Heimdall_Data.config.combatAlerter) + print(string.format("[%s] Combat log event received", ModuleName)) end - if not Heimdall_Data.config.combatAlerter.enabled then return end + if not Heimdall_Data.config.combatAlerter.enabled then + if Heimdall_Data.config.combatAlerter.debug then + print(string.format("[%s] Module disabled, ignoring combat event", ModuleName)) + end + return + end + local destination, err = CLEUParser.GetDestName(...) - if err then return end - if Heimdall_Data.config.combatAlerter.debug then - print(string.format("%s: Destination: %s", ModuleName, destination)) + if err then + if Heimdall_Data.config.combatAlerter.debug then + print(string.format("[%s] Error getting destination: %s", ModuleName, err)) + end + return end - if destination ~= UnitName("player") then return end + + if Heimdall_Data.config.combatAlerter.debug then + print(string.format("[%s] Combat event destination: %s", ModuleName, destination)) + end + + if destination ~= UnitName("player") then + if Heimdall_Data.config.combatAlerter.debug then + print(string.format("[%s] Ignoring event - not targeted at player", ModuleName)) + end + return + end + local source, err = CLEUParser.GetSourceName(...) - if Heimdall_Data.config.combatAlerter.debug then - print(string.format("%s: Source: %s", ModuleName, source)) + if err then + if Heimdall_Data.config.combatAlerter.debug then + print(string.format("[%s] Error getting source, using 'unknown': %s", ModuleName, err)) + end + source = "unknown" + end + + if Heimdall_Data.config.combatAlerter.debug then + print(string.format("[%s] Combat event source: %s", ModuleName, source)) end - if err then source = "unknown" end if shared.stinkyTracker.stinkies and shared.stinkyTracker.stinkies[source] then if Heimdall_Data.config.combatAlerter.debug then - print(string.format("%s: Alerted status for %s: %s", ModuleName, source, alerted[source])) + print(string.format("[%s] Source is tracked stinky: %s (Already alerted: %s)", ModuleName, source, tostring(alerted[source] or false))) end if alerted[source] then return end + alerted[source] = true local x, y = GetPlayerMapPosition("player") + local zone, subZone = GetZoneText(), GetSubZoneText() + if Heimdall_Data.config.combatAlerter.debug then - print(string.format("%s: Player position: %2.2f,%2.2f", ModuleName, x, y)) + print(string.format("[%s] Player location: %s/%s at %.2f,%.2f", ModuleName, zone, subZone, x * 100, y * 100)) end + ---@type Message local msg = { channel = "CHANNEL", data = Heimdall_Data.config.combatAlerter.masterChannel, message = string.format("%s is attacking me in %s(%s) at %2.2f,%2.2f ", source, - GetZoneText(), GetSubZoneText(), + zone, subZone, x * 100, y * 100 ), } + if Heimdall_Data.config.combatAlerter.debug then - print(string.format("%s: Message:", ModuleName)) - shared.dumpTable(msg) + print(string.format("[%s] Queuing alert message: '%s'", ModuleName, msg.message)) end table.insert(shared.messenger.queue, msg) + elseif Heimdall_Data.config.combatAlerter.debug then + print(string.format("[%s] Source not in stinky list, ignoring: %s", ModuleName, source)) end end) @@ -60,11 +90,18 @@ function shared.CombatAlerter.Init() combatTriggerFrame:RegisterEvent("PLAYER_REGEN_ENABLED") combatTriggerFrame:SetScript("OnEvent", function(self, event, ...) if Heimdall_Data.config.combatAlerter.debug then - print(string.format("%s: Received event: %s", ModuleName, event)) - shared.dumpTable(Heimdall_Data.config.combatAlerter) + print(string.format("[%s] Combat state changed: %s", ModuleName, event)) + if event == "PLAYER_REGEN_DISABLED" then + print(string.format("[%s] Entered combat - Resetting alerts", ModuleName)) + else + print(string.format("[%s] Left combat - Resetting alerts", ModuleName)) + end end alerted = {} end) - print("Heimdall - CombatAlerter loaded") + if Heimdall_Data.config.combatAlerter.debug then + print(string.format("[%s] Module initialized", ModuleName)) + end + print("[Heimdall] CombatAlerter loaded") end diff --git a/Modules/Commander.lua b/Modules/Commander.lua index 7f60bbc..c4f8e63 100644 --- a/Modules/Commander.lua +++ b/Modules/Commander.lua @@ -88,7 +88,7 @@ function shared.Commander.Init() end end if Heimdall_Data.config.commander.debug then - print(string.format("%s: ret = %s", ModuleName, strjoin(", ", unpack(ret)))) + print(string.format("[%s] Command result: %s", ModuleName, strjoin(", ", unpack(ret)))) end return ret end @@ -116,7 +116,7 @@ function shared.Commander.Init() text[#text + 1] = string.format("%s: %d", class, count) end if Heimdall_Data.config.commander.debug then - print(string.format("%s: ret = %s", ModuleName, strjoin(", ", unpack(text)))) + print(string.format("[%s] Message text: %s", ModuleName, strjoin(", ", unpack(text)))) end return text end @@ -131,7 +131,7 @@ function shared.Commander.Init() return text end local function CountClassPartitionedStinkies() - if Heimdall_Data.config.commander.debug then print(string.format("%s: CountClassPartitionedStinkies", ModuleName)) end + if Heimdall_Data.config.commander.debug then print(string.format("[%s] Executing: CountClassPartitionedStinkies", ModuleName)) end local res = CountClassPartitioned(HeimdallStinkies) if #res == 0 then return { "No stinkies found" } @@ -139,7 +139,7 @@ function shared.Commander.Init() return res end local function WhoPartitionedStinkies() - if Heimdall_Data.config.commander.debug then print(string.format("%s: WhoPartitionedStinkies", ModuleName)) end + if Heimdall_Data.config.commander.debug then print(string.format("[%s] Executing: WhoPartitionedStinkies", ModuleName)) end local res = WhoPartitioned(HeimdallStinkies) if #res == 0 then return { "No stinkies found" } @@ -147,7 +147,7 @@ function shared.Commander.Init() return res end local function CountPartitionedStinkies() - if Heimdall_Data.config.commander.debug then print(string.format("%s: CountPartitionedStinkies", ModuleName)) end + if Heimdall_Data.config.commander.debug then print(string.format("[%s] Executing: CountPartitionedStinkies", ModuleName)) end local res = CountPartitioned(HeimdallStinkies) if #res == 0 then return { "No stinkies found" } @@ -155,25 +155,25 @@ function shared.Commander.Init() return res end local function HelpRu() - if Heimdall_Data.config.commander.debug then print(string.format("%s: HelpRu", ModuleName)) end + if Heimdall_Data.config.commander.debug then print(string.format("[%s] Executing: HelpRu", ModuleName)) end return helpMessages.ru end local function HelpEn() - if Heimdall_Data.config.commander.debug then print(string.format("%s: HelpEn", ModuleName)) end + if Heimdall_Data.config.commander.debug then print(string.format("[%s] Executing: HelpEn", ModuleName)) end return helpMessages.en end local groupInviteFrame = CreateFrame("Frame") groupInviteFrame:SetScript("OnEvent", function(self, event, ...) - if Heimdall_Data.config.commander.debug then print(string.format("%s: OnEvent", ModuleName)) end + if Heimdall_Data.config.commander.debug then print(string.format("[%s] Event received", ModuleName)) end AcceptGroup() groupInviteFrame:UnregisterEvent("PARTY_INVITE_REQUEST") C_Timer.NewTimer(0.1, function() - if Heimdall_Data.config.commander.debug then print(string.format("%s: Click", ModuleName)) end + if Heimdall_Data.config.commander.debug then print(string.format("[%s] Click event triggered", ModuleName)) end _G["StaticPopup1Button1"]:Click() end, 1) end) local function JoinGroup() - if Heimdall_Data.config.commander.debug then print(string.format("%s: JoinGroup", ModuleName)) end + if Heimdall_Data.config.commander.debug then print(string.format("[%s] JoinGroup command received", ModuleName)) end groupInviteFrame:RegisterEvent("PARTY_INVITE_REQUEST") C_Timer.NewTimer(10, function() groupInviteFrame:UnregisterEvent("PARTY_INVITE_REQUEST") @@ -181,13 +181,13 @@ function shared.Commander.Init() return { "+" } end local function LeaveGroup() - if Heimdall_Data.config.commander.debug then print(string.format("%s: LeaveGroup", ModuleName)) end + if Heimdall_Data.config.commander.debug then print(string.format("[%s] LeaveGroup command received", ModuleName)) end LeaveParty() return {} end ---@param target string local function FollowTarget(target) - if Heimdall_Data.config.commander.debug then print(string.format("%s: FollowTarget: %s", ModuleName, target)) end + if Heimdall_Data.config.commander.debug then print(string.format("[%s] Following target: %s", ModuleName, target)) end if not target then return end FollowUnit(target) return {} @@ -213,25 +213,25 @@ function shared.Commander.Init() commanderChannelFrame:RegisterEvent("CHAT_MSG_CHANNEL") commanderChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...) if Heimdall_Data.config.commander.debug then - print(string.format("%s: OnEvent", ModuleName)) + print(string.format("[%s] Event received", ModuleName)) shared.dumpTable(Heimdall_Data.config.commander) end if not Heimdall_Data.config.commander.enabled then return end local channelId = select(6, ...) local _, channelname = GetChannelName(channelId) if Heimdall_Data.config.commander.debug then - print(string.format("%s: channelname = %s", ModuleName, channelname)) + print(string.format("[%s] Channel received: %s", ModuleName, channelname)) end if channelname ~= Heimdall_Data.config.commander.masterChannel then return end sender = string.match(sender, "^[^-]+") if Heimdall_Data.config.commander.debug then - print(string.format("%s: sender = %s", ModuleName, sender)) + print(string.format("[%s] Message from: %s", ModuleName, sender)) end for _, command in ipairs(commands) do local enabled = Heimdall_Data.config.commander.commands[command.keywordRe] == true or false if Heimdall_Data.config.commander.debug then - print(string.format("%s: command.keywordRe = %s: %s", ModuleName, command.keywordRe, tostring(enabled))) + print(string.format("[%s] Command match: %s = %s", ModuleName, command.keywordRe, tostring(enabled))) end if enabled and (not command.commanderOnly @@ -240,7 +240,7 @@ function shared.Commander.Init() if msg:match(command.keywordRe) then local messages = command.callback({ strsplit(" ", msg) }) if Heimdall_Data.config.commander.debug then - print(string.format("%s: messages = %s", ModuleName, strjoin(", ", unpack(messages)))) + print(string.format("[%s] Messages to send: %s", ModuleName, strjoin(", ", unpack(messages)))) end for _, message in ipairs(messages) do ---@type Message @@ -256,5 +256,5 @@ function shared.Commander.Init() end end) - print("Heimdall - Commander loaded") + print("[Heimdall] Commander module loaded") end diff --git a/Modules/DeathReporter.lua b/Modules/DeathReporter.lua index bfa98ef..3a77854 100644 --- a/Modules/DeathReporter.lua +++ b/Modules/DeathReporter.lua @@ -16,106 +16,108 @@ function shared.DeathReporter.Init() ---@param spellName string local function RegisterDeath(source, destination, spellName) if Heimdall_Data.config.deathReporter.debug then - print(string.format("%s: RegisterDeath", ModuleName)) - shared.dumpTable(Heimdall_Data.config.deathReporter) + print(string.format("[%s] Processing death event - Source: %s, Target: %s, Spell: %s", + ModuleName, source, destination, spellName)) end - if not Heimdall_Data.config.deathReporter.enabled then return end - if recentDeaths[destination] - and GetTime() - recentDeaths[destination] < Heimdall_Data.config.deathReporter.throttle then + + if not Heimdall_Data.config.deathReporter.enabled then if Heimdall_Data.config.deathReporter.debug then - print(string.format("%s: Throttled death report for %s", ModuleName, destination)) + print(string.format("[%s] Module disabled, ignoring death event", ModuleName)) + end + return + end + + if recentDeaths[destination] and GetTime() - recentDeaths[destination] < Heimdall_Data.config.deathReporter.throttle then + if Heimdall_Data.config.deathReporter.debug then + local timeLeft = Heimdall_Data.config.deathReporter.throttle - (GetTime() - recentDeaths[destination]) + print(string.format("[%s] Death report throttled for %s (%.1f seconds remaining)", + ModuleName, destination, timeLeft)) end return end - if recentDuels[destination] - and GetTime() - recentDuels[destination] < Heimdall_Data.config.deathReporter.duelThrottle then + if recentDuels[destination] and GetTime() - recentDuels[destination] < Heimdall_Data.config.deathReporter.duelThrottle then if Heimdall_Data.config.deathReporter.debug then - print(string.format("Cancelling death reports for %s and %s because of recent duel", source, destination)) + print(string.format("[%s] Ignoring death report - Recent duel detected for target: %s", ModuleName, destination)) end return end - if recentDuels[source] - and GetTime() - recentDuels[source] < Heimdall_Data.config.deathReporter.duelThrottle then + + if recentDuels[source] and GetTime() - recentDuels[source] < Heimdall_Data.config.deathReporter.duelThrottle then if Heimdall_Data.config.deathReporter.debug then - print(string.format("Cancelling death reports for %s and %s because of recent duel", source, destination)) + print(string.format("[%s] Ignoring death report - Recent duel detected for source: %s", ModuleName, source)) end return end + if Heimdall_Data.config.deathReporter.debug then + print(string.format("[%s] Recording death for %s", ModuleName, destination)) + end recentDeaths[destination] = GetTime() + C_Timer.NewTimer(3, function() - if recentDuels[destination] - and GetTime() - recentDuels[destination] < Heimdall_Data.config.deathReporter.duelThrottle then + if recentDuels[destination] and GetTime() - recentDuels[destination] < Heimdall_Data.config.deathReporter.duelThrottle then if Heimdall_Data.config.deathReporter.debug then - print(string.format("Cancelling death reports for %s and %s because of recent duel", source, - destination)) + print(string.format("[%s] Cancelling delayed death report - Recent duel detected for: %s", ModuleName, destination)) end return end - if recentDuels[source] - and GetTime() - recentDuels[source] < Heimdall_Data.config.deathReporter.duelThrottle then + + if recentDuels[source] and GetTime() - recentDuels[source] < Heimdall_Data.config.deathReporter.duelThrottle then if Heimdall_Data.config.deathReporter.debug then - print(string.format("Cancelling death reports for %s and %s because of recent duel", source, - destination)) + print(string.format("[%s] Cancelling delayed death report - Recent duel detected for: %s", ModuleName, source)) end return end - local zone = Heimdall_Data.config.deathReporter.zoneOverride - if zone == nil or zone == "" then - zone = string.format("%s (%s)", GetZoneText(), GetSubZoneText()) - end if Heimdall_Data.config.deathReporter.debug then - print(string.format("%s: zone = %s", ModuleName, zone)) + print(string.format("[%s] Sending death report - %s killed %s with %s", + ModuleName, source, destination, spellName)) end - - local text = string.format("%s killed %s with %s in %s", - tostring(source), - tostring(destination), - tostring(spellName), - tostring(zone)) - if Heimdall_Data.config.deathReporter.debug then - print(string.format("%s: text = %s", ModuleName, text)) - end - + ---@type Message local msg = { channel = "CHANNEL", - data = Heimdall_Data.config.deathReporter.notifyChannel, - message = text, + data = Heimdall_Data.config.deathReporter.masterChannel, + message = string.format("%s killed %s with %s", source, destination, spellName) } if Heimdall_Data.config.deathReporter.debug then - print(string.format("%s: msg =", ModuleName)) - shared.dumpTable(msg) + print(string.format("[%s] Adding message to queue: %s", ModuleName, msg.message)) end table.insert(shared.messenger.queue, msg) - - if Heimdall_Data.config.deathReporter.doWhisper then - for _, name in pairs(Heimdall_Data.config.whisperNotify) do - local msg = { - channel = "WHISPER", - data = name, - message = text, - } - table.insert(shared.messenger.queue, msg) - end - end end) end local cleuFrame = CreateFrame("Frame") cleuFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") cleuFrame:SetScript("OnEvent", function(self, event, ...) + -- if Heimdall_Data.config.deathReporter.debug then + -- print(string.format("[%s] Received combat log event", ModuleName)) + -- end if not Heimdall_Data.config.deathReporter.enabled then return end local overkill, err = CLEUParser.GetOverkill(...) if not err and overkill > 0 then local source, err = CLEUParser.GetSourceName(...) - if err then source = "unknown" end + if err then + source = "unknown" + if Heimdall_Data.config.deathReporter.debug then + print(string.format("[%s] Error getting source name", ModuleName)) + end + end local destination, err = CLEUParser.GetDestName(...) - if err then destination = "unknown" end + if err then + destination = "unknown" + if Heimdall_Data.config.deathReporter.debug then + print(string.format("[%s] Error getting destination name", ModuleName)) + end + end local spellName, err = CLEUParser.GetSpellName(...) - if err then spellName = "unknown" end + if err then + spellName = "unknown" + if Heimdall_Data.config.deathReporter.debug then + print(string.format("[%s] Error getting spell name", ModuleName)) + end + end local sourceGUID, err = CLEUParser.GetSourceGUID(...) if err or not string.match(sourceGUID, "Player") then return end local destinationGUID, err = CLEUParser.GetDestGUID(...) @@ -127,18 +129,66 @@ function shared.DeathReporter.Init() local systemMessageFrame = CreateFrame("Frame") systemMessageFrame:RegisterEvent("CHAT_MSG_SYSTEM") systemMessageFrame:SetScript("OnEvent", function(self, event, msg) - if not Heimdall_Data.config.deathReporter.enabled then return end - local source, destination = string.match(msg, "([^ ]+) has defeated ([^ ]+) in a duel") - if not source or not destination then return end - source = string.match(source, "([^-]+)") - destination = string.match(destination, "([^-]+)") - if source and destination then - print(string.format("Detected duel between %s and %s", source, destination)) - local now = GetTime() - recentDuels[source] = now - recentDuels[destination] = now + if Heimdall_Data.config.deathReporter.debug then + print(string.format("[%s] Received system message: %s", ModuleName, msg)) end + + if not Heimdall_Data.config.deathReporter.enabled then + if Heimdall_Data.config.deathReporter.debug then + print(string.format("[%s] Module disabled, ignoring event", ModuleName)) + end + return + end + + if event == "DUEL_REQUESTED" then + local opponent = ... + if Heimdall_Data.config.deathReporter.debug then + print(string.format("[%s] Duel requested with: %s", ModuleName, opponent)) + end + recentDuels[opponent] = GetTime() + recentDuels[UnitName("player")] = GetTime() + return + end + + if event == "DUEL_FINISHED" or event == "DUEL_CANCELLED" then + if Heimdall_Data.config.deathReporter.debug then + print(string.format("[%s] Duel ended: %s", ModuleName, event)) + end + return + end + + local subevent = select(2, ...) + if subevent ~= "PARTY_KILL" and subevent ~= "UNIT_DIED" then return end + + local source, err = CLEUParser.GetSourceName(...) + if err then + if Heimdall_Data.config.deathReporter.debug then + print(string.format("[%s] Error getting source: %s", ModuleName, err)) + end + return + end + + local destination, err = CLEUParser.GetDestName(...) + if err then + if Heimdall_Data.config.deathReporter.debug then + print(string.format("[%s] Error getting destination: %s", ModuleName, err)) + end + return + end + + if Heimdall_Data.config.deathReporter.debug then + print(string.format("[%s] Death event detected - Source: %s, Target: %s", ModuleName, source, destination)) + end + + local spellId = CLEUParser.GetSpellId(...) + local spellName = GetSpellInfo(spellId) or "Unknown Spell" + + RegisterDeath(source, destination, spellName) end) - print("Heimdall - DeathReporter loaded") + if Heimdall_Data.config.deathReporter.debug then + print(string.format("[%s] Module initialized with throttle: %.1fs, duel throttle: %.1fs", + ModuleName, Heimdall_Data.config.deathReporter.throttle, Heimdall_Data.config.deathReporter.duelThrottle)) + end + print("[Heimdall] DeathReporter loaded") end diff --git a/Modules/Dueler.lua b/Modules/Dueler.lua index 3add508..7f9e8df 100644 --- a/Modules/Dueler.lua +++ b/Modules/Dueler.lua @@ -10,29 +10,41 @@ function shared.Dueler.Init() frame:RegisterEvent("DUEL_REQUESTED") frame:SetScript("OnEvent", function(self, event, sender) if Heimdall_Data.config.dueler.debug then - print(string.format("%s: OnEvent", ModuleName)) - shared.dumpTable(Heimdall_Data.config.dueler) + print(string.format("[%s] Duel request received from: %s", ModuleName, sender)) end - if not Heimdall_Data.config.dueler.enabled then return end + if not Heimdall_Data.config.dueler.enabled then + if Heimdall_Data.config.dueler.debug then + print(string.format("[%s] Module disabled, ignoring duel request", ModuleName)) + end + return + end + if Heimdall_Data.config.dueler.debug then - print(string.format("%s: sender = %s", ModuleName, sender)) - shared.dumpTable(Heimdall_Data.config.agents) + print(string.format("[%s] Checking if sender '%s' is in agents list", ModuleName, sender)) end + local allow = Heimdall_Data.config.agents[sender] if allow then if Heimdall_Data.config.dueler.debug then - print(string.format("%s: Accepting duel from %s", ModuleName, sender)) + print(string.format("[%s] Accepting duel from trusted agent: %s", ModuleName, sender)) end AcceptDuel() else if Heimdall_Data.config.dueler.autoDecline then if Heimdall_Data.config.dueler.debug then - print(string.format("%s: Auto declining duel from %s", ModuleName, sender)) + print(string.format("[%s] Auto-declining duel from untrusted sender: %s", ModuleName, sender)) end CancelDuel() + else + if Heimdall_Data.config.dueler.debug then + print(string.format("[%s] Leaving duel request from %s for manual response", ModuleName, sender)) + end end end end) - print("Heimdall - Dueler loaded") + if Heimdall_Data.config.dueler.debug then + print(string.format("[%s] Module initialized with auto-decline: %s", ModuleName, tostring(Heimdall_Data.config.dueler.autoDecline))) + end + print("[Heimdall] Dueler loaded") end diff --git a/Modules/Echoer.lua b/Modules/Echoer.lua index 361d737..4c28f15 100644 --- a/Modules/Echoer.lua +++ b/Modules/Echoer.lua @@ -10,26 +10,45 @@ function shared.Echoer.Init() frame:RegisterEvent("CHAT_MSG_CHANNEL") frame:SetScript("OnEvent", function(self, event, msg, sender, ...) if Heimdall_Data.config.echoer.debug then - print(string.format("%s: OnEvent", ModuleName)) - shared.dumpTable(Heimdall_Data.config.echoer) + print(string.format("[%s] Channel message received from: %s", ModuleName, sender)) + end + + if not Heimdall_Data.config.echoer.enabled then + if Heimdall_Data.config.echoer.debug then + print(string.format("[%s] Module disabled, ignoring message", ModuleName)) + end + return end - if not Heimdall_Data.config.echoer.enabled then return end local channelId = select(6, ...) local _, channelname = GetChannelName(channelId) if Heimdall_Data.config.echoer.debug then - print(string.format("%s: channelname = %s", ModuleName, channelname)) + print(string.format("[%s] Processing message from channel: %s", ModuleName, channelname)) + end + + if channelname ~= Heimdall_Data.config.echoer.masterChannel then + if Heimdall_Data.config.echoer.debug then + print(string.format("[%s] Ignoring message from non-master channel", ModuleName)) + end + return end - if channelname ~= Heimdall_Data.config.echoer.masterChannel then return end if string.find(msg, "^" .. Heimdall_Data.config.echoer.prefix) then if Heimdall_Data.config.echoer.debug then - print(string.format("%s: msg = %s", ModuleName, msg)) + print(string.format("[%s] Found echo command in message: %s", ModuleName, msg)) end local msg = string.sub(msg, string.len(Heimdall_Data.config.echoer.prefix) + 1) + if Heimdall_Data.config.echoer.debug then + print(string.format("[%s] Echoing message: %s", ModuleName, msg)) + end SendChatMessage(msg, "SAY") + elseif Heimdall_Data.config.echoer.debug then + print(string.format("[%s] Message does not start with echo prefix", ModuleName)) end end) - print("Heimdall - Echoer loaded") + if Heimdall_Data.config.echoer.debug then + print(string.format("[%s] Module initialized", ModuleName)) + end + print("[Heimdall] Echoer loaded") end diff --git a/Modules/Emoter.lua b/Modules/Emoter.lua index f3c8920..41b3615 100644 --- a/Modules/Emoter.lua +++ b/Modules/Emoter.lua @@ -10,25 +10,45 @@ function shared.Emoter.Init() frame:RegisterEvent("CHAT_MSG_CHANNEL") frame:SetScript("OnEvent", function(self, event, msg, sender, ...) if Heimdall_Data.config.emoter.debug then - print(string.format("%s: OnEvent", ModuleName)) - shared.dumpTable(Heimdall_Data.config.emoter) + print(string.format("[%s] Channel message received from: %s", ModuleName, sender)) + end + + if not Heimdall_Data.config.emoter.enabled then + if Heimdall_Data.config.emoter.debug then + print(string.format("[%s] Module disabled, ignoring message", ModuleName)) + end + return end - if not Heimdall_Data.config.emoter.enabled then return end local channelId = select(6, ...) local _, channelname = GetChannelName(channelId) if Heimdall_Data.config.emoter.debug then - print(string.format("%s: channelname = %s", ModuleName, channelname)) + print(string.format("[%s] Processing message from channel: %s", ModuleName, channelname)) + end + + if channelname ~= Heimdall_Data.config.emoter.masterChannel then + if Heimdall_Data.config.emoter.debug then + print(string.format("[%s] Ignoring message from non-master channel", ModuleName)) + end + return end - if channelname ~= Heimdall_Data.config.emoter.masterChannel then return end if string.find(msg, "^" .. Heimdall_Data.config.emoter.prefix) then if Heimdall_Data.config.emoter.debug then - print(string.format("%s: msg = %s", ModuleName, msg)) + print(string.format("[%s] Found emote command in message: %s", ModuleName, msg)) end local emote = string.sub(msg, string.len(Heimdall_Data.config.emoter.prefix) + 1) + if Heimdall_Data.config.emoter.debug then + print(string.format("[%s] Performing emote: %s", ModuleName, emote)) + end DoEmote(emote) + elseif Heimdall_Data.config.emoter.debug then + print(string.format("[%s] Message does not start with emote prefix", ModuleName)) end end) - print("Heimdall - Emoter loaded") + + if Heimdall_Data.config.emoter.debug then + print(string.format("[%s] Module initialized", ModuleName)) + end + print("[Heimdall] Emoter loaded") end diff --git a/Modules/Inviter.lua b/Modules/Inviter.lua index 7b8f39b..0b3b425 100644 --- a/Modules/Inviter.lua +++ b/Modules/Inviter.lua @@ -11,40 +11,53 @@ function shared.Inviter.Init() local function FixGroup() if Heimdall_Data.config.inviter.debug then - print(string.format("%s: FixGroup", ModuleName)) - shared.dumpTable(Heimdall_Data.config.inviter) + print(string.format("[%s] Checking and fixing group configuration", ModuleName)) end + if not IsInRaid() then if Heimdall_Data.config.inviter.debug then - print(string.format("%s: Not in raid", ModuleName)) + print(string.format("[%s] Converting party to raid", ModuleName)) end ConvertToRaid() end + if Heimdall_Data.config.inviter.allAssist then if Heimdall_Data.config.inviter.debug then - print(string.format("%s: Setting everyone to assistant", ModuleName)) + print(string.format("[%s] Setting all members to assistant", ModuleName)) end SetEveryoneIsAssistant() end + if Heimdall_Data.config.inviter.agentsAssist then if Heimdall_Data.config.inviter.debug then - print(string.format("%s: Setting agents to assistant", ModuleName)) + 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)) end - --shared.dumpTable(Heimdall_Data.config.agents) + for name, _ in pairs(Heimdall_Data.config.agents) do - if UnitInParty(name) - and not UnitIsGroupLeader(name) - and not UnitIsRaidOfficer(name) then + if UnitInParty(name) and not UnitIsGroupLeader(name) and not UnitIsRaidOfficer(name) then if Heimdall_Data.config.inviter.debug then - print(string.format("%s: Promoting %s to assistant", ModuleName, name)) + print(string.format("[%s] Promoting agent to assistant: %s", ModuleName, name)) end PromoteToAssistant(name, 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)) + end end end end + + if Heimdall_Data.config.inviter.debug then + print(string.format("[%s] Group configuration update complete", ModuleName)) + end end - local framePool = {} ---@param name string ---Kicking people or othwerise people leaving will fuck up the buttons ---We should make them reactive to GROUP_ROSTER_UPDATE @@ -52,23 +65,23 @@ function shared.Inviter.Init() ---Since I'm the only one currently using this - I don't care where the buttons are local function OverlayKickButtonElvUI(name) if Heimdall_Data.config.inviter.debug then - print(string.format("%s: OverlayKickButtonElvUI", ModuleName)) + print(string.format("[%s] OverlayKickButtonElvUI", ModuleName)) shared.dumpTable(Heimdall_Data.config.inviter) end for group = 1, 8 do for player = 1, 5 do local button = _G[string.format("ElvUF_RaidGroup%dUnitButton%d", group, player)] if Heimdall_Data.config.inviter.debug then - print(string.format("%s: button = %s", ModuleName, button)) + print(string.format("[%s] button = %s", ModuleName, button)) end local unitName = button and button.unit and UnitName(button.unit) if Heimdall_Data.config.inviter.debug then - print(string.format("%s: unitName = %s", ModuleName, unitName)) + print(string.format("[%s] unitName = %s", ModuleName, unitName)) end if unitName == name then if Heimdall_Data.config.inviter.debug then - print(string.format("%s: unitName == name", ModuleName)) + print(string.format("[%s] unitName == name", ModuleName)) end local overlayButton = framePool[button.unit] or CreateFrame("Button", @@ -139,17 +152,23 @@ function shared.Inviter.Init() end Tick() - local inviterGroupFrame = CreateFrame("Frame") - inviterGroupFrame:RegisterEvent("GROUP_ROSTER_UPDATE") - inviterGroupFrame:SetScript("OnEvent", function(self, event, ...) + local groupRosterUpdateFrame = CreateFrame("Frame") + groupRosterUpdateFrame:RegisterEvent("GROUP_ROSTER_UPDATE") + groupRosterUpdateFrame:SetScript("OnEvent", function(self, event, ...) if Heimdall_Data.config.inviter.debug then - print(string.format("%s: OnEvent", ModuleName)) - shared.dumpTable(Heimdall_Data.config.inviter) - print(string.format("%s: event = %s", ModuleName, UnitIsGroupLeader("player"))) + print(string.format("[%s] Event received: %s", ModuleName, event)) end - if not Heimdall_Data.config.inviter.enabled then return end - if not UnitIsGroupLeader("player") then return end + if not Heimdall_Data.config.inviter.enabled then + if Heimdall_Data.config.inviter.debug then + print(string.format("[%s] Module disabled, ignoring event", ModuleName)) + end + return + end + + if Heimdall_Data.config.inviter.debug then + print(string.format("[%s] Group roster changed - Checking configuration", ModuleName)) + end if updateTimer then updateTimer:Cancel() end updateTimer = C_Timer.NewTimer(Heimdall_Data.config.inviter.throttle, FixGroup) end) @@ -157,21 +176,27 @@ function shared.Inviter.Init() local inviterChannelFrame = CreateFrame("Frame") inviterChannelFrame:RegisterEvent("CHAT_MSG_CHANNEL") inviterChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...) - if Heimdall_Data.config.inviter.debug then - print(string.format("%s: OnEvent", ModuleName)) - shared.dumpTable(Heimdall_Data.config.inviter) - end + -- if Heimdall_Data.config.inviter.debug then + -- print(string.format("[%s] Chat message received: %s", ModuleName, msg)) + -- shared.dumpTable(Heimdall_Data.config.inviter) + -- end if not Heimdall_Data.config.inviter.enabled then return end local channelId = select(6, ...) local _, channelname = GetChannelName(channelId) if channelname ~= Heimdall_Data.config.inviter.listeningChannel then return end if msg == Heimdall_Data.config.inviter.keyword then if Heimdall_Data.config.inviter.debug then - print(string.format("%s: Inviting %s", ModuleName, sender)) + print(string.format("[%s] Inviting %s", ModuleName, sender)) end InviteUnit(sender) end end) - print("Heimdall - Inviter loaded") + if Heimdall_Data.config.inviter.debug then + print(string.format("[%s] Module initialized - All assist: %s, Agents assist: %s", + ModuleName, + tostring(Heimdall_Data.config.inviter.allAssist), + tostring(Heimdall_Data.config.inviter.agentsAssist))) + end + print("[Heimdall] Inviter loaded") end diff --git a/Modules/Macroer.lua b/Modules/Macroer.lua index c1f627b..4e3436f 100644 --- a/Modules/Macroer.lua +++ b/Modules/Macroer.lua @@ -14,19 +14,18 @@ function shared.Macroer.Init() local function FindOrCreateMacro(macroName) if Heimdall_Data.config.macroer.debug then - print(string.format("%s: FindOrCreateMacro", ModuleName)) - shared.dumpTable(Heimdall_Data.config.macroer) + print(string.format("[%s] Finding or creating macro: %s", ModuleName, macroName)) end local idx = GetMacroIndexByName(macroName) if idx == 0 then if Heimdall_Data.config.macroer.debug then - print(string.format("%s: Creating macro", ModuleName)) + print(string.format("[%s] Creating new macro: %s", ModuleName, macroName)) end CreateMacro(macroName, "INV_Misc_QuestionMark", "") end idx = GetMacroIndexByName(macroName) if Heimdall_Data.config.macroer.debug then - print(string.format("%s: idx = %s", ModuleName, idx)) + print(string.format("[%s] Macro index: %d", ModuleName, idx)) end return idx end @@ -34,15 +33,21 @@ function shared.Macroer.Init() ---@param stinkies table local function FixMacro(stinkies) if Heimdall_Data.config.macroer.debug then - print(string.format("%s: FixMacro", ModuleName)) - shared.dumpTable(Heimdall_Data.config.macroer) + print(string.format("[%s] Fixing macro with %d stinkies", ModuleName, #stinkies)) end - if not Heimdall_Data.config.macroer.enabled then return end - if InCombatLockdown() then return end - if Heimdall_Data.config.macroer.debug then - print(string.format("%s: InCombatLockdown", ModuleName)) - shared.dumpTable(Heimdall_Data.config.macroer) + if not Heimdall_Data.config.macroer.enabled then + if Heimdall_Data.config.macroer.debug then + print(string.format("[%s] Module disabled, skipping macro update", ModuleName)) + end + return end + if InCombatLockdown() then + if Heimdall_Data.config.macroer.debug then + print(string.format("[%s] In combat, skipping macro update", ModuleName)) + end + return + end + local priorityMap = {} for priority, className in ipairs(Heimdall_Data.config.macroer.priority) do priorityMap[className] = priority @@ -56,6 +61,10 @@ function shared.Macroer.Init() end end + if Heimdall_Data.config.macroer.debug then + print(string.format("[%s] Processing %d non-agent stinkies", ModuleName, #sortedStinkies)) + end + table.sort(sortedStinkies, function(a, b) local aPriority = priorityMap[a.class] or minPriority local bPriority = priorityMap[b.class] or minPriority @@ -65,23 +74,30 @@ function shared.Macroer.Init() local lines = { "/targetenemy" } for _, stinky in pairs(sortedStinkies) do if stinky.seenAt > GetTime() - 600 then - print(string.format("Macroing %s", stinky.name)) + if Heimdall_Data.config.macroer.debug then + print(string.format("[%s] Adding target macro for: %s", ModuleName, stinky.name)) + end lines[#lines + 1] = string.format("/tar %s", stinky.name) end end local idx = FindOrCreateMacro("HeimdallTarget") local body = strjoin("\n", unpack(lines)) + if Heimdall_Data.config.macroer.debug then + print(string.format("[%s] Updating macro with %d lines", ModuleName, #lines)) + end EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body) end shared.stinkyTracker.stinkies:onChange(function(value) if Heimdall_Data.config.macroer.debug then - print(string.format("%s: onChange", ModuleName)) - shared.dumpTable(Heimdall_Data.config.macroer) + print(string.format("[%s] Stinkies changed, updating macro", ModuleName)) end FixMacro(value) end) - print("Heimdall - Macroer loaded") + if Heimdall_Data.config.macroer.debug then + print(string.format("[%s] Module initialized", ModuleName)) + end + print("[Heimdall] Macroer loaded") end diff --git a/Modules/Messenger.lua b/Modules/Messenger.lua index fd5bf3f..e9675e3 100644 --- a/Modules/Messenger.lua +++ b/Modules/Messenger.lua @@ -26,7 +26,7 @@ function shared.Messenger.Init() local channelId = GetChannelName(channelName) if channelId == 0 then if Heimdall_Data.config.messenger.debug then - print(string.format("%s: Channel %s not found, joining", ModuleName, channelName)) + print(string.format("[%s] Channel not found, joining: %s", ModuleName, channelName)) end if password then JoinPermanentChannel(channelName, password) @@ -36,7 +36,7 @@ function shared.Messenger.Init() end channelId = GetChannelName(channelName) if Heimdall_Data.config.messenger.debug then - print(string.format("%s: Channel %s found, id = %s", ModuleName, channelName, channelId)) + print(string.format("[%s] Channel found with ID: %s (%s)", ModuleName, channelId, channelName)) end return channelId end @@ -47,43 +47,81 @@ function shared.Messenger.Init() if not shared.messenger.ticker then local function DoMessage() if Heimdall_Data.config.messenger.debug then - print(string.format("%s: DoMessage", ModuleName)) - shared.dumpTable(Heimdall_Data.config.messenger) + print(string.format("[%s] Processing message queue", ModuleName)) + end + if not Heimdall_Data.config.messenger.enabled then + if Heimdall_Data.config.messenger.debug then + print(string.format("[%s] Module disabled, skipping message processing", ModuleName)) + end + return end - if not Heimdall_Data.config.messenger.enabled then return end ---@type Message local message = shared.messenger.queue[1] - if not message then return end - if not message.message or message.message == "" then return end - if not message.channel or message.channel == "" then return end + if not message then + if Heimdall_Data.config.messenger.debug then + print(string.format("[%s] Message queue empty", ModuleName)) + end + return + end + if not message.message or message.message == "" then + if Heimdall_Data.config.messenger.debug then + print(string.format("[%s] Invalid message: empty content", ModuleName)) + end + return + end + if not message.channel or message.channel == "" then + if Heimdall_Data.config.messenger.debug then + print(string.format("[%s] Invalid message: no channel specified", ModuleName)) + end + return + end if message.channel == "CHANNEL" and message.data and string.match(message.data, "%D") then if Heimdall_Data.config.messenger.debug then - print(string.format("%s: Channel presented as string: %s", ModuleName, message.data)) + print(string.format("[%s] Processing channel message: '%s' to '%s'", ModuleName, message.message, message.data)) end local channelId = GetChannelName(message.data) if channelId == 0 then if Heimdall_Data.config.messenger.debug then - print(string.format("%s: Channel not found, joining %s", ModuleName, message.data)) + print(string.format("[%s] Channel not found, attempting to join: %s", ModuleName, message.data)) end channelId = FindOrJoinChannel(message.data) - end - if Heimdall_Data.config.messenger.debug then - print(string.format("%s: Channel resolved to id %s", ModuleName, channelId)) + if Heimdall_Data.config.messenger.debug then + print(string.format("[%s] Channel join result - ID: %s", ModuleName, channelId)) + end end message.data = tostring(channelId) end table.remove(shared.messenger.queue, 1) - if not message.message or message.message == "" then return end - if not message.channel or message.channel == "" then return end - if not message.data or message.data == "" then return end + if not message.message or message.message == "" then + if Heimdall_Data.config.messenger.debug then + print(string.format("[%s] Skipping empty message", ModuleName)) + end + return + end + if not message.channel or message.channel == "" then + if Heimdall_Data.config.messenger.debug then + print(string.format("[%s] Skipping message with no channel", ModuleName)) + end + return + end + if not message.data or message.data == "" then + if Heimdall_Data.config.messenger.debug then + print(string.format("[%s] Skipping message with no data", ModuleName)) + end + return + end + + if Heimdall_Data.config.messenger.debug then + print(string.format("[%s] Sending message: '%s' to %s:%s", ModuleName, message.message, message.channel, message.data)) + end SendChatMessage(message.message, message.channel, nil, message.data) end local function Tick() if Heimdall_Data.config.messenger.debug then - print(string.format("%s: Tick", ModuleName)) - shared.dumpTable(Heimdall_Data.config.messenger) + local queueSize = #shared.messenger.queue + print(string.format("[%s] Queue check - Messages pending: %d", ModuleName, queueSize)) end DoMessage() shared.messenger.ticker = C_Timer.NewTimer(Heimdall_Data.config.messenger.interval, Tick, 1) @@ -91,14 +129,8 @@ function shared.Messenger.Init() Tick() end - --C_Timer.NewTicker(2, function() - -- print("Q") - -- table.insert(data.messenger.queue, { - -- channel = "CHANNEL", - -- data = "Foobar", - -- message = "TEST" - -- }) - --end) - - print("Heimdall - Messenger loaded") + if Heimdall_Data.config.messenger.debug then + print(string.format("[%s] Module initialized with interval: %s", ModuleName, Heimdall_Data.config.messenger.interval)) + end + print("[Heimdall] Messenger loaded") end diff --git a/Modules/Spotter.lua b/Modules/Spotter.lua index 90dc0bd..dc6b914 100644 --- a/Modules/Spotter.lua +++ b/Modules/Spotter.lua @@ -29,34 +29,46 @@ function shared.Spotter.Init() ---@return string? error local function ShouldNotify(unit, name, faction, hostile) if Heimdall_Data.config.spotter.debug then - print(string.format("%s: ShouldNotify", ModuleName)) - shared.dumpTable(Heimdall_Data.config.spotter) + print(string.format("[%s] Checking notification criteria for %s (%s)", ModuleName, name, faction)) end - if Heimdall_Data.config.agents[name] then return false end + + if Heimdall_Data.config.agents[name] then + if Heimdall_Data.config.spotter.debug then + print(string.format("[%s] Skipping agent: %s", ModuleName, name)) + end + return false + end + if Heimdall_Data.config.spotter.stinky then if Heimdall_Data.config.stinkies[name] then if Heimdall_Data.config.spotter.debug then - print(string.format("%s: Stinky found in config", ModuleName)) + print(string.format("[%s] Notifying - Found stinky: %s", ModuleName, name)) end return true end end + if Heimdall_Data.config.spotter.alliance then if faction == "Alliance" then if Heimdall_Data.config.spotter.debug then - print(string.format("%s: Alliance", ModuleName)) + print(string.format("[%s] Notifying - Found Alliance player: %s", ModuleName, name)) end return true end end + if Heimdall_Data.config.spotter.hostile then if hostile then if Heimdall_Data.config.spotter.debug then - print(string.format("%s: Hostile", ModuleName)) + print(string.format("[%s] Notifying - Found hostile player: %s", ModuleName, name)) end return true end end + + if Heimdall_Data.config.spotter.debug then + print(string.format("[%s] Using everyone setting: %s", ModuleName, tostring(Heimdall_Data.config.spotter.everyone))) + end return Heimdall_Data.config.spotter.everyone end @@ -64,22 +76,28 @@ function shared.Spotter.Init() ---@return string? local function NotifySpotted(unit) if Heimdall_Data.config.spotter.debug then - print(string.format("%s: NotifySpotted", ModuleName)) - shared.dumpTable(Heimdall_Data.config.spotter) + print(string.format("[%s] Processing spotted unit: %s", ModuleName, unit)) end + if not unit then return string.format("Could not find unit %s", tostring(unit)) end - if not UnitIsPlayer(unit) then return nil end - - if Heimdall_Data.config.spotter.debug then - print(string.format("%s: UnitIsPlayer", ModuleName)) + if not UnitIsPlayer(unit) then + if Heimdall_Data.config.spotter.debug then + print(string.format("[%s] Ignoring non-player unit: %s", ModuleName, unit)) + end + return nil end + local name = UnitName(unit) if not name then return string.format("Could not find name for unit %s", tostring(unit)) end + if Heimdall_Data.config.spotter.debug then + print(string.format("[%s] Processing player: %s", ModuleName, name)) + end local time = GetTime() if throttleTable[name] and time - throttleTable[name] < Heimdall_Data.config.spotter.throttleTime then if Heimdall_Data.config.spotter.debug then - print(string.format("%s: Throttled %s", ModuleName, tostring(name))) + local remainingTime = Heimdall_Data.config.spotter.throttleTime - (time - throttleTable[name]) + print(string.format("[%s] Player %s throttled for %.1f more seconds", ModuleName, name, remainingTime)) end return string.format("Throttled %s", tostring(name)) end @@ -90,36 +108,32 @@ function shared.Spotter.Init() local faction = shared.raceMap[race] if not faction then return string.format("Could not find faction for race %s", tostring(race)) end if Heimdall_Data.config.spotter.debug then - print(string.format("%s: Faction %s", ModuleName, tostring(faction))) + print(string.format("[%s] Player %s is %s (%s)", ModuleName, name, race, faction)) end local hostile = UnitCanAttack("player", unit) if Heimdall_Data.config.spotter.debug then - print(string.format("%s: Hostile %s", ModuleName, tostring(hostile))) + print(string.format("[%s] Player %s is %s", ModuleName, name, hostile and "hostile" or "friendly")) end + local doNotify = ShouldNotify(unit, name, faction, hostile) - if not doNotify then return string.format("Not notifying for %s", tostring(name)) end + if not doNotify then + if Heimdall_Data.config.spotter.debug then + print(string.format("[%s] Skipping notification for %s", ModuleName, name)) + end + return string.format("Not notifying for %s", tostring(name)) + end local hp = UnitHealth(unit) if not hp then return string.format("Could not find hp for unit %s", tostring(unit)) end - if Heimdall_Data.config.spotter.debug then - print(string.format("%s: HP %s", ModuleName, tostring(hp))) - end - - local maxHp = UnitHealthMax(unit) if not maxHp then return string.format("Could not find maxHp for unit %s", tostring(unit)) end if Heimdall_Data.config.spotter.debug then - print(string.format("%s: MaxHP %s", ModuleName, tostring(maxHp))) + print(string.format("[%s] Player %s health: %s/%s", ModuleName, name, FormatHP(hp), FormatHP(maxHp))) end - local class = UnitClass(unit) if not class then return string.format("Could not find class for unit %s", tostring(unit)) end - if Heimdall_Data.config.spotter.debug then - print(string.format("%s: Class %s", ModuleName, tostring(class))) - end - local location = Heimdall_Data.config.spotter.zoneOverride if not location or location == "" then @@ -128,17 +142,16 @@ function shared.Spotter.Init() local subzone = GetSubZoneText() if not subzone then subzone = "" end if Heimdall_Data.config.spotter.debug then - print(string.format("%s: Zone %s", ModuleName, tostring(zone))) - print(string.format("%s: Subzone %s", ModuleName, tostring(subzone))) + print(string.format("[%s] Player %s location: %s (%s)", ModuleName, name, zone, subzone)) end location = string.format("%s (%s)", zone, subzone) end local x, y = GetPlayerMapPosition("player") if Heimdall_Data.config.spotter.debug then - print(string.format("%s: X %s", ModuleName, tostring(x))) - print(string.format("%s: Y %s", ModuleName, tostring(y))) + print(string.format("[%s] Player %s coordinates: %.2f, %.2f", ModuleName, name, x * 100, y * 100)) end + local stinky = Heimdall_Data.config.stinkies[name] or false local text = string.format("I see (%s) %s/%s %s of race %s (%s) with health %s/%s at %s (%2.2f, %2.2f)", hostile and "Hostile" or "Friendly", @@ -151,10 +164,10 @@ function shared.Spotter.Init() FormatHP(maxHp), location, x * 100, y * 100) - if Heimdall_Data.config.spotter.debug then - print(string.format("%s: Text %s", ModuleName, tostring(text))) - end + if Heimdall_Data.config.spotter.debug then + print(string.format("[%s] Sending notification: %s", ModuleName, text)) + end ---@type Message local msg = { @@ -162,10 +175,6 @@ function shared.Spotter.Init() data = Heimdall_Data.config.spotter.notifyChannel, message = text } - if Heimdall_Data.config.spotter.debug then - print(string.format("%s: Inserting message into queue", ModuleName)) - shared.dumpTable(msg) - end table.insert(shared.messenger.queue, msg) end @@ -173,15 +182,31 @@ function shared.Spotter.Init() frame:RegisterEvent("NAME_PLATE_UNIT_ADDED") frame:RegisterEvent("UNIT_TARGET") frame:SetScript("OnEvent", function(self, event, unit) - if not Heimdall_Data.config.spotter.enabled then return end + if Heimdall_Data.config.spotter.debug then + print(string.format("[%s] Event received: %s for unit: %s", ModuleName, event, unit or "target")) + end + + if not Heimdall_Data.config.spotter.enabled then + if Heimdall_Data.config.spotter.debug then + print(string.format("[%s] Module disabled, ignoring event", ModuleName)) + end + return + end + if event == "UNIT_TARGET" then unit = "target" end + local err = NotifySpotted(unit) if err then - print(string.format("Error notifying %s: %s", tostring(unit), tostring(err))) + if Heimdall_Data.config.spotter.debug then + print(string.format("[%s] Error processing unit %s: %s", ModuleName, unit, err)) + end end end) - print("Heimdall - Spotter loaded") + if Heimdall_Data.config.spotter.debug then + print(string.format("[%s] Module initialized", ModuleName)) + end + print("[Heimdall] Spotter loaded") end diff --git a/Modules/StinkyTracker.lua b/Modules/StinkyTracker.lua index 430ec45..5746959 100644 --- a/Modules/StinkyTracker.lua +++ b/Modules/StinkyTracker.lua @@ -15,7 +15,7 @@ function shared.StinkyTracker.Init() ---@return table local function ParseWho(msg) if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Parsing who message: %s", ModuleName, msg)) + print(string.format("[%s] Parsing WHO message: '%s'", ModuleName, msg)) end local stinkies = {} for name, class in string.gmatch(msg, whoRegex) do @@ -26,7 +26,7 @@ function shared.StinkyTracker.Init() hostile = true } if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Found stinky in who: %s/%s", ModuleName, name, class)) + print(string.format("[%s] Found hostile player: %s (%s) at %s", ModuleName, name, class, date("%H:%M:%S", time()))) end end return stinkies @@ -37,13 +37,13 @@ function shared.StinkyTracker.Init() ---@return table local function ParseSee(msg) if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Parsing see message: %s", ModuleName, msg)) + print(string.format("[%s] Parsing SEE message: '%s'", ModuleName, msg)) end local stinkies = {} local aggression, name, class = string.match(msg, seeRegex) if not name or not class then if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: No valid stinky found in see message", ModuleName)) + print(string.format("[%s] Error: Invalid SEE message format", ModuleName)) end return stinkies end @@ -55,7 +55,7 @@ function shared.StinkyTracker.Init() } stinkies[name] = stinky if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Found stinky in see: %s/%s (%s)", ModuleName, name, class, aggression)) + print(string.format("[%s] Found stinky in SEE: %s (%s) - %s at %s", ModuleName, name, class, aggression, date("%H:%M:%S", time()))) end return stinkies end @@ -96,11 +96,11 @@ function shared.StinkyTracker.Init() frame:RegisterEvent("CHAT_MSG_CHANNEL") frame:SetScript("OnEvent", function(self, event, msg, sender, ...) if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Received event: %s", ModuleName, event)) + print(string.format("[%s] Event received: %s from %s", ModuleName, event, sender)) end if not Heimdall_Data.config.stinkyTracker.enabled then if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: StinkyTracker disabled", ModuleName)) + print(string.format("[%s] Module disabled, ignoring event", ModuleName)) end return end @@ -108,66 +108,87 @@ function shared.StinkyTracker.Init() local _, channelname = GetChannelName(channelId) if channelname ~= Heimdall_Data.config.stinkyTracker.masterChannel then if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Message not in master channel: %s", ModuleName, channelname)) + print(string.format("[%s] Ignoring message from non-master channel: %s", ModuleName, channelname)) end return end if string.find(msg, "^who:") then if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Processing who message", ModuleName)) + print(string.format("[%s] Processing WHO message from %s", ModuleName, sender)) end local whoStinkies = ParseWho(msg) + if Heimdall_Data.config.stinkyTracker.debug then + print(string.format("[%s] Found %d stinkies in WHO message", ModuleName, #whoStinkies)) + end for name, stinky in pairs(whoStinkies) do if stinky.hostile then shared.stinkyTracker.stinkies[name] = stinky if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Added stinky from who: %s", ModuleName, name)) + print(string.format("[%s] Added hostile stinky from WHO: %s (%s)", ModuleName, name, stinky.class)) end end end end if string.find(msg, "^I see") then if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Processing see message", ModuleName)) + print(string.format("[%s] Processing SEE message from %s", ModuleName, sender)) end local seeStinkies = ParseSee(msg) + if Heimdall_Data.config.stinkyTracker.debug then + print(string.format("[%s] Found %d stinkies in SEE message", ModuleName, #seeStinkies)) + end for name, stinky in pairs(seeStinkies) do if stinky.hostile then shared.stinkyTracker.stinkies[name] = stinky if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Added stinky from see: %s", ModuleName, name)) + print(string.format("[%s] Added hostile stinky from SEE: %s (%s)", ModuleName, name, stinky.class)) end end if not stinky.hostile then shared.stinkyTracker.stinkies[name] = nil if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Removed stinky from see: %s", ModuleName, name)) + print(string.format("[%s] Removed non-hostile stinky from SEE: %s", ModuleName, name)) end end end end if string.find(msg, " and guild ") then if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Processing arrived message", ModuleName)) + print(string.format("[%s] Processing ARRIVED message from %s", ModuleName, sender)) end local arrivedStinkies = ParseArrived(msg) + if Heimdall_Data.config.stinkyTracker.debug then + print(string.format("[%s] Found %d stinkies in ARRIVED message", ModuleName, #arrivedStinkies)) + end for name, stinky in pairs(arrivedStinkies) do shared.stinkyTracker.stinkies[name] = stinky if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Added stinky from arrived: %s", ModuleName, name)) + print(string.format("[%s] Added stinky from ARRIVED: %s (%s)", ModuleName, name, stinky.class)) end end end + + -- Log total stinky count after processing + if Heimdall_Data.config.stinkyTracker.debug then + local count = 0 + for _ in pairs(shared.stinkyTracker.stinkies) do count = count + 1 end + print(string.format("[%s] Current total stinkies tracked: %d", ModuleName, count)) + end + for name, stinky in pairs(shared.stinkyTracker.stinkies) do if Heimdall_Data.config.agents[name] then shared.stinkyTracker.stinkies[name] = nil if Heimdall_Data.config.stinkyTracker.debug then - print(string.format("%s: Removed agent stinky: %s", ModuleName, name)) + print(string.format("[%s] Removed agent from stinkies: %s", ModuleName, name)) end end end end) - print("Heimdall - StinkyTracker loaded") + if Heimdall_Data.config.stinkyTracker.debug then + print(string.format("[%s] Module initialized", ModuleName)) + end + print("[Heimdall] StinkyTracker loaded") end + diff --git a/Modules/Whoer.lua b/Modules/Whoer.lua index 68a55c3..5639cbc 100644 --- a/Modules/Whoer.lua +++ b/Modules/Whoer.lua @@ -1,6 +1,7 @@ local addonname, shared = ... ---@cast shared HeimdallShared ---@cast addonname string +local ModuleName = "Whoer" ---@diagnostic disable-next-line: missing-fields shared.Whoer = {} @@ -131,14 +132,36 @@ function shared.Whoer.Init() ---@param player Player ---@return string? local function Notify(player) - if not Heimdall_Data.config.who.enabled then return end - if not player then return string.format("Cannot notify for nil player %s", tostring(player)) end + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Processing notification for player: %s", ModuleName, player.name)) + end + + if not Heimdall_Data.config.who.enabled then + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Module disabled, skipping notification", ModuleName)) + end + return + end + + if not player then + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Error: Cannot notify for nil player", ModuleName)) + end + return string.format("Cannot notify for nil player %s", tostring(player)) + end + if not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then - return string.format("Not notifying for zone %s", - tostring(player.zone)) + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Skipping notification - Zone '%s' not in notify list", ModuleName, player.zone)) + end + return string.format("Not notifying for zone %s", tostring(player.zone)) end local text = player:NotifyMessage() + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Queuing channel notification: '%s'", ModuleName, text)) + end + ---@type Message local msg = { channel = "CHANNEL", @@ -148,6 +171,9 @@ function shared.Whoer.Init() table.insert(shared.messenger.queue, msg) if Heimdall_Data.config.who.doWhisper then + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Processing whisper notifications for %d recipients", ModuleName, #Heimdall_Data.config.whisperNotify)) + end for _, name in pairs(Heimdall_Data.config.whisperNotify) do ---@type Message local msg = { @@ -155,6 +181,9 @@ function shared.Whoer.Init() data = name, message = text } + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Queuing whisper to %s", ModuleName, name)) + end table.insert(shared.messenger.queue, msg) end end @@ -243,60 +272,98 @@ function shared.Whoer.Init() local frame = CreateFrame("Frame") frame:RegisterEvent("WHO_LIST_UPDATE") frame:SetScript("OnEvent", function(self, event, ...) - if not Heimdall_Data.config.who.enabled then return end + if Heimdall_Data.config.who.debug then + print(string.format("[%s] WHO list update received", ModuleName)) + end + + if not Heimdall_Data.config.who.enabled then + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Module disabled, ignoring WHO update", ModuleName)) + end + return + end + ---@type WHOQuery? local query = lastQuery if not query then - print("No query wtf?") + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Error: No active WHO query found", ModuleName)) + end return end - for i = 1, GetNumWhoResults() do - local name, guild, level, race, class, zone = GetWhoInfo(i) - local continue = false - --print(name, guild, level, race, class, zone) + local results = GetNumWhoResults() + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Processing %d WHO results for query: %s", ModuleName, results, query.query)) + end + for i = 1, results do + local name, guild, level, race, class, zone = GetWhoInfo(i) + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Processing result %d/%d: %s/%s/%s", ModuleName, i, results, name, class, zone)) + end + + local continue = false ---@type WHOFilter[] local filters = query.filters for _, filter in pairs(filters) do if not filter(name, guild, level, race, class, zone) then - -- Mega scuffed, yes... - -- But wow does not have gotos + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Player %s filtered out by WHO filter", ModuleName, name)) + end continue = true + break end end - if Heimdall_Data.config.who.ignored[name] then continue = true end - --print(continue) + + if Heimdall_Data.config.who.ignored[name] then + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Ignoring blacklisted player: %s", ModuleName, name)) + end + continue = true + end if not continue then local timestamp = date("%Y-%m-%dT%H:%M:%S") local player = HeimdallStinkies[name] if not player then + if Heimdall_Data.config.who.debug then + print(string.format("[%s] New player detected: %s (%s) in %s", ModuleName, name, class, zone)) + end + 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 + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Found existing data for %s - Last seen: %s, Count: %d", + ModuleName, name, existing.lastSeen or "never", existing.seenCount or 0)) + end 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 + if Heimdall_Data.config.who.debug then + print(string.format("[%s] First time seeing player: %s at %s", ModuleName, name, timestamp)) + end end local stinky = Heimdall_Data.config.stinkies[name] if stinky then + if Heimdall_Data.config.who.debug then + print(string.format("[%s] Player %s marked as stinky!", ModuleName, name)) + end player.stinky = true - --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))) + print(string.format("[%s] Error notifying for %s: %s", ModuleName, tostring(name), tostring(err))) end player.lastSeen = timestamp @@ -365,3 +432,4 @@ function shared.Whoer.Init() print("Heimdall - Whoer loaded") end + diff --git a/scratch.lua b/scratch.lua new file mode 100644 index 0000000..8d006c4 --- /dev/null +++ b/scratch.lua @@ -0,0 +1,8 @@ +print(123) +do + local test = "333" + print(test) + return nil + print("abv") +end +print(345)