local addonname, shared = ... ---@cast shared HeimdallShared ---@cast addonname string ---@diagnostic disable-next-line: missing-fields shared.Messenger = {} function shared.Messenger.Init() ---@class Message ---@field message string ---@field channel string ---@field data string 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 function FindOrJoinChannel(channelName, password) local channelId = GetChannelName(channelName) if channelId == 0 then print("Channel", tostring(channelName), "not found, joining") if password then JoinPermanentChannel(channelName, password) else JoinPermanentChannel(channelName) end end channelId = GetChannelName(channelName) return channelId end ---@diagnostic disable-next-line: missing-fields if not shared.messenger then shared.messenger = {} end if not shared.messenger.queue then shared.messenger.queue = {} end if not shared.messenger.ticker then local function DoMessage() if not Heimdall_Data.config.messenger.enabled then return end ---@type Message local message = shared.messenger.queue[1] 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 if message.channel == "CHANNEL" and message.data and string.match(message.data, "%D") then print("Channel presented as string:", message.data) local channelId = GetChannelName(message.data) if channelId == 0 then print("Channel not found, joining") channelId = FindOrJoinChannel(message.data) end print("Channel resolved to id", channelId) message.data = tostring(channelId) end table.remove(shared.messenger.queue, 1) if not message.message or message.message == "" then return end if not message.channel or message.channel == "" then return end if not message.data or message.data == "" then return end SendChatMessage(message.message, message.channel, nil, message.data) end local function Tick() DoMessage() shared.messenger.ticker = C_Timer.NewTimer(Heimdall_Data.config.messenger.interval, Tick, 1) end Tick() end --C_Timer.NewTicker(2, function() -- print("Q") -- table.insert(data.messenger.queue, { -- channel = "CHANNEL", -- data = "Foobar", -- message = "TEST" -- }) --end) print("Heimdall - Messenger loaded") end