Fix who messages to be partitioned
This commit is contained in:
@@ -368,10 +368,40 @@ function shared.Whoer.Init()
|
||||
Tick()
|
||||
end
|
||||
|
||||
---@param text string
|
||||
---@param size number
|
||||
---@return string[]
|
||||
local function Count()
|
||||
local function Partition(text, size)
|
||||
local words = {}
|
||||
for word in text:gmatch("%S+") do
|
||||
words[#words + 1] = word
|
||||
end
|
||||
|
||||
local ret = {}
|
||||
for _, player in pairs(HeimdallStinkies) do
|
||||
local currentChunk = ""
|
||||
|
||||
for _, word in ipairs(words) do
|
||||
if #currentChunk + #word + 1 <= size then
|
||||
currentChunk = currentChunk .. (currentChunk == "" and word or " " .. word)
|
||||
else
|
||||
if #currentChunk > 0 then
|
||||
ret[#ret + 1] = currentChunk
|
||||
end
|
||||
currentChunk = word
|
||||
end
|
||||
end
|
||||
|
||||
if #currentChunk > 0 then
|
||||
ret[#ret + 1] = currentChunk
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
---@param arr table<string, Player>
|
||||
---@return string[]
|
||||
local function Count(arr)
|
||||
local ret = {}
|
||||
for _, player in pairs(arr) do
|
||||
if Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||
ret[player.zone] = (ret[player.zone] or 0) + 1
|
||||
end
|
||||
@@ -382,21 +412,43 @@ function shared.Whoer.Init()
|
||||
end
|
||||
return text
|
||||
end
|
||||
---@param arr table<string, Player>
|
||||
---@return string[]
|
||||
local function Who()
|
||||
local function CountPartitioned(arr)
|
||||
local count = Count(arr)
|
||||
local text = {}
|
||||
for _, line in pairs(Partition(strjoin(", ", unpack(count)), 200)) do
|
||||
text[#text + 1] = line
|
||||
end
|
||||
return text
|
||||
end
|
||||
---@param arr table<string, Player>
|
||||
---@return string[]
|
||||
local function Who(arr)
|
||||
local ret = {}
|
||||
for _, player in pairs(HeimdallStinkies) do
|
||||
for _, player in pairs(arr) do
|
||||
if Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||
ret[#ret + 1] = string.format("%s/%s (%s) %s", player.name, player.class, player.zone,
|
||||
player.stinky and "(!!!!)" or "")
|
||||
player.stinky and "(!!!!)" or "")
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
---@param arr table<string, Player>
|
||||
---@return string[]
|
||||
local function CountClass()
|
||||
local function WhoPartitioned(arr)
|
||||
local who = Who(arr)
|
||||
local text = {}
|
||||
for _, line in pairs(Partition(strjoin(", ", unpack(who)), 200)) do
|
||||
text[#text + 1] = line
|
||||
end
|
||||
return text
|
||||
end
|
||||
---@param arr table<string, Player>
|
||||
---@return string[]
|
||||
local function CountClass(arr)
|
||||
local ret = {}
|
||||
for _, player in pairs(HeimdallStinkies) do
|
||||
for _, player in pairs(arr) do
|
||||
if Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||
ret[player.class] = (ret[player.class] or 0) + 1
|
||||
end
|
||||
@@ -407,37 +459,56 @@ function shared.Whoer.Init()
|
||||
end
|
||||
return text
|
||||
end
|
||||
---@param arr table<string, Player>
|
||||
---@return string[]
|
||||
local function CountClassPartitioned(arr)
|
||||
local countClass = CountClass(arr)
|
||||
local text = {}
|
||||
for _, line in pairs(Partition(strjoin(", ", unpack(countClass)), 200)) do
|
||||
text[#text + 1] = line
|
||||
end
|
||||
return text
|
||||
end
|
||||
|
||||
local whoQueryWhisperFrame = CreateFrame("Frame")
|
||||
whoQueryWhisperFrame:RegisterEvent("CHAT_MSG_WHISPER")
|
||||
whoQueryWhisperFrame:SetScript("OnEvent", function(self, event, msg, sender)
|
||||
if not Heimdall_Data.config.who.enabled then return end
|
||||
if msg == "who" then
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "WHISPER",
|
||||
data = sender,
|
||||
message = strjoin(", ", unpack(Who()))
|
||||
}
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
local messages = WhoPartitioned(HeimdallStinkies)
|
||||
for _, message in pairs(messages) do
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "WHISPER",
|
||||
data = sender,
|
||||
message = message
|
||||
}
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
if msg == "howmany" then
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "WHISPER",
|
||||
data = sender,
|
||||
message = strjoin(", ", unpack(Count()))
|
||||
}
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
local messages = CountPartitioned(HeimdallStinkies)
|
||||
for _, message in pairs(messages) do
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "WHISPER",
|
||||
data = sender,
|
||||
message = message
|
||||
}
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
if msg == "classes" then
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "WHISPER",
|
||||
data = sender,
|
||||
message = strjoin(", ", unpack(CountClass()))
|
||||
}
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
local messages = CountClassPartitioned(HeimdallStinkies)
|
||||
for _, message in pairs(messages) do
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "WHISPER",
|
||||
data = sender,
|
||||
message = message
|
||||
}
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
if msg == "help" then
|
||||
for _, helpMessage in pairs(helpMessages) do
|
||||
@@ -473,31 +544,40 @@ function shared.Whoer.Init()
|
||||
if channelname ~= Heimdall_Data.config.who.notifyChannel then return end
|
||||
|
||||
if msg == "who" then
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "CHANNEL",
|
||||
data = channelname,
|
||||
message = "who: " .. strjoin(", ", unpack(Who()))
|
||||
}
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
local messages = WhoPartitioned(HeimdallStinkies)
|
||||
for _, message in pairs(messages) do
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "CHANNEL",
|
||||
data = channelname,
|
||||
message = message
|
||||
}
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
if msg == "howmany" then
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "CHANNEL",
|
||||
data = channelname,
|
||||
message = "howmany: " .. strjoin(", ", unpack(Count()))
|
||||
}
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
local messages = CountPartitioned(HeimdallStinkies)
|
||||
for _, message in pairs(messages) do
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "CHANNEL",
|
||||
data = channelname,
|
||||
message = message
|
||||
}
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
if msg == "classes" then
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "CHANNEL",
|
||||
data = channelname,
|
||||
message = "classes: " .. strjoin(", ", unpack(CountClass()))
|
||||
}
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
local messages = CountClassPartitioned(HeimdallStinkies)
|
||||
for _, message in pairs(messages) do
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "CHANNEL",
|
||||
data = channelname,
|
||||
message = message
|
||||
}
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
if msg == "help" then
|
||||
for _, helpMessage in pairs(helpMessages) do
|
||||
|
Reference in New Issue
Block a user