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 GetOrDefault fun(table: table<any, any>, keys: string[], default: any): any
|
||||||
---@field Split fun(input: string, deliminer: string): string[]
|
---@field Split fun(input: string, deliminer: string): string[]
|
||||||
---@field IsStinky fun(name: string): boolean
|
---@field IsStinky fun(name: string): boolean
|
||||||
|
---@field Memoize fun(f: function): function
|
||||||
---@field WhoQueryService WhoQueryService
|
---@field WhoQueryService WhoQueryService
|
||||||
---@field Whoer InitTable
|
---@field Whoer InitTable
|
||||||
---@field Messenger InitTable
|
---@field Messenger InitTable
|
||||||
@@ -88,6 +89,7 @@ local function init()
|
|||||||
---@field notes table<string, Note[]>
|
---@field notes table<string, Note[]>
|
||||||
---@field locale string
|
---@field locale string
|
||||||
---@field echoToRussian boolean
|
---@field echoToRussian boolean
|
||||||
|
---@field debug boolean
|
||||||
|
|
||||||
---@class HeimdallSpotterConfig
|
---@class HeimdallSpotterConfig
|
||||||
---@field enabled boolean
|
---@field enabled boolean
|
||||||
@@ -315,6 +317,7 @@ local function init()
|
|||||||
|
|
||||||
--/run Heimdall_Data.config.who.queries="g-\"БеспредеЛ\"|ally"
|
--/run Heimdall_Data.config.who.queries="g-\"БеспредеЛ\"|ally"
|
||||||
Heimdall_Data.config = {
|
Heimdall_Data.config = {
|
||||||
|
debug = shared.GetOrDefault(Heimdall_Data, { "config", "debug" }, false),
|
||||||
spotter = {
|
spotter = {
|
||||||
enabled = shared.GetOrDefault(Heimdall_Data, { "config", "spotter", "enabled" }, true),
|
enabled = shared.GetOrDefault(Heimdall_Data, { "config", "spotter", "enabled" }, true),
|
||||||
debug = shared.GetOrDefault(Heimdall_Data, { "config", "spotter", "debug" }, false),
|
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
|
return Heimdall_Data.config.stinkies[name] ~= nil or shared.StinkyCache[name] ~= nil
|
||||||
end
|
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.Messenger.Init()
|
||||||
shared.StinkyTracker.Init()
|
shared.StinkyTracker.Init()
|
||||||
shared.AgentTracker.Init()
|
shared.AgentTracker.Init()
|
||||||
|
@@ -530,7 +530,16 @@ function shared.Config.Init()
|
|||||||
configFrame:Add(scale, 2, 2)
|
configFrame:Add(scale, 2, 2)
|
||||||
local title = configFrame.frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
|
local title = configFrame.frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
|
||||||
title:SetText(string.format("%s - v%s", shared.L[Heimdall_Data.config.locale].config.heimdallConfig, shared.VERSION))
|
title:SetText(string.format("%s - v%s", shared.L[Heimdall_Data.config.locale].config.heimdallConfig, shared.VERSION))
|
||||||
configFrame:Add(title, 2, 8)
|
configFrame:Add(title, 2, 7)
|
||||||
|
|
||||||
|
local debug = CreateBasicButton("HeimdallConfigDebug", configFrame.frame,
|
||||||
|
shared.L[Heimdall_Data.config.locale].config.debug, function()
|
||||||
|
Heimdall_Data.config.debug = not Heimdall_Data.config.debug
|
||||||
|
return Heimdall_Data.config.debug
|
||||||
|
end)
|
||||||
|
debug:UpdateColor(Heimdall_Data.config.debug)
|
||||||
|
configFrame:Add(debug, 2, 1)
|
||||||
|
|
||||||
local russian = nil
|
local russian = nil
|
||||||
local english = CreateBasicButton("HeimdallConfigEnglish", configFrame.frame, shared.L.en.config.english, function()
|
local english = CreateBasicButton("HeimdallConfigEnglish", configFrame.frame, shared.L.en.config.english, function()
|
||||||
Heimdall_Data.config.locale = "en"
|
Heimdall_Data.config.locale = "en"
|
||||||
|
@@ -169,7 +169,7 @@ function shared.Whoer.Init()
|
|||||||
return nil
|
return nil
|
||||||
end,
|
end,
|
||||||
---@param query WHOQuery
|
---@param query WHOQuery
|
||||||
---@return string
|
---@return string
|
||||||
WhoQueryToString = function(query)
|
WhoQueryToString = function(query)
|
||||||
local ret = ""
|
local ret = ""
|
||||||
ret = ret .. query.query
|
ret = ret .. query.query
|
||||||
@@ -226,6 +226,26 @@ function shared.Whoer.Init()
|
|||||||
}
|
}
|
||||||
shared.WhoQueryService.queries = shared.WhoQueryService.WhoQueriesFromString(Heimdall_Data.config.who.queries)
|
shared.WhoQueryService.queries = shared.WhoQueryService.WhoQueriesFromString(Heimdall_Data.config.who.queries)
|
||||||
|
|
||||||
|
---@param inputZone string
|
||||||
|
---@return boolean
|
||||||
|
local ShouldNotifyForZone = shared.Memoize(function(inputZone)
|
||||||
|
if not Heimdall_Data.config.who.debug then
|
||||||
|
print(string.format("[%s] ShouldNotifyForZone %s", ModuleName, inputZone))
|
||||||
|
end
|
||||||
|
for zone, _ in pairs(Heimdall_Data.config.who.zoneNotifyFor) do
|
||||||
|
if string.find(inputZone, zone) then
|
||||||
|
if not Heimdall_Data.config.who.debug then
|
||||||
|
print(string.format("[%s] ShouldNotifyForZone %s is true thanks to %s", ModuleName, inputZone, zone))
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not Heimdall_Data.config.who.debug then
|
||||||
|
print(string.format("[%s] ShouldNotifyForZone %s is false", ModuleName, inputZone))
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end)
|
||||||
|
|
||||||
-----@type WHOQuery[]
|
-----@type WHOQuery[]
|
||||||
--local whoQueries = {
|
--local whoQueries = {
|
||||||
-- WHOQuery.new("g-\"БеспредеЛ\"", {}),
|
-- WHOQuery.new("g-\"БеспредеЛ\"", {}),
|
||||||
@@ -271,7 +291,8 @@ function shared.Whoer.Init()
|
|||||||
return string.format("Cannot notify for nil player %s", tostring(player))
|
return string.format("Cannot notify for nil player %s", tostring(player))
|
||||||
end
|
end
|
||||||
|
|
||||||
if not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
if not ShouldNotifyForZone(player.zone) then
|
||||||
|
--if not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||||
if Heimdall_Data.config.who.debug then
|
if Heimdall_Data.config.who.debug then
|
||||||
print(string.format("[%s] Skipping notification - Zone '%s' not in notify list", ModuleName, player.zone))
|
print(string.format("[%s] Skipping notification - Zone '%s' not in notify list", ModuleName, player.zone))
|
||||||
end
|
end
|
||||||
@@ -341,8 +362,9 @@ function shared.Whoer.Init()
|
|||||||
local function NotifyZoneChanged(player, zone)
|
local function NotifyZoneChanged(player, zone)
|
||||||
if not Heimdall_Data.config.who.enabled then return end
|
if not Heimdall_Data.config.who.enabled then return end
|
||||||
if not player then return string.format("Cannot notify for nil player %s", tostring(player)) end
|
if not player then return string.format("Cannot notify for nil player %s", tostring(player)) end
|
||||||
if not Heimdall_Data.config.who.zoneNotifyFor[zone]
|
--if not Heimdall_Data.config.who.zoneNotifyFor[zone]
|
||||||
and not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
-- and not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||||
|
if not ShouldNotifyForZone(zone) and not ShouldNotifyForZone(player.zone) then
|
||||||
return string.format("Not notifying for zones %s and %s", tostring(zone), tostring(player.zone))
|
return string.format("Not notifying for zones %s and %s", tostring(zone), tostring(player.zone))
|
||||||
end
|
end
|
||||||
local text = string.format(shared.L.en.whoerMoved,
|
local text = string.format(shared.L.en.whoerMoved,
|
||||||
@@ -405,9 +427,9 @@ function shared.Whoer.Init()
|
|||||||
local function NotifyGone(player)
|
local function NotifyGone(player)
|
||||||
if not Heimdall_Data.config.who.enabled then return end
|
if not Heimdall_Data.config.who.enabled then return end
|
||||||
if not player then return string.format("Cannot notify for nil player %s", tostring(player)) end
|
if not player then return string.format("Cannot notify for nil player %s", tostring(player)) end
|
||||||
if not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
--if not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||||
return string.format("Not notifying for zone %s",
|
if not ShouldNotifyForZone(player.zone) then
|
||||||
tostring(player.zone))
|
return string.format("Not notifying for zone %s", tostring(player.zone))
|
||||||
end
|
end
|
||||||
|
|
||||||
local text = string.format(shared.L.en.whoerGone,
|
local text = string.format(shared.L.en.whoerGone,
|
||||||
@@ -517,6 +539,10 @@ function shared.Whoer.Init()
|
|||||||
print(string.format("[%s] Ignoring blacklisted player: %s", ModuleName, name))
|
print(string.format("[%s] Ignoring blacklisted player: %s", ModuleName, name))
|
||||||
end
|
end
|
||||||
continue = true
|
continue = true
|
||||||
|
else
|
||||||
|
if Heimdall_Data.config.who.debug then
|
||||||
|
print(string.format("[%s] Player %s is not blacklisted", ModuleName, name))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not continue then
|
if not continue then
|
||||||
@@ -572,6 +598,9 @@ function shared.Whoer.Init()
|
|||||||
|
|
||||||
player.lastSeenInternal = GetTime()
|
player.lastSeenInternal = GetTime()
|
||||||
if player.zone ~= zone then
|
if player.zone ~= zone then
|
||||||
|
if Heimdall_Data.config.who.debug then
|
||||||
|
print(string.format("[%s] Player %s zone changed from %s to %s", ModuleName, name, player.zone, zone))
|
||||||
|
end
|
||||||
local err = NotifyZoneChanged(player, zone)
|
local err = NotifyZoneChanged(player, zone)
|
||||||
if err then
|
if err then
|
||||||
print(string.format("Error notifying for %s: %s", tostring(name), tostring(err)))
|
print(string.format("Error notifying for %s: %s", tostring(name), tostring(err)))
|
||||||
|
Reference in New Issue
Block a user