diff --git a/Modules/Messenger.lua b/Modules/Messenger.lua index 035e8e7..2e006ca 100644 --- a/Modules/Messenger.lua +++ b/Modules/Messenger.lua @@ -10,9 +10,6 @@ function shared.Messenger.Init() ---@field channel string ---@field data string - ---@type table - local channelIdMap = {} - local function GetChannelId(channelName) local channels = { GetChannelList() } for i = 1, #channels, 2 do @@ -25,8 +22,8 @@ function shared.Messenger.Init() end local function FindOrJoinChannel(channelName, password) - local channelId = GetChannelId(channelName) - if not channelId then + local channelId = GetChannelName(channelName) + if channelId == 0 then print("Channel", tostring(channelName), "not found, joining") if password then JoinPermanentChannel(channelName, password) @@ -34,20 +31,10 @@ function shared.Messenger.Init() JoinPermanentChannel(channelName) end end - channelId = GetChannelId(channelName) - channelIdMap[channelName] = channelId + channelId = GetChannelName(channelName) 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 - ---@diagnostic disable-next-line: missing-fields if not shared.messenger then shared.messenger = {} end if not shared.messenger.queue then shared.messenger.queue = {} end @@ -60,17 +47,11 @@ function shared.Messenger.Init() 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") + 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)