Rework who queries out to config

This commit is contained in:
2025-01-25 20:57:11 +01:00
parent 439e9b29d1
commit 196a5a8cfa
3 changed files with 157 additions and 52 deletions

View File

@@ -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 WhoQueryService WhoQueryService
---@field Whoer InitTable ---@field Whoer InitTable
---@field Messenger InitTable ---@field Messenger InitTable
---@field Spotter InitTable ---@field Spotter InitTable
@@ -107,6 +108,7 @@ local function init()
---@field ttl number ---@field ttl number
---@field doWhisper boolean ---@field doWhisper boolean
---@field zoneNotifyFor table<string, boolean> ---@field zoneNotifyFor table<string, boolean>
---@field queries WHOQuery[]
---@class HeimdallMessengerConfig ---@class HeimdallMessengerConfig
---@field enabled boolean ---@field enabled boolean
@@ -338,6 +340,7 @@ local function init()
["Echo Isles"] = true, ["Echo Isles"] = true,
["Valley of Trials"] = true, ["Valley of Trials"] = true,
}), }),
queries = shared.GetOrDefault(Heimdall_Data, { "config", "who", "queries" }, {}),
}, },
messenger = { messenger = {
enabled = shared.GetOrDefault(Heimdall_Data, { "config", "messenger", "enabled" }, true), enabled = shared.GetOrDefault(Heimdall_Data, { "config", "messenger", "enabled" }, true),

View File

@@ -657,7 +657,7 @@ function shared.Config.Init()
local whoerConfigFrame = GridFrame.new("HeimdallWhoerConfig", local whoerConfigFrame = GridFrame.new("HeimdallWhoerConfig",
UIParent, 12, 20) UIParent, 12, 20)
whoerConfigFrame.frame:SetBackdropColor(r, g, b, 0.3) whoerConfigFrame.frame:SetBackdropColor(r, g, b, 0.3)
configFrame:Add(whoerConfigFrame, 16, 3) configFrame:Add(whoerConfigFrame, 16, 6)
local title = CreateFancyText("HeimdallWhoerConfigTitle", whoerConfigFrame.frame, local title = CreateFancyText("HeimdallWhoerConfigTitle", whoerConfigFrame.frame,
shared.L[Heimdall_Data.config.locale].config.whoer, { r, g, b, a }) shared.L[Heimdall_Data.config.locale].config.whoer, { r, g, b, a })
@@ -676,7 +676,7 @@ function shared.Config.Init()
return Heimdall_Data.config.who.enabled return Heimdall_Data.config.who.enabled
end) end)
enableButton:UpdateColor(Heimdall_Data.config.who.enabled) enableButton:UpdateColor(Heimdall_Data.config.who.enabled)
whoerConfigFrame:Add(enableButton, 1, 6) whoerConfigFrame:Add(enableButton, 2, 3)
local doWhisperButton = CreateBasicButton("HeimdallWhoerConfigDoWhisperButton", local doWhisperButton = CreateBasicButton("HeimdallWhoerConfigDoWhisperButton",
whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.doWhisper, function() whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.doWhisper, function()
@@ -684,7 +684,7 @@ function shared.Config.Init()
return Heimdall_Data.config.who.doWhisper return Heimdall_Data.config.who.doWhisper
end) end)
doWhisperButton:UpdateColor(Heimdall_Data.config.who.doWhisper) doWhisperButton:UpdateColor(Heimdall_Data.config.who.doWhisper)
whoerConfigFrame:Add(doWhisperButton, 1, 6) whoerConfigFrame:Add(doWhisperButton, 2, 3)
local notifyChannel = CreateBasicSmallEditBox("HeimdallWhoerConfigNotifyChannel", local notifyChannel = CreateBasicSmallEditBox("HeimdallWhoerConfigNotifyChannel",
whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.notifyChannel, whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.notifyChannel,
@@ -699,7 +699,7 @@ function shared.Config.Init()
self:SetText(Heimdall_Data.config.who.notifyChannel) self:SetText(Heimdall_Data.config.who.notifyChannel)
end end
end) end)
whoerConfigFrame:Add(notifyChannel, 2, 6) whoerConfigFrame:Add(notifyChannel, 2, 3)
local ttl = CreateBasicSmallEditBox("HeimdallWhoerConfigTTL", local ttl = CreateBasicSmallEditBox("HeimdallWhoerConfigTTL",
whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.ttl, whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.ttl,
@@ -714,7 +714,7 @@ function shared.Config.Init()
self:SetText(Heimdall_Data.config.who.ttl) self:SetText(Heimdall_Data.config.who.ttl)
end end
end) end)
whoerConfigFrame:Add(ttl, 2, 6) whoerConfigFrame:Add(ttl, 2, 3)
local ignored = CreateBasicBigEditBox("HeimdallWhoerConfigIgnored", local ignored = CreateBasicBigEditBox("HeimdallWhoerConfigIgnored",
whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.ignored, whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.ignored,
@@ -723,7 +723,7 @@ function shared.Config.Init()
local ignored = StringToMap(self:GetText(), "\n") local ignored = StringToMap(self:GetText(), "\n")
Heimdall_Data.config.who.ignored = ignored Heimdall_Data.config.who.ignored = ignored
end) end)
whoerConfigFrame:Add(ignored, 6, 6) whoerConfigFrame:Add(ignored, 4, 6)
local zoneNotifyFor = CreateBasicBigEditBox("HeimdallWhoerConfigZoneNotifyFor", local zoneNotifyFor = CreateBasicBigEditBox("HeimdallWhoerConfigZoneNotifyFor",
whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.zoneNotifyFor, whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.zoneNotifyFor,
@@ -732,7 +732,16 @@ function shared.Config.Init()
local zoneNotifyFor = StringToMap(self:GetText(), "\n") local zoneNotifyFor = StringToMap(self:GetText(), "\n")
Heimdall_Data.config.who.zoneNotifyFor = zoneNotifyFor Heimdall_Data.config.who.zoneNotifyFor = zoneNotifyFor
end) end)
whoerConfigFrame:Add(zoneNotifyFor, 6, 6) whoerConfigFrame:Add(zoneNotifyFor, 4, 6)
local whoQueries = CreateBasicBigEditBox("HeimdallWhoerConfigQueries",
whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.queries,
shared.WhoQueryService.WhoQueriesToString(Heimdall_Data.config.who.queries or {}),
function(self)
local queries = shared.WhoQueryService.WhoQueriesFromString(self:GetText())
Heimdall_Data.config.who.queries = queries
end)
whoerConfigFrame:Add(whoQueries, 4, 6)
end end
-- Messenger -- Messenger

