Refactor CombatAlerter, Commander, Inviter, Macroer, Sniffer modules for improved structure and clarity
This commit is contained in:
@@ -7,9 +7,9 @@ local ModuleName = "CombatAlerter"
|
||||
---@field debug boolean
|
||||
---@field channels string[]
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.CombatAlerter = {}
|
||||
function shared.CombatAlerter.Init()
|
||||
---@class CombatAlerter
|
||||
shared.CombatAlerter = {
|
||||
Init = function()
|
||||
local alerted = {}
|
||||
local combatAlerterFrame = CreateFrame("Frame")
|
||||
combatAlerterFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
|
||||
@@ -137,4 +137,5 @@ function shared.CombatAlerter.Init()
|
||||
|
||||
if Heimdall_Data.config.combatAlerter.debug then print(string.format("[%s] Module initialized", ModuleName)) end
|
||||
print("[Heimdall] CombatAlerter loaded")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
@@ -39,9 +39,9 @@ local helpMessages = {
|
||||
},
|
||||
}
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.Commander = {}
|
||||
function shared.Commander.Init()
|
||||
---@class Commander
|
||||
shared.Commander = {
|
||||
Init = function()
|
||||
---@param text string
|
||||
---@param size number
|
||||
---@return string[]
|
||||
@@ -127,7 +127,9 @@ function shared.Commander.Init()
|
||||
local function CountClass(arr)
|
||||
local ret = {}
|
||||
for _, player in pairs(arr) do
|
||||
if shared.Whoer.ShouldNotifyForZone(player.zone) then ret[player.class] = (ret[player.class] or 0) + 1 end
|
||||
if shared.Whoer.ShouldNotifyForZone(player.zone) then
|
||||
ret[player.class] = (ret[player.class] or 0) + 1
|
||||
end
|
||||
end
|
||||
local text = {}
|
||||
for class, count in pairs(ret) do
|
||||
@@ -343,12 +345,19 @@ function shared.Commander.Init()
|
||||
for _, command in ipairs(commands) do
|
||||
local enabled = Heimdall_Data.config.commander.commands[command.keywordRe] == true or false
|
||||
if Heimdall_Data.config.commander.debug then
|
||||
print(string.format("[%s] Command match: %s = %s", ModuleName, command.keywordRe, tostring(enabled)))
|
||||
print(
|
||||
string.format("[%s] Command match: %s = %s", ModuleName, command.keywordRe, tostring(enabled))
|
||||
)
|
||||
end
|
||||
if
|
||||
enabled
|
||||
and (
|
||||
not command.commanderOnly
|
||||
-- if Heimdall_Data.config.commander.debug then print(string.format("[%s] Ignoring command, sender %s not commander %s", ModuleName, sender, Heimdall_Data.config.commander.commander)) end
|
||||
|
||||
|
||||
|
||||
|
||||
or (command.commanderOnly and sender == Heimdall_Data.config.commander.commander)
|
||||
)
|
||||
then
|
||||
@@ -357,7 +366,9 @@ function shared.Commander.Init()
|
||||
local messages = command.callback({ strsplit(",", msg) })
|
||||
if Heimdall_Data.config.commander.debug then
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
print(string.format("[%s] Messages to send: %s", ModuleName, strjoin(", ", unpack(messages))))
|
||||
print(
|
||||
string.format("[%s] Messages to send: %s", ModuleName, strjoin(", ", unpack(messages)))
|
||||
)
|
||||
end
|
||||
for _, message in ipairs(messages) do
|
||||
---@type Message
|
||||
@@ -379,4 +390,5 @@ function shared.Commander.Init()
|
||||
end)
|
||||
|
||||
print("[Heimdall] Commander module loaded")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
@@ -1,10 +1,24 @@
|
||||
local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
|
||||
---@class HeimdallInviterConfig
|
||||
---@field enabled boolean
|
||||
---@field debug boolean
|
||||
---@field channels string[]
|
||||
---@field keyword string
|
||||
---@field allAssist boolean
|
||||
---@field agentsAssist boolean
|
||||
---@field throttle number
|
||||
---@field kickOffline boolean
|
||||
---@field cleanupInterval number
|
||||
---@field afkThreshold number
|
||||
---@field listeningChannel table<string, boolean>
|
||||
|
||||
local ModuleName = "Inviter"
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.Inviter = {}
|
||||
function shared.Inviter.Init()
|
||||
---@class Inviter
|
||||
shared.Inviter = {
|
||||
Init = function()
|
||||
-- Fallback for old config
|
||||
if type(Heimdall_Data.config.inviter.listeningChannel) == "string" then
|
||||
Heimdall_Data.config.inviter.listeningChannel = {
|
||||
@@ -225,7 +239,9 @@ function shared.Inviter.Init()
|
||||
return
|
||||
end
|
||||
if msg == Heimdall_Data.config.inviter.keyword then
|
||||
if Heimdall_Data.config.inviter.debug then print(string.format("[%s] Inviting %s", ModuleName, sender)) end
|
||||
if Heimdall_Data.config.inviter.debug then
|
||||
print(string.format("[%s] Inviting %s", ModuleName, sender))
|
||||
end
|
||||
InviteUnit(sender)
|
||||
else
|
||||
if Heimdall_Data.config.inviter.debug then
|
||||
@@ -256,4 +272,5 @@ function shared.Inviter.Init()
|
||||
)
|
||||
end
|
||||
print("[Heimdall] Inviter loaded")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
@@ -1,10 +1,16 @@
|
||||
local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
|
||||
---@class HeimdallMacroerConfig
|
||||
---@field enabled boolean
|
||||
---@field debug boolean
|
||||
---@field priority string[]
|
||||
|
||||
local ModuleName = "Macroer"
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.Macroer = {}
|
||||
function shared.Macroer.Init()
|
||||
---@class Macroer
|
||||
shared.Macroer = {
|
||||
Init = function()
|
||||
local function FindOrCreateMacro(macroName)
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Finding or creating macro: %s", ModuleName, macroName))
|
||||
@@ -90,7 +96,7 @@ function shared.Macroer.Init()
|
||||
end
|
||||
FixMacro(stinkies)
|
||||
end)
|
||||
|
||||
if Heimdall_Data.config.macroer.debug then print(string.format("[%s] Module initialized", ModuleName)) end
|
||||
print("[Heimdall] Macroer loaded")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
@@ -2,9 +2,17 @@ local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
local ModuleName = "Sniffer"
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.Sniffer = {}
|
||||
function shared.Sniffer.Init()
|
||||
---@class HeimdallSnifferConfig
|
||||
---@field enabled boolean
|
||||
---@field debug boolean
|
||||
---@field channels string[]
|
||||
---@field throttle number -- throttleTime in the original code, matching config name now
|
||||
---@field zoneOverride string?
|
||||
---@field stinky boolean
|
||||
|
||||
---@class Sniffer
|
||||
shared.Sniffer = {
|
||||
Init = function()
|
||||
if Heimdall_Data.config.sniffer.debug then print(string.format("[%s] Module initializing", ModuleName)) end
|
||||
local smellThrottle = {}
|
||||
local SmellStinky = function(stinky)
|
||||
@@ -19,7 +27,7 @@ function shared.Sniffer.Init()
|
||||
end
|
||||
return
|
||||
end
|
||||
if smellThrottle[stinky] and GetTime() - smellThrottle[stinky] < Heimdall_Data.config.sniffer.throttleTime then
|
||||
if smellThrottle[stinky] and GetTime() - smellThrottle[stinky] < Heimdall_Data.config.sniffer.throttle then
|
||||
if Heimdall_Data.config.sniffer.debug then print(string.format("%s: Throttled", ModuleName)) end
|
||||
return
|
||||
end
|
||||
@@ -80,4 +88,5 @@ function shared.Sniffer.Init()
|
||||
end)
|
||||
if Heimdall_Data.config.sniffer.debug then print(string.format("[%s] Module initialized", ModuleName)) end
|
||||
print("[Heimdall] Sniffer loaded")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
Reference in New Issue
Block a user