local addonname, shared = ... ---@cast shared HeimdallShared ---@cast addonname string local ModuleName = "Noter" ---@class Note ---@field source string ---@field for string ---@field date string ---@field note string ---@diagnostic disable-next-line: missing-fields shared.Noter = {} function shared.Noter.Init() ---@param text string ---@param size number ---@return string[] local function Partition(text, size) local words = {} for word in text:gmatch("[^,]+") do words[#words + 1] = word end local ret = {} 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 -- Here's the plan: -- Implement a "note" command, that will do everything -- Saying "note " will add a note to the list for the character -- Saying "note " will list last N notes -- Saying "note i" will list the i-th note -- Saying "note i..j" will list notes from i to j -- Saying "note delete i" will delete the i-th note -- Saying "note delete i..j" will delete notes from i to j local noterChannelFrame = CreateFrame("Frame") noterChannelFrame:RegisterEvent("CHAT_MSG_CHANNEL") noterChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...) --if Heimdall_Data.config.noter.debug then -- print(string.format("[%s] Event received", ModuleName)) -- shared.dumpTable(Heimdall_Data.config.noter) --end if not Heimdall_Data.config.noter.enabled then --if Heimdall_Data.config.noter.debug then -- print(string.format("[%s] Module disabled, ignoring event", ModuleName)) --end return end local channelId = select(6, ...) local _, channelname = GetChannelName(channelId) --if Heimdall_Data.config.noter.debug then -- print(string.format("[%s] Channel received: %s", ModuleName, channelname)) --end if channelname ~= Heimdall_Data.config.noter.masterChannel then --if Heimdall_Data.config.noter.debug then -- print(string.format("[%s] Channel %s does not match master channel %s", ModuleName, channelname, Heimdall_Data.config.noter.masterChannel)) --end return end sender = string.match(sender, "^[^-]+") if Heimdall_Data.config.noter.debug then print(string.format("[%s] Message from: %s", ModuleName, sender)) shared.dumpTable(Heimdall_Data.config.noter) end for _, command in ipairs(commands) do local enabled = Heimdall_Data.config.noter.commands[command.keywordRe] == true or false if Heimdall_Data.config.noter.debug then print(string.format("[%s] Command match: %s = %s", ModuleName, command.keywordRe, tostring(enabled))) end if enabled and (not command.commanderOnly or (command.commanderOnly and sender == Heimdall_Data.config.noter.commander)) then if msg:match(command.keywordRe) then local messages = command.callback({ strsplit(",", msg) }) if Heimdall_Data.config.noter.debug then print(string.format("[%s] Messages to send: %s", ModuleName, strjoin(", ", unpack(messages)))) end for _, message in ipairs(messages) do ---@type Message local msg = { channel = "CHANNEL", data = channelname, message = message } table.insert(shared.messenger.queue, msg) end end end end end) print("[Heimdall] Commander module loaded") end