Update messenger to also accept channel names as args

This commit is contained in:
2024-11-29 19:07:19 +01:00
parent d325141929
commit f813e85755
2 changed files with 33 additions and 5 deletions

View File

@@ -7,12 +7,31 @@ function()
local message = WeakAurasSaved.Cyka.MessageQueue[1]
if message == nil then return end
-- Map channel names to ids
if message.channel == "CHANNEL" and string.match(message.data, "%D") then
print("Channel presented as string:", message.data)
local channelId = aura_env.channelIdMap[message.data]
if not channelId then
print("Channel not found, scanning")
aura_env.ScanChannels()
channelId = aura_env.channelIdMap[message.data]
end
if not channelId then
print("Channel not joined, joining")
channelId = aura_env.FindOrJoinChannel(message.data)
end
print("Channel resolved to id", channelId)
message.data = channelId
end
table.remove(WeakAurasSaved.Cyka.MessageQueue, 1)
SendChatMessage(message.message, message.channel, nil, message.data)
end
--INIT
local function FindOrJoinChannel(channelName, password)
---@type table<string, number>
aura_env.channelIdMap = {}
aura_env.FindOrJoinChannel = function(channelName, password)
local function GetChannelId(channelName)
local channels = {GetChannelList()}
for i = 1, #channels, 2 do
@@ -24,7 +43,7 @@ local function FindOrJoinChannel(channelName, password)
end
end
channelId = GetChannelId(channelName)
local channelId = GetChannelId(channelName)
if not channelId then
print("Channel", channelName, "not found, joining")
if password then
@@ -34,10 +53,19 @@ local function FindOrJoinChannel(channelName, password)
end
end
channelId = GetChannelId(channelName)
aura_env.channelIdMap[channelName] = channelId
return channelId
end
aura_env.channelId = FindOrJoinChannel(aura_env.config.channel, aura_env.config.channelPassword)
print("Channel", aura_env.config.channel, "resolved to id", aura_env.channelId)
aura_env.ScanChannels = function()
local channels = {GetChannelList()}
for i = 1, #channels, 2 do
local id = channels[i]
local name = channels[i + 1]
aura_env.channelIdMap[name] = id
end
end
local channelId = aura_env.FindOrJoinChannel(aura_env.config.channel, aura_env.config.channelPassword)
print("Channel", aura_env.config.channel, "resolved to id", channelId)
--aura_env.iterator = 0
--WeakAurasSaved.Cyka.MessageQueue = {}
--for i = 1, 100 do