Rework the tracking functionality from macroer to stinkytracker
This commit is contained in:
@@ -21,6 +21,7 @@ local function init()
|
||||
---@field classColors table<string, string>
|
||||
---@field messenger HeimdallMessengerData
|
||||
---@field who HeimdallWhoData
|
||||
---@field stinkyTracker HeimdallStinkyTrackerData
|
||||
---@field dumpTable fun(table: any, depth?: number): nil
|
||||
---@field utf8len fun(input: string): number
|
||||
---@field padString fun(input: string, targetLength: number, left?: boolean): string
|
||||
@@ -150,6 +151,9 @@ local function init()
|
||||
---@field whoTicker number?
|
||||
---@field ignored table<string, boolean>
|
||||
|
||||
---@class HeimdallStinkyTrackerData
|
||||
---@field stinkies ReactiveValue
|
||||
|
||||
shared.GetOrDefault = function(table, keys, default)
|
||||
local value = default
|
||||
if not table then return value end
|
||||
|
@@ -5,5 +5,100 @@ local addonname, shared = ...
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.StinkyTracker = {}
|
||||
function shared.StinkyTracker.Init()
|
||||
shared.stinkyTracker = {
|
||||
stinkies = ReactiveValue.new({})
|
||||
}
|
||||
|
||||
local whoRegex = "([^ -/]+)-?%w*/(%w+)"
|
||||
---@param msg string
|
||||
---@return table<string, stinky>
|
||||
local function ParseWho(msg)
|
||||
local stinkies = {}
|
||||
for name, class in string.gmatch(msg, whoRegex) do
|
||||
stinkies[name] = {
|
||||
name = name,
|
||||
class = class,
|
||||
seenAt = GetTime(),
|
||||
hostile = true
|
||||
}
|
||||
end
|
||||
return stinkies
|
||||
end
|
||||
local seeRegex = "I see %((%w+)%) ([^ -/]+)-?%w*/(%w+)"
|
||||
---@param msg string
|
||||
---@return table<string, stinky>
|
||||
local function ParseSee(msg)
|
||||
local stinkies = {}
|
||||
local aggression, name, class = string.match(msg, seeRegex)
|
||||
if not name or not class then
|
||||
return stinkies
|
||||
end
|
||||
local stinky = {
|
||||
name = name,
|
||||
class = class,
|
||||
seenAt = GetTime(),
|
||||
hostile = aggression == "Hostile"
|
||||
}
|
||||
stinkies[name] = stinky
|
||||
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)
|
||||
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
|
||||
return stinkies
|
||||
end
|
||||
local stinky = {
|
||||
name = name,
|
||||
class = class,
|
||||
seenAt = GetTime(),
|
||||
hostile = true
|
||||
}
|
||||
stinkies[name] = stinky
|
||||
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
|
||||
local channelId = select(6, ...)
|
||||
local _, channelname = GetChannelName(channelId)
|
||||
if channelname ~= Heimdall_Data.config.stinkyTracker.masterChannel then return end
|
||||
|
||||
if string.find(msg, "^who:") then
|
||||
local whoStinkies = ParseWho(msg)
|
||||
for name, stinky in pairs(whoStinkies) do
|
||||
if stinky.hostile then
|
||||
shared.stinkyTracker.stinkies[name] = stinky
|
||||
end
|
||||
end
|
||||
end
|
||||
if string.find(msg, "^I see") then
|
||||
local seeStinkies = ParseSee(msg)
|
||||
for name, stinky in pairs(seeStinkies) do
|
||||
if stinky.hostile then
|
||||
shared.stinkyTracker.stinkies[name] = stinky
|
||||
end
|
||||
if not stinky.hostile then
|
||||
shared.stinkyTracker.stinkies[name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
if string.find(msg, " and guild ") then
|
||||
local arrivedStinkies = ParseArrived(msg)
|
||||
for name, stinky in pairs(arrivedStinkies) do
|
||||
shared.stinkyTracker.stinkies[name] = stinky
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
print("Heimdall - StinkyTracker loaded")
|
||||
end
|
||||
|
Reference in New Issue
Block a user