Files
wow-Heimdall/Modules/Macroer.lua

50 lines
1.4 KiB
Lua

local addonname, shared = ...
---@cast shared HeimdallShared
---@cast addonname string
---@diagnostic disable-next-line: missing-fields
shared.Macroer = {}
function shared.Macroer.Init()
local function FindOrCreateMacro(macroName)
local idx = GetMacroIndexByName(macroName)
if idx == 0 then
CreateMacro(macroName, "INV_Misc_QuestionMark", "")
end
idx = GetMacroIndexByName(macroName)
return idx
end
---@type table<string, number>
local recentStinkies = {}
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 stinky = string.match(msg, "I see (Hostile) (.*) of")
if not stinky then
stinky = string.match(msg, "^(.*) of class")
end
if stinky then
stinky = strtrim(stinky)
stinky = string.match(stinky, "^(.*)-?")
recentStinkies[stinky] = GetTime()
end
end)
hooksecurefunc("JumpOrAscendStart", function()
local idx = FindOrCreateMacro("HeimdallTarget")
local stinkies = {}
for stinky, time in pairs(recentStinkies) do
if time > GetTime() - 10 then
stinkies[#stinkies + 1] = string.format("/tar %s", stinky)
end
end
local body = strjoin("\n", unpack(stinkies))
EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body)
print("Jumped")
end)
print("Heimdall - Macroer loaded")
end