Implement deathreporter
Again, from weakaura
This commit is contained in:
@@ -1,8 +1,68 @@
|
||||
|
||||
local addonname, data = ...
|
||||
---@cast data HeimdallData
|
||||
---@cast addonname string
|
||||
|
||||
data.DeathReporter = {}
|
||||
function data.DeathReporter.Init()
|
||||
if not data.config.deathReporter.enabled then return end
|
||||
---@type table<string, number>
|
||||
local recentDeaths = {}
|
||||
---@type table<string, number>
|
||||
local notifyTimers = {}
|
||||
|
||||
---@param source string
|
||||
---@param destination string
|
||||
---@param spellName string
|
||||
---@param overkill number
|
||||
local function RegisterDeath(source, destination, spellName, overkill)
|
||||
if recentDeaths[destination]
|
||||
and GetTime() - recentDeaths[destination] < data.config.deathReporter.throttle then
|
||||
return
|
||||
end
|
||||
recentDeaths[destination] = GetTime()
|
||||
local timer = C_Timer.After(1, function()
|
||||
local text = string.format("%s killed %s with %s (%d)",
|
||||
tostring(source),
|
||||
tostring(destination),
|
||||
tostring(spellName),
|
||||
tostring(overkill))
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "CHANNEL",
|
||||
data = data.config.deathReporter.notifyChannel,
|
||||
message = text,
|
||||
}
|
||||
table.insert(data.messenger.queue, msg)
|
||||
|
||||
if data.config.deathReporter.doWhisper then
|
||||
for _, name in pairs(data.config.whisperNotify) do
|
||||
local msg = {
|
||||
channel = "WHISPER",
|
||||
data = name,
|
||||
message = text,
|
||||
}
|
||||
table.insert(data.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local cleuFrame = CreateFrame("Frame")
|
||||
cleuFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
|
||||
cleuFrame:SetScript("OnEvent", function(self, event, ...)
|
||||
local overkill, err = CLEUParser.GetOverkill(...)
|
||||
if not err and overkill > 0 then
|
||||
local source, err = CLEUParser.GetSourceName(...)
|
||||
if err then source = "unknown" end
|
||||
local destination, err = CLEUParser.GetDestName(...)
|
||||
if err then destination = "unknown" end
|
||||
local spellName, err = CLEUParser.GetSpellName(...)
|
||||
if err then spellName = "unknown" end
|
||||
local sourceGUID, err = CLEUParser.GetSourceGUID(...)
|
||||
if err or not string.match(sourceGUID, "Player") then return end
|
||||
local destinationGUID, err = CLEUParser.GetDestGUID(...)
|
||||
if err or not string.match(destinationGUID, "Player") then return end
|
||||
RegisterDeath(source, destination, spellName, overkill)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
19
Heimdall.lua
19
Heimdall.lua
@@ -33,6 +33,7 @@ local function init()
|
||||
---@field spotter HeimdallSpotterConfig
|
||||
---@field who HeimdallWhoConfig
|
||||
---@field messenger HeimdallMessengerConfig
|
||||
---@field deathReporter HeimdallDeathReporterConfig
|
||||
---@field whisperNotify table<string, string>
|
||||
|
||||
---@class HeimdallSpotterConfig
|
||||
@@ -56,6 +57,12 @@ local function init()
|
||||
---@class HeimdallMessengerConfig
|
||||
---@field enabled boolean
|
||||
|
||||
---@class HeimdallDeathReporterConfig
|
||||
---@field enabled boolean
|
||||
---@field throttle number
|
||||
---@field doWhisper boolean
|
||||
---@field notifyChannel string
|
||||
|
||||
--- Data ---
|
||||
---@class HeimdallMessengerData
|
||||
---@field queue table<string, Message>
|
||||
@@ -99,8 +106,8 @@ local function init()
|
||||
enabled = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "enabled" }, true),
|
||||
everyone = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "everyone" }, false),
|
||||
hostile = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "hostile" }, true),
|
||||
alliance = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "alliance" }, false),
|
||||
stinky = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "stinky" }, false),
|
||||
alliance = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "alliance" }, true),
|
||||
stinky = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "stinky" }, true),
|
||||
notifyChannel = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "notifyChannel" }, "Foobar"),
|
||||
zoneOverride = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "zoneOverride" }, nil),
|
||||
throttleTime = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "throttleTime" }, 1)
|
||||
@@ -123,6 +130,12 @@ local function init()
|
||||
messenger = {
|
||||
enabled = data.GetOrDefault(Heimdall_Data, { "config", "messenger", "enabled" }, true),
|
||||
},
|
||||
deathReporter = {
|
||||
enabled = data.GetOrDefault(Heimdall_Data, { "config", "deathReporter", "enabled" }, true),
|
||||
throttle = data.GetOrDefault(Heimdall_Data, { "config", "deathReporter", "throttle" }, 10),
|
||||
doWhisper = data.GetOrDefault(Heimdall_Data, { "config", "deathReporter", "doWhisper" }, true),
|
||||
notifyChannel = data.GetOrDefault(Heimdall_Data, { "config", "deathReporter", "notifyChannel" }, "Foobar"),
|
||||
},
|
||||
whisperNotify = data.GetOrDefault(Heimdall_Data, { "config", "whisperNotify" }, {
|
||||
-- "Extazyk",
|
||||
-- "Smokefire",
|
||||
@@ -237,4 +250,4 @@ loadedFrame:SetScript("OnEvent", function(self, event, addonName)
|
||||
if addonName == addonname then
|
||||
init()
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
@@ -10,4 +10,5 @@ DumpTable.lua
|
||||
Spotter.lua
|
||||
Whoer.lua
|
||||
Messenger.lua
|
||||
DeathReporter.lua
|
||||
Heimdall.lua
|
Reference in New Issue
Block a user