From c66c9612977927f35ab0d0b25c2079d1184ab0f8 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Wed, 1 Jan 2025 15:35:15 +0100 Subject: [PATCH] Rework the channel commands a little --- Modules/Whoer.lua | 74 ++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/Modules/Whoer.lua b/Modules/Whoer.lua index 7c26c87..dbde0ce 100644 --- a/Modules/Whoer.lua +++ b/Modules/Whoer.lua @@ -367,7 +367,7 @@ function shared.Whoer.Init() Tick() end - ---@return table + ---@return string[] local function Count() local ret = {} for _, player in pairs(HeimdallStinkies) do @@ -375,6 +375,20 @@ function shared.Whoer.Init() ret[player.zone] = (ret[player.zone] or 0) + 1 end end + local text = {} + for zone, count in pairs(ret) do + text[#text + 1] = string.format("%s: %d", zone, count) + end + return text + end + ---@return string[] + local function Who() + local ret = {} + for _, player in pairs(HeimdallStinkies) do + if Heimdall_Data.config.who.zoneNotifyFor[player.zone] then + ret[#ret + 1] = string.format("%s (%s) %s", player.name, player.zone, player.stinky and "(!!!!)" or "") + end + end return ret end @@ -383,29 +397,20 @@ function shared.Whoer.Init() whoQueryWhisperFrame:SetScript("OnEvent", function(self, event, msg, sender) if not Heimdall_Data.config.who.enabled then return end if msg == "who" then - for _, player in pairs(HeimdallStinkies) do - local text = player:NotifyMessage() - ---@type Message - local msg = { - channel = "WHISPER", - data = sender, - message = text - } - table.insert(shared.messenger.queue, msg) - end - end - if msg == "howmany" then - local count = Count() - local text = "" - for zone, count in pairs(count) do - text = text .. string.format("%s: %d, ", zone, count) - end - text = text:sub(1, string.len(text) - 2) ---@type Message local msg = { channel = "WHISPER", data = sender, - message = text + message = strjoin(", ", unpack(Who())) + } + table.insert(shared.messenger.queue, msg) + end + if msg == "howmany" then + ---@type Message + local msg = { + channel = "WHISPER", + data = sender, + message = strjoin(", ", unpack(Count())) } table.insert(shared.messenger.queue, msg) end @@ -432,29 +437,20 @@ function shared.Whoer.Init() if channelname ~= Heimdall_Data.config.who.notifyChannel then return end if msg == "who" then - for _, player in pairs(HeimdallStinkies) do - local text = player:NotifyMessage() - ---@type Message - local msg = { - channel = "CHANNEL", - data = channelname, - message = text - } - table.insert(shared.messenger.queue, msg) - end - end - if msg == "howmany" then - local count = Count() - local text = "" - for zone, count in pairs(count) do - text = text .. string.format("%s: %d, ", zone, count) - end - text = text:sub(1, string.len(text) - 2) ---@type Message local msg = { channel = "CHANNEL", data = channelname, - message = text + message = strjoin(", ", unpack(Who())) + } + table.insert(shared.messenger.queue, msg) + end + if msg == "howmany" then + ---@type Message + local msg = { + channel = "CHANNEL", + data = channelname, + message = strjoin(", ", unpack(Count())) } table.insert(shared.messenger.queue, msg) end