---@type HeimdallData local _, data = ... ---@class Message ---@field message string ---@field channel string ---@field data string ---@type table local channelIdMap = {} if not data.messenger then data.messenger = {} end if not data.messenger.queue then data.messenger.queue = {} end if not data.messenger.ticker then data.messenger.ticker = C_Timer.NewTicker(0.2, function() print("AAAAAAAAAA") ---@type Message local message = data.messenger.queue[1] data.dumpTable(message) if not message then return end if not message.message or message.message == "" then return end if not message.channel or message.channel == "" then return end -- -- Map channel names to ids -- if message.channel == "CHANNEL" and message.data and string.match(message.data, "%D") then -- print("Channel presented as string:", message.data) -- local channelId = channelIdMap[message.data] -- if not channelId then -- print("Channel not found, scanning") -- ScanChannels() -- channelId = channelIdMap[message.data] -- end -- if not channelId then -- print("Channel not joined, joining") -- channelId = FindOrJoinChannel(message.data) -- end -- print("Channel resolved to id", channelId) -- message.data = channelId -- end -- -- table.remove(data.messengerQueue, 1) -- SendChatMessage(message.message, message.channel, nil, message.data) end) end C_Timer.Ticker(2, function() print("Q") table.insert(data.messenger.queue, { channel = "Foobar", data = "CHANNEL", message = "TEST" }) end) local FindOrJoinChannel = function(channelName, password) local function GetChannelId(channelName) local channels = { GetChannelList() } for i = 1, #channels, 2 do local id = channels[i] local name = channels[i + 1] if name == channelName then return id end end end local channelId = GetChannelId(channelName) if not channelId then print("Channel", channelName, "not found, joining") if password then JoinPermanentChannel(channelName, password) else JoinPermanentChannel(channelName) end end channelId = GetChannelId(channelName) channelIdMap[channelName] = channelId return channelId end local ScanChannels = function() local channels = { GetChannelList() } for i = 1, #channels, 2 do local id = channels[i] local name = channels[i + 1] channelIdMap[name] = id end end