diff --git a/AUDIT.md b/AUDIT.md index ef4920e..d650918 100644 --- a/AUDIT.md +++ b/AUDIT.md @@ -163,6 +163,12 @@ macro slots again for every button. #### Macro Tweaks — fixed / ClassicAPI-aware +Registers modern-style `/startattack` and `/stopattack` slash commands on +Vanilla and routes them to ClassicAPI's non-toggling `StartAttack()` and +`StopAttack()` functions. This avoids Vanilla treating `/startattack` as an +unknown slash command and, unlike `AttackTarget()`, repeated use cannot toggle +an active auto-attack off. + Container item lookup now prefers ClassicAPI item IDs/names. Numeric `/use` and `/equip` parsing is anchored so arbitrary item names that diff --git a/mods/macro-tweaks.lua b/mods/macro-tweaks.lua index 59af314..72cc0fa 100644 --- a/mods/macro-tweaks.lua +++ b/mods/macro-tweaks.lua @@ -4,7 +4,7 @@ local API = ShaguTweaks.API or {} local module = ShaguTweaks:register({ title = T["Macro Tweaks"], - description = T["Add /equip command to macros, remove #showtooltip from chat and hide macro commands from history."], + description = T["Add /equip, /use, /startattack and /stopattack to macros, remove #showtooltip from chat and hide macro commands from history."], expansions = { ["vanilla"] = true, ["tbc"] = false }, maintainer = "@shagu (GitHub)", category = T["Macro"], @@ -30,6 +30,8 @@ module.enable = function(self) if string.find(text, "^/run%s*") then return end if string.find(text, "^/script%s*") then return end if string.find(text, "^/cast%s*") then return end + if string.find(text, "^/startattack%s*") then return end + if string.find(text, "^/stopattack%s*") then return end end ChatFrameEditBox._AddHistoryLine(self, text) end @@ -67,6 +69,29 @@ module.enable = function(self) end end + -- ClassicAPI exposes the modern non-toggling StartAttack/StopAttack verbs. + -- Register the corresponding slash commands so Vanilla's macro parser can + -- use the familiar modern syntax without falling through to "unknown command". + _G.SLASH_STARTATTACK1 = "/startattack" + _G.SlashCmdList.STARTATTACK = function(msg) + if type(_G.StartAttack) ~= "function" then return end + + local unit + if msg then + _, _, unit = string.find(msg, "^%s*(.-)%s*$") + if unit == "" then unit = nil end + end + + _G.StartAttack(unit) + end + + _G.SLASH_STOPATTACK1 = "/stopattack" + _G.SlashCmdList.STOPATTACK = function() + if type(_G.StopAttack) == "function" then + _G.StopAttack() + end + end + _G.SLASH_EQUIP1 = "/equip" _G.SLASH_EQUIP2 = "/use" _G.SlashCmdList.EQUIP = function(msg)