92 lines
2.2 KiB
Lua
92 lines
2.2 KiB
Lua
local addonname, shared = ...
|
|
---@cast shared HeimdallShared
|
|
---@cast addonname string
|
|
|
|
---@diagnostic disable-next-line: missing-fields
|
|
shared.Macroer = {}
|
|
function shared.Macroer.Init()
|
|
---@class stinky
|
|
---@field name string
|
|
---@field class string
|
|
---@field seenAt number
|
|
|
|
---@type table<string, stinky>
|
|
local recentStinkies = {}
|
|
|
|
local function FindOrCreateMacro(macroName)
|
|
local idx = GetMacroIndexByName(macroName)
|
|
if idx == 0 then
|
|
CreateMacro(macroName, "INV_Misc_QuestionMark", "")
|
|
end
|
|
idx = GetMacroIndexByName(macroName)
|
|
return idx
|
|
end
|
|
|
|
---@param stinkies table<string, stinky>
|
|
local function FixMacro(stinkies)
|
|
local lines = {}
|
|
for name, info in pairs(stinkies) do
|
|
if info.seenAt > GetTime() - 600 then
|
|
print(string.format("Macroing %s", name))
|
|
lines[#lines + 1] = string.format("/tar %s", name)
|
|
end
|
|
end
|
|
|
|
local idx = FindOrCreateMacro("HeimdallTarget")
|
|
local body = strjoin("\n", unpack(lines))
|
|
EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body)
|
|
print("Updated macro")
|
|
end
|
|
|
|
local frame = CreateFrame("Frame")
|
|
frame:RegisterEvent("CHAT_MSG_CHANNEL")
|
|
frame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
|
if not Heimdall_Data.config.macroer.enabled then return end
|
|
local doUpdate = false
|
|
if string.find(msg, "^who:") then
|
|
for name, class in string.gmatch(msg, "([^ -/]+)-?%w*/(%w+)") do
|
|
recentStinkies[name] = {
|
|
name = name,
|
|
class = class,
|
|
seenAt = GetTime(),
|
|
}
|
|
doUpdate = true
|
|
end
|
|
end
|
|
local name, class = string.match(msg, "I see (Hostile) (.+)/(%w+) of")
|
|
if not name then
|
|
name, class = string.match(msg, "^(.+) of class (%w+)")
|
|
end
|
|
if name then
|
|
name = strtrim(name)
|
|
name = string.match(name, "^(.*)-?")
|
|
recentStinkies[name] = {
|
|
name = name,
|
|
class = class,
|
|
seenAt = GetTime(),
|
|
}
|
|
doUpdate = true
|
|
end
|
|
if doUpdate then
|
|
FixMacro(recentStinkies)
|
|
end
|
|
end)
|
|
|
|
hooksecurefunc("JumpOrAscendStart", function()
|
|
FixMacro({
|
|
["茶杯鸭跳芭蕾"] = {
|
|
name = "茶杯鸭跳芭蕾",
|
|
class = "Paladin",
|
|
seenAt = GetTime(),
|
|
},
|
|
["Asen"] = {
|
|
name = "Asen",
|
|
class = "Warlock",
|
|
seenAt = GetTime(),
|
|
},
|
|
})
|
|
end)
|
|
|
|
print("Heimdall - Macroer loaded")
|
|
end
|