Rework who queries out to config
This commit is contained in:
@@ -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 WhoQueryService WhoQueryService
|
||||
---@field Whoer InitTable
|
||||
---@field Messenger InitTable
|
||||
---@field Spotter InitTable
|
||||
@@ -107,6 +108,7 @@ local function init()
|
||||
---@field ttl number
|
||||
---@field doWhisper boolean
|
||||
---@field zoneNotifyFor table<string, boolean>
|
||||
---@field queries WHOQuery[]
|
||||
|
||||
---@class HeimdallMessengerConfig
|
||||
---@field enabled boolean
|
||||
@@ -338,6 +340,7 @@ local function init()
|
||||
["Echo Isles"] = true,
|
||||
["Valley of Trials"] = true,
|
||||
}),
|
||||
queries = shared.GetOrDefault(Heimdall_Data, { "config", "who", "queries" }, {}),
|
||||
},
|
||||
messenger = {
|
||||
enabled = shared.GetOrDefault(Heimdall_Data, { "config", "messenger", "enabled" }, true),
|
||||
|
@@ -657,7 +657,7 @@ function shared.Config.Init()
|
||||
local whoerConfigFrame = GridFrame.new("HeimdallWhoerConfig",
|
||||
UIParent, 12, 20)
|
||||
whoerConfigFrame.frame:SetBackdropColor(r, g, b, 0.3)
|
||||
configFrame:Add(whoerConfigFrame, 16, 3)
|
||||
configFrame:Add(whoerConfigFrame, 16, 6)
|
||||
|
||||
local title = CreateFancyText("HeimdallWhoerConfigTitle", whoerConfigFrame.frame,
|
||||
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
|
||||
end)
|
||||
enableButton:UpdateColor(Heimdall_Data.config.who.enabled)
|
||||
whoerConfigFrame:Add(enableButton, 1, 6)
|
||||
whoerConfigFrame:Add(enableButton, 2, 3)
|
||||
|
||||
local doWhisperButton = CreateBasicButton("HeimdallWhoerConfigDoWhisperButton",
|
||||
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
|
||||
end)
|
||||
doWhisperButton:UpdateColor(Heimdall_Data.config.who.doWhisper)
|
||||
whoerConfigFrame:Add(doWhisperButton, 1, 6)
|
||||
whoerConfigFrame:Add(doWhisperButton, 2, 3)
|
||||
|
||||
local notifyChannel = CreateBasicSmallEditBox("HeimdallWhoerConfigNotifyChannel",
|
||||
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)
|
||||
end
|
||||
end)
|
||||
whoerConfigFrame:Add(notifyChannel, 2, 6)
|
||||
whoerConfigFrame:Add(notifyChannel, 2, 3)
|
||||
|
||||
local ttl = CreateBasicSmallEditBox("HeimdallWhoerConfigTTL",
|
||||
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)
|
||||
end
|
||||
end)
|
||||
whoerConfigFrame:Add(ttl, 2, 6)
|
||||
whoerConfigFrame:Add(ttl, 2, 3)
|
||||
|
||||
local ignored = CreateBasicBigEditBox("HeimdallWhoerConfigIgnored",
|
||||
whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.ignored,
|
||||
@@ -723,7 +723,7 @@ function shared.Config.Init()
|
||||
local ignored = StringToMap(self:GetText(), "\n")
|
||||
Heimdall_Data.config.who.ignored = ignored
|
||||
end)
|
||||
whoerConfigFrame:Add(ignored, 6, 6)
|
||||
whoerConfigFrame:Add(ignored, 4, 6)
|
||||
|
||||
local zoneNotifyFor = CreateBasicBigEditBox("HeimdallWhoerConfigZoneNotifyFor",
|
||||
whoerConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.zoneNotifyFor,
|
||||
@@ -732,7 +732,16 @@ function shared.Config.Init()
|
||||
local zoneNotifyFor = StringToMap(self:GetText(), "\n")
|
||||
Heimdall_Data.config.who.zoneNotifyFor = zoneNotifyFor
|
||||
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
|
||||
|
||||
-- Messenger
|
||||
|
@@ -66,9 +66,9 @@ function shared.Whoer.Init()
|
||||
tostring(shared.raceMap[self.race]),
|
||||
self.guild,
|
||||
self.zone)
|
||||
--self.firstSeen,
|
||||
--self.lastSeen,
|
||||
--self.seenCount)
|
||||
--self.firstSeen,
|
||||
--self.lastSeen,
|
||||
--self.seenCount)
|
||||
return text
|
||||
end,
|
||||
---@return string
|
||||
@@ -97,9 +97,9 @@ function shared.Whoer.Init()
|
||||
ruFaction or faction,
|
||||
self.guild,
|
||||
self.zone)
|
||||
--self.firstSeen,
|
||||
--self.lastSeen,
|
||||
--self.seenCount)
|
||||
--self.firstSeen,
|
||||
--self.lastSeen,
|
||||
--self.seenCount)
|
||||
return text
|
||||
end
|
||||
}
|
||||
@@ -121,43 +121,130 @@ function shared.Whoer.Init()
|
||||
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
|
||||
local NotSiegeOfOrgrimmarFilter = function(name, guild, level, race, class, zone)
|
||||
if not zone then
|
||||
return false
|
||||
end
|
||||
return zone ~= "Siege of Orgrimmar"
|
||||
end
|
||||
---@type WHOFilter
|
||||
local AllianceFilter = 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
|
||||
|
||||
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 NotSiegeOfOrgrimmarFilter = {
|
||||
Run = function(name, guild, level, race, class, zone)
|
||||
if not zone then
|
||||
return false
|
||||
end
|
||||
return zone ~= "Siege of Orgrimmar"
|
||||
end,
|
||||
key = "notsoo"
|
||||
}
|
||||
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?
|
||||
local lastQuery = nil
|
||||
|
||||
@@ -411,9 +498,9 @@ function shared.Whoer.Init()
|
||||
---@type WHOFilter[]
|
||||
local filters = query.filters
|
||||
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
|
||||
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
|
||||
continue = true
|
||||
break
|
||||
@@ -519,9 +606,15 @@ function shared.Whoer.Init()
|
||||
local function DoQuery()
|
||||
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
|
||||
if whoQueryIdx > #whoQueries then
|
||||
if whoQueryIdx > #Heimdall_Data.config.who.queries then
|
||||
whoQueryIdx = 1
|
||||
end
|
||||
lastQuery = query
|
||||
|
Reference in New Issue
Block a user