Files
wow_dechickenator/Dechickenator.lua

78 lines
2.8 KiB
Lua

local addonname, shared = ...
---@cast addonname string
---@class shared
---@field timer number?
shared = { timer = nil }
---@class DechickenatorData
---@field blacklistedBuffs table<string, boolean>
if not Dechickenator_Data then Dechickenator_Data = {} end
if not Dechickenator_Data.blacklistedBuffs then Dechickenator_Data.blacklistedBuffs = {} end
if not Dechickenator_Data.message then Dechickenator_Data.message = "Индивидуум %s хочет поделиться своим истинным обликом" end
local function init()
local function RemoveBuff(buff)
if UnitAffectingCombat("player") then return end
CancelUnitBuff("player", buff)
end
local function RemoveBuffs()
if UnitAffectingCombat("player") then return end
for buff, enabled in pairs(Dechickenator_Data.blacklistedBuffs) do
if enabled then
RemoveBuff(buff)
end
end
end
if not shared.timer then
shared.timer = C_Timer.NewTicker(1, function()
RemoveBuffs()
end)
end
local cleuFrame = CreateFrame("Frame")
cleuFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
cleuFrame:SetScript("OnEvent", function(self, event, ...)
local subevent = CLEUParser.GetSubevent(...)
if subevent == "SPELL_AURA_APPLIED" or subevent == "SPELL_AURA_REFRESH" then
local target = CLEUParser.GetDestName(...)
if target ~= UnitName("player") then return end
local spellName = CLEUParser.GetSpellName(...)
if not Dechickenator_Data.blacklistedBuffs[spellName] then return end
local source = CLEUParser.GetSourceName(...)
local msg = string.format(Dechickenator_Data.message, tostring(source))
RemoveBuff(spellName)
SendChatMessage(msg, "EMOTE")
DoEmote("spit", source)
end
end)
print("Dechickenator loaded!")
end
local loadedFrame = CreateFrame("Frame")
loadedFrame:RegisterEvent("ADDON_LOADED")
loadedFrame:SetScript("OnEvent", function(self, event, addonName)
if addonName == addonname then
init()
end
end)
SlashCmdList["DECHICKENATOR_TOGGLE_BLACKLISTED_BUFF"] = function(input)
print("Toggling blacklisted buff: " .. tostring(input))
if Dechickenator_Data.blacklistedBuffs[input] then
Dechickenator_Data.blacklistedBuffs[input] = nil
else
Dechickenator_Data.blacklistedBuffs[input] = true
end
print(Dechickenator_Data.blacklistedBuffs[input])
end
SLASH_DECHICKENATOR_TOGGLE_BLACKLISTED_BUFF1 = "/dechicken"
SlashCmdList["DECHICKENATOR_SET_MESSAGE"] = function(input)
print("Setting message: " .. tostring(input))
Dechickenator_Data.message = input
print(Dechickenator_Data.message)
end
SLASH_DECHICKENATOR_SET_MESSAGE1 = "/dechicken_message"