Add debug options
Add debug buttons Add combatalerter debug
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
local addonname, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
---@cast addonname string
|
||||
local ModuleName = "StinkyTracker"
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.StinkyTracker = {}
|
||||
@@ -13,6 +14,9 @@ function shared.StinkyTracker.Init()
|
||||
---@param msg string
|
||||
---@return table<string, stinky>
|
||||
local function ParseWho(msg)
|
||||
if Heimdall_Data.config.stinkyTracker.debug then
|
||||
print(string.format("%s: Parsing who message: %s", ModuleName, msg))
|
||||
end
|
||||
local stinkies = {}
|
||||
for name, class in string.gmatch(msg, whoRegex) do
|
||||
stinkies[name] = {
|
||||
@@ -21,16 +25,26 @@ function shared.StinkyTracker.Init()
|
||||
seenAt = GetTime(),
|
||||
hostile = true
|
||||
}
|
||||
if Heimdall_Data.config.stinkyTracker.debug then
|
||||
print(string.format("%s: Found stinky in who: %s/%s", ModuleName, name, class))
|
||||
end
|
||||
end
|
||||
return stinkies
|
||||
end
|
||||
|
||||
local seeRegex = "I see %((%w+)%) ([^ -/]+)-?%w*/(%w+)"
|
||||
---@param msg string
|
||||
---@return table<string, stinky>
|
||||
local function ParseSee(msg)
|
||||
if Heimdall_Data.config.stinkyTracker.debug then
|
||||
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))
|
||||
end
|
||||
return stinkies
|
||||
end
|
||||
local stinky = {
|
||||
@@ -40,19 +54,29 @@ function shared.StinkyTracker.Init()
|
||||
hostile = aggression == "Hostile"
|
||||
}
|
||||
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))
|
||||
end
|
||||
return stinkies
|
||||
end
|
||||
|
||||
local arrivedRegex = "([^ -/]+)-?%w* of class (%w+)"
|
||||
local arrivedRegexAlt = "([^ -/]+)-?%w* %(!!!!%) of class (%w+)"
|
||||
---@param msg string
|
||||
---@return table<string, stinky>
|
||||
local function ParseArrived(msg)
|
||||
if Heimdall_Data.config.stinkyTracker.debug then
|
||||
print(string.format("%s: Parsing arrived message: %s", ModuleName, msg))
|
||||
end
|
||||
local stinkies = {}
|
||||
local name, class = string.match(msg, arrivedRegex)
|
||||
if not name or not class then
|
||||
name, class = string.match(msg, arrivedRegexAlt)
|
||||
end
|
||||
if not name or not class then
|
||||
if Heimdall_Data.config.stinkyTracker.debug then
|
||||
print(string.format("%s: No valid stinky found in arrived message", ModuleName))
|
||||
end
|
||||
return stinkies
|
||||
end
|
||||
local stinky = {
|
||||
@@ -62,45 +86,85 @@ function shared.StinkyTracker.Init()
|
||||
hostile = true
|
||||
}
|
||||
stinkies[name] = stinky
|
||||
if Heimdall_Data.config.stinkyTracker.debug then
|
||||
print(string.format("%s: Found stinky in arrived: %s/%s", ModuleName, name, class))
|
||||
end
|
||||
return stinkies
|
||||
end
|
||||
|
||||
local frame = CreateFrame("Frame")
|
||||
frame:RegisterEvent("CHAT_MSG_CHANNEL")
|
||||
frame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
||||
if not Heimdall_Data.config.stinkyTracker.enabled then return end
|
||||
if Heimdall_Data.config.stinkyTracker.debug then
|
||||
print(string.format("%s: Received event: %s", ModuleName, event))
|
||||
end
|
||||
if not Heimdall_Data.config.stinkyTracker.enabled then
|
||||
if Heimdall_Data.config.stinkyTracker.debug then
|
||||
print(string.format("%s: StinkyTracker disabled", ModuleName))
|
||||
end
|
||||
return
|
||||
end
|
||||
local channelId = select(6, ...)
|
||||
local _, channelname = GetChannelName(channelId)
|
||||
if channelname ~= Heimdall_Data.config.stinkyTracker.masterChannel then return end
|
||||
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))
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if string.find(msg, "^who:") then
|
||||
if Heimdall_Data.config.stinkyTracker.debug then
|
||||
print(string.format("%s: Processing who message", ModuleName))
|
||||
end
|
||||
local whoStinkies = ParseWho(msg)
|
||||
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))
|
||||
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))
|
||||
end
|
||||
local seeStinkies = ParseSee(msg)
|
||||
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))
|
||||
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))
|
||||
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))
|
||||
end
|
||||
local arrivedStinkies = ParseArrived(msg)
|
||||
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))
|
||||
end
|
||||
end
|
||||
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))
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user