Rework "notifyzonefor" to use regex
This commit is contained in:
30
Heimdall.lua
30
Heimdall.lua
@@ -31,6 +31,7 @@ local function init()
|
||||
---@field GetOrDefault fun(table: table<any, any>, keys: string[], default: any): any
|
||||
---@field Split fun(input: string, deliminer: string): string[]
|
||||
---@field IsStinky fun(name: string): boolean
|
||||
---@field Memoize fun(f: function): function
|
||||
---@field WhoQueryService WhoQueryService
|
||||
---@field Whoer InitTable
|
||||
---@field Messenger InitTable
|
||||
@@ -88,6 +89,7 @@ local function init()
|
||||
---@field notes table<string, Note[]>
|
||||
---@field locale string
|
||||
---@field echoToRussian boolean
|
||||
---@field debug boolean
|
||||
|
||||
---@class HeimdallSpotterConfig
|
||||
---@field enabled boolean
|
||||
@@ -315,6 +317,7 @@ local function init()
|
||||
|
||||
--/run Heimdall_Data.config.who.queries="g-\"БеспредеЛ\"|ally"
|
||||
Heimdall_Data.config = {
|
||||
debug = shared.GetOrDefault(Heimdall_Data, { "config", "debug" }, false),
|
||||
spotter = {
|
||||
enabled = shared.GetOrDefault(Heimdall_Data, { "config", "spotter", "enabled" }, true),
|
||||
debug = shared.GetOrDefault(Heimdall_Data, { "config", "spotter", "debug" }, false),
|
||||
@@ -622,6 +625,33 @@ local function init()
|
||||
return Heimdall_Data.config.stinkies[name] ~= nil or shared.StinkyCache[name] ~= nil
|
||||
end
|
||||
|
||||
---@param f function
|
||||
---@return function
|
||||
shared.Memoize = function(f)
|
||||
local mem = {} -- memoizing table
|
||||
setmetatable(mem, { __mode = "kv" }) -- make it weak
|
||||
return function(x) -- new version of ’f’, with memoizing
|
||||
if Heimdall_Data.config.debug then
|
||||
print(string.format("[Heimdall] Memoize %s", tostring(x)))
|
||||
end
|
||||
local r = mem[x]
|
||||
if r == nil then -- no previous result?
|
||||
if Heimdall_Data.config.debug then
|
||||
print(string.format("[Heimdall] Memoize %s is nil, calling original function", tostring(x)))
|
||||
end
|
||||
r = f(x) -- calls original function
|
||||
if Heimdall_Data.config.debug then
|
||||
print(string.format("[Heimdall] Memoized result for %s: %s", tostring(x), tostring(r)))
|
||||
end
|
||||
mem[x] = r -- store result for reuse
|
||||
end
|
||||
if Heimdall_Data.config.debug then
|
||||
print(string.format("[Heimdall] Memoize %s is %s", tostring(x), tostring(r)))
|
||||
end
|
||||
return r
|
||||
end
|
||||
end
|
||||
|
||||
shared.Messenger.Init()
|
||||
shared.StinkyTracker.Init()
|
||||
shared.AgentTracker.Init()
|
||||
|
Reference in New Issue
Block a user