View File

@@ -66,9 +66,9 @@ function shared.Whoer.Init()
tostring(shared.raceMap[self.race]), tostring(shared.raceMap[self.race]),
self.guild, self.guild,
self.zone) self.zone)
--self.firstSeen, --self.firstSeen,
--self.lastSeen, --self.lastSeen,
--self.seenCount) --self.seenCount)
return text return text
end, end,
---@return string ---@return string
@@ -97,9 +97,9 @@ function shared.Whoer.Init()
ruFaction or faction, ruFaction or faction,
self.guild, self.guild,
self.zone) self.zone)
--self.firstSeen, --self.firstSeen,
--self.lastSeen, --self.lastSeen,
--self.seenCount) --self.seenCount)
return text return text
end end
} }
@@ -121,43 +121,130 @@ function shared.Whoer.Init()
end end
} }
---@alias WHOFilter fun(name: string, guild: string, level: number, race: string, class: string, zone: string): boolean ---@class WHOFilter
---@field Run fun(name: string, guild: string, level: number, race: string, class: string, zone: string): boolean
---@field key string
---@type WHOFilter ---@type WHOFilter
local NotSiegeOfOrgrimmarFilter = function(name, guild, level, race, class, zone) local NotSiegeOfOrgrimmarFilter = {
if not zone then Run = function(name, guild, level, race, class, zone)
return false if not zone then
end return false
return zone ~= "Siege of Orgrimmar" end
end return zone ~= "Siege of Orgrimmar"
---@type WHOFilter end,
local AllianceFilter = function(name, guild, level, race, class, zone) key = "notsoo"
if not race then return false end
if not shared.raceMap[race] then return false end
return shared.raceMap[race] == "Alliance"
end
local whoQueryIdx = 1
---@type WHOQuery[]
local whoQueries = {
WHOQuery.new("g-\"БеспредеЛ\"", {}),
WHOQuery.new("g-\"ЗАО бещёки\"", {}),
WHOQuery.new("g-\"КОНИЛИНГУСЫ\"", {}),
--WHOQuery.new("g-\"Dovahkin\"", {}),
WHOQuery.new(
"z-\"Orgrimmar\" z-\"Durotar\" z-\"Valley of Trials\" r-\"Human\" r-\"Dwarf\" r-\"Night Elf\"",
{ NotSiegeOfOrgrimmarFilter, AllianceFilter }),
WHOQuery.new(
"z-\"Orgrimmar\" z-\"Durotar\" z-\"Valley of Trials\" r-\"Gnome\" r-\"Draenei\" r-\"Worgen\"",
{ NotSiegeOfOrgrimmarFilter, AllianceFilter }),
WHOQuery.new(
"z-\"Orgrimmar\" z-\"Durotar\" z-\"Valley of Trials\" r-\"Kul Tiran\" r-\"Dark Iron Dwarf\" r-\"Void Elf\"",
{ NotSiegeOfOrgrimmarFilter, AllianceFilter }),
WHOQuery.new(
"z-\"Orgrimmar\" z-\"Durotar\" z-\"Valley of Trials\" r-\"Lightforged Draenei\" r-\"Mechagnome\"",
{ NotSiegeOfOrgrimmarFilter, AllianceFilter }),
WHOQuery.new("Kekv Firobot Tomoki Mld Alltros", {})
} }
local ttl = #whoQueries * 2 ---@type WHOFilter
local AllianceFilter = {
Run = function(name, guild, level, race, class, zone)
if not race then return false end
if not shared.raceMap[race] then return false end
return shared.raceMap[race] == "Alliance"
end,
key = "ally"
}
---@class WhoQueryService
---@field filters WHOFilter[]
---@field getFilter fun(key: string): WHOFilter?
---@field WhoQueryToString fun(query: WHOQuery): string
---@field WhoQueryFromString fun(query: string): WHOQuery
---@field WhoQueriesToString fun(queries: WHOQuery[]): string
---@field WhoQueriesFromString fun(queries: string): WHOQuery[]
shared.WhoQueryService = {
filters = {
NotSiegeOfOrgrimmarFilter,
AllianceFilter
},
---@param key string
---@return WHOFilter?
getFilter = function(key)
for _, filter in pairs(shared.WhoQueryService.filters) do
if filter.key == key then
return filter
end
end
return nil
end,
---@param query WHOQuery
---@return string
WhoQueryToString = function(query)
local ret = ""
ret = ret .. query.query
ret = ret .. ";"
for _, filter in pairs(query.filters) do
ret = ret .. filter.key .. ";"
end
return ret
end,
---@param queries WHOQuery[]
---@return string
WhoQueriesToString = function(queries)
local ret = ""
for _, query in pairs(queries) do
ret = ret .. shared.WhoQueryService.WhoQueryToString(query) .. "\n"
end
return ret
end,
---@param query string
---@return WHOQuery
WhoQueryFromString = function(query)
local queryParts = shared.Split(query, ";")
local filters = {}
for _, filterKey in pairs(queryParts) do
local filter = shared.WhoQueryService.getFilter(filterKey)
if not filter then
if Heimdall_Data.config.who.debug then
print(string.format("[%s] Filter %s not found", ModuleName, filterKey))
end
else
if Heimdall_Data.config.who.debug then
print(string.format("[%s] Filter %s found", ModuleName, filterKey))
end
table.insert(filters, filter)
end
end
if Heimdall_Data.config.who.debug then
print(string.format("[%s] WHO query: %s with %d filters", ModuleName, queryParts[1], #filters))
end
return WHOQuery.new(queryParts[1], filters)
end,
---@param queries string
---@return WHOQuery[]
WhoQueriesFromString = function(queries)
local queries = shared.Split(queries, "\n")
local ret = {}
for _, query in pairs(queries) do
table.insert(ret, shared.WhoQueryService.WhoQueryFromString(query))
end
return ret
end
}
local query = shared.WhoQueryService.WhoQueryFromString("g-\"БеспредеЛ\";ally")
Heimdall_Data.config.who.queries[1] = query
-----@type WHOQuery[]
--local whoQueries = {
-- WHOQuery.new("g-\"БеспредеЛ\"", {}),
-- WHOQuery.new("g-\"ЗАО бещёки\"", {}),
-- WHOQuery.new("g-\"КОНИЛИНГУСЫ\"", {}),
-- --WHOQuery.new("g-\"Dovahkin\"", {}),
-- WHOQuery.new(
-- "z-\"Orgrimmar\" z-\"Durotar\" z-\"Valley of Trials\" r-\"Human\" r-\"Dwarf\" r-\"Night Elf\"",
-- { NotSiegeOfOrgrimmarFilter, AllianceFilter }),
-- WHOQuery.new(
-- "z-\"Orgrimmar\" z-\"Durotar\" z-\"Valley of Trials\" r-\"Gnome\" r-\"Draenei\" r-\"Worgen\"",
-- { NotSiegeOfOrgrimmarFilter, AllianceFilter }),
-- WHOQuery.new(
-- "z-\"Orgrimmar\" z-\"Durotar\" z-\"Valley of Trials\" r-\"Kul Tiran\" r-\"Dark Iron Dwarf\" r-\"Void Elf\"",
-- { NotSiegeOfOrgrimmarFilter, AllianceFilter }),
-- WHOQuery.new(
-- "z-\"Orgrimmar\" z-\"Durotar\" z-\"Valley of Trials\" r-\"Lightforged Draenei\" r-\"Mechagnome\"",
-- { NotSiegeOfOrgrimmarFilter, AllianceFilter }),
-- WHOQuery.new("Kekv Firobot Tomoki Mld Alltros", {})
--}
local whoQueryIdx = 1
---@type WHOQuery? ---@type WHOQuery?
local lastQuery = nil local lastQuery = nil
@@ -411,9 +498,9 @@ function shared.Whoer.Init()
---@type WHOFilter[] ---@type WHOFilter[]
local filters = query.filters local filters = query.filters
for _, filter in pairs(filters) do for _, filter in pairs(filters) do
if not filter(name, guild, level, race, class, zone) then if not filter.Run(name, guild, level, race, class, zone) then
if Heimdall_Data.config.who.debug then if Heimdall_Data.config.who.debug then
print(string.format("[%s] Player %s filtered out by WHO filter", ModuleName, name)) print(string.format("[%s] Player %s filtered out by WHO filter %s", ModuleName, name, filter.key))
end end
continue = true continue = true
break break
@@ -519,9 +606,15 @@ function shared.Whoer.Init()
local function DoQuery() local function DoQuery()
if not Heimdall_Data.config.who.enabled then return end if not Heimdall_Data.config.who.enabled then return end
local query = whoQueries[whoQueryIdx] local query = Heimdall_Data.config.who.queries[whoQueryIdx]
if not query then
if Heimdall_Data.config.who.debug then
print(string.format("[%s] Error: No WHO query found to run", ModuleName))
end
return
end
whoQueryIdx = whoQueryIdx + 1 whoQueryIdx = whoQueryIdx + 1
if whoQueryIdx > #whoQueries then if whoQueryIdx > #Heimdall_Data.config.who.queries then
whoQueryIdx = 1 whoQueryIdx = 1
end end
lastQuery = query lastQuery = query