Do fucking something who even fucking cares
This commit is contained in:
@@ -245,6 +245,8 @@ local function init()
|
|||||||
---@class HeimdallStinkyCacheConfig
|
---@class HeimdallStinkyCacheConfig
|
||||||
---@field enabled boolean
|
---@field enabled boolean
|
||||||
---@field debug boolean
|
---@field debug boolean
|
||||||
|
---@field commander string
|
||||||
|
---@field ttl number
|
||||||
|
|
||||||
--- Data ---
|
--- Data ---
|
||||||
---@class HeimdallMessengerData
|
---@class HeimdallMessengerData
|
||||||
@@ -267,7 +269,7 @@ local function init()
|
|||||||
---@field ticker number?
|
---@field ticker number?
|
||||||
|
|
||||||
---@class HeimdallStinkyCacheData
|
---@class HeimdallStinkyCacheData
|
||||||
---@field stinkies table<string, number>
|
---@field stinkies table<string, {value: number, timestamp: number}>
|
||||||
|
|
||||||
shared.GetOrDefault = function(table, keys, default)
|
shared.GetOrDefault = function(table, keys, default)
|
||||||
local value = default
|
local value = default
|
||||||
@@ -490,6 +492,8 @@ local function init()
|
|||||||
stinkyCache = {
|
stinkyCache = {
|
||||||
enabled = shared.GetOrDefault(Heimdall_Data, { "config", "stinkyCache", "enabled" }, false),
|
enabled = shared.GetOrDefault(Heimdall_Data, { "config", "stinkyCache", "enabled" }, false),
|
||||||
debug = shared.GetOrDefault(Heimdall_Data, { "config", "stinkyCache", "debug" }, false),
|
debug = shared.GetOrDefault(Heimdall_Data, { "config", "stinkyCache", "debug" }, false),
|
||||||
|
commander = shared.GetOrDefault(Heimdall_Data, { "config", "stinkyCache", "commander" }, "Heimdállr"),
|
||||||
|
ttl = shared.GetOrDefault(Heimdall_Data, { "config", "stinkyCache", "ttl" }, 10),
|
||||||
},
|
},
|
||||||
addonPrefix = shared.GetOrDefault(Heimdall_Data, { "config", "addonPrefix" }, "HEIMDALL"),
|
addonPrefix = shared.GetOrDefault(Heimdall_Data, { "config", "addonPrefix" }, "HEIMDALL"),
|
||||||
}
|
}
|
||||||
|
@@ -6,5 +6,53 @@ local ModuleName = "StinkyCache"
|
|||||||
---@diagnostic disable-next-line: missing-fields
|
---@diagnostic disable-next-line: missing-fields
|
||||||
shared.StinkyCache = {}
|
shared.StinkyCache = {}
|
||||||
function shared.StinkyCache.Init()
|
function shared.StinkyCache.Init()
|
||||||
|
shared.stinkyCache.stinkies = {}
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
local function AskCommander(name)
|
||||||
|
if Heimdall_Data.config.stinkyCache.debug then
|
||||||
|
print(string.format("[%s] Asking commander %s about %s", ModuleName,
|
||||||
|
Heimdall_Data.config.stinkyCache.commander, name))
|
||||||
|
end
|
||||||
|
local messageParts = { "isstinky", name }
|
||||||
|
local message = table.concat(messageParts, "|")
|
||||||
|
SendAddonMessage(Heimdall_Data.config.addonPrefix,
|
||||||
|
message, "WHISPER",
|
||||||
|
Heimdall_Data.config.stinkyCache.commander)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local addonMessageFrame = CreateFrame("Frame")
|
||||||
|
addonMessageFrame:RegisterEvent("CHAT_MSG_ADDON")
|
||||||
|
addonMessageFrame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
||||||
|
if sender == Heimdall_Data.config.stinkyCache.commander then
|
||||||
|
if Heimdall_Data.config.stinkyCache.debug then
|
||||||
|
print(string.format("[%s] Received stinky from commander %s: %s", ModuleName,
|
||||||
|
Heimdall_Data.config.stinkyCache.commander, msg))
|
||||||
|
end
|
||||||
|
local name, value = {strsplit("|", msg)}
|
||||||
|
shared.stinkyCache.stinkies[name] = { value = value, timestamp = time() }
|
||||||
|
else
|
||||||
|
if Heimdall_Data.config.stinkyCache.debug then
|
||||||
|
print(string.format("[%s] Received stinky from non-commander %s: %s", ModuleName, sender, msg))
|
||||||
|
end
|
||||||
|
local parts = {strsplit("|", msg)}
|
||||||
|
local command, name = parts[1], parts[2]
|
||||||
|
if parts[1] == "isstinky" then
|
||||||
|
local res = Heimdall_Data.config.stinkies[parts[2]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
setmetatable(shared.stinkyCache.stinkies, {
|
||||||
|
__index = function(self, key)
|
||||||
|
local value = rawget(self, key)
|
||||||
|
local now = GetTime()
|
||||||
|
if value == nil or now - value.timestamp > Heimdall_Data.config.stinkyCache.ttl then
|
||||||
|
AskCommander(key)
|
||||||
|
end
|
||||||
|
return rawget(self, key)
|
||||||
|
end
|
||||||
|
})
|
||||||
print("[Heimdall] StinkyCache module loaded")
|
print("[Heimdall] StinkyCache module loaded")
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user