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