Files
wow-Heimdall/Modules/Sniffer.lua
PhatPhuckDave 30068a5b11 Shorten every instance of "CHANNEL" to "C" and whisper too
To save a little space in messages, it's getting very cramped
2025-01-24 20:35:49 +01:00

95 lines
3.1 KiB
Lua

local addonname, shared = ...
---@cast shared HeimdallShared
---@cast addonname string
local ModuleName = "Sniffer"
---@diagnostic disable-next-line: missing-fields
shared.Sniffer = {}
function shared.Sniffer.Init()
if Heimdall_Data.config.sniffer.debug then
print(string.format("[%s] Module initializing", ModuleName))
end
local smellThrottle = {}
local SmellStinky = function(stinky)
if Heimdall_Data.config.sniffer.debug then
print(string.format("%s: SmellStinky", ModuleName))
shared.dumpTable(Heimdall_Data.config.sniffer)
end
if not Heimdall_Data.config.sniffer.enabled then return end
if Heimdall_Data.config.sniffer.stinky and
not shared.IsStinky(stinky) then
if Heimdall_Data.config.sniffer.debug then
print(string.format("%s: Stinky not found in config", ModuleName))
end
return
end
if smellThrottle[stinky] and GetTime() - smellThrottle[stinky] < Heimdall_Data.config.sniffer.throttleTime then
if Heimdall_Data.config.sniffer.debug then
print(string.format("%s: Throttled", ModuleName))
end
return
end
smellThrottle[stinky] = GetTime()
local msg = {
channel = "C",
data = Heimdall_Data.config.deathReporter.notifyChannel,
message = string.format(shared.L.en.snifferStinky, stinky),
}
if Heimdall_Data.config.sniffer.debug then
print(string.format("%s: Inserting message into queue", ModuleName))
shared.dumpTable(msg)
end
table.insert(shared.messenger.queue, msg)
if Heimdall_Data.config.echoToRussian then
-- Russian message
local ruMsg = {
channel = "C",
data = Heimdall_Data.config.deathReporter.notifyChannel .. "ru",
message = string.format(shared.L.ru.snifferStinky, stinky),
}
table.insert(shared.messenger.queue, ruMsg)
end
end
local cleuFrame = CreateFrame("Frame")
cleuFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
cleuFrame:SetScript("OnEvent", function(self, event, ...)
if Heimdall_Data.config.sniffer.debug then
print(string.format("[%s] Received event: %s", ModuleName, event))
end
if not Heimdall_Data.config.sniffer.enabled then
if Heimdall_Data.config.sniffer.debug then
print(string.format("[%s] Module disabled, ignoring event", ModuleName))
end
return
end
local source, err = CLEUParser.GetSourceName(...)
if Heimdall_Data.config.sniffer.debug then
print(string.format("[%s] Processing source: %s", ModuleName, source))
end
if err then
if Heimdall_Data.config.sniffer.debug then
print(string.format("[%s] Error parsing source: %s", ModuleName, err))
end
return
end
SmellStinky(source)
local destination, err = CLEUParser.GetDestName(...)
if Heimdall_Data.config.sniffer.debug then
print(string.format("[%s] Processing destination: %s", ModuleName, destination))
end
if err then
if Heimdall_Data.config.sniffer.debug then
print(string.format("[%s] Error parsing destination: %s", ModuleName, err))
end
return
end
SmellStinky(destination)
end)
if Heimdall_Data.config.sniffer.debug then
print(string.format("[%s] Module initialized", ModuleName))
end
print("[Heimdall] Sniffer loaded")
end