Rework "notifyzonefor" to use regex

This commit is contained in:
2025-01-25 22:51:43 +01:00
parent ffca28c67d
commit a90eb8248f
3 changed files with 76 additions and 8 deletions

View File

@@ -169,7 +169,7 @@ function shared.Whoer.Init()
return nil
end,
---@param query WHOQuery
---@return string
---@return string
WhoQueryToString = function(query)
local ret = ""
ret = ret .. query.query
@@ -226,6 +226,26 @@ function shared.Whoer.Init()
}
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[]
--local whoQueries = {
-- WHOQuery.new("g-\"БеспредеЛ\"", {}),
@@ -271,7 +291,8 @@ function shared.Whoer.Init()
return string.format("Cannot notify for nil player %s", tostring(player))
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
print(string.format("[%s] Skipping notification - Zone '%s' not in notify list", ModuleName, player.zone))
end
@@ -341,8 +362,9 @@ function shared.Whoer.Init()
local function NotifyZoneChanged(player, zone)
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 Heimdall_Data.config.who.zoneNotifyFor[zone]
and not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
--if not Heimdall_Data.config.who.zoneNotifyFor[zone]
-- 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))
end
local text = string.format(shared.L.en.whoerMoved,
@@ -405,9 +427,9 @@ function shared.Whoer.Init()
local function NotifyGone(player)
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 Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
return string.format("Not notifying for zone %s",
tostring(player.zone))
--if not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
if not ShouldNotifyForZone(player.zone) then
return string.format("Not notifying for zone %s", tostring(player.zone))
end
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))
end
continue = true
else
if Heimdall_Data.config.who.debug then
print(string.format("[%s] Player %s is not blacklisted", ModuleName, name))
end
end
if not continue then
@@ -572,6 +598,9 @@ function shared.Whoer.Init()
player.lastSeenInternal = GetTime()
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)
if err then
print(string.format("Error notifying for %s: %s", tostring(name), tostring(err)))