Assemble messenger properly

This commit is contained in:
2024-12-12 12:55:26 +01:00
parent 22c5e6b1c3
commit af2bb157bd

View File

@@ -8,48 +8,6 @@ local _, data = ...
---@type table<string, number> ---@type table<string, number>
local channelIdMap = {} 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 FindOrJoinChannel = function(channelName, password)
local function GetChannelId(channelName) local function GetChannelId(channelName)
@@ -65,7 +23,7 @@ local FindOrJoinChannel = function(channelName, password)
local channelId = GetChannelId(channelName) local channelId = GetChannelId(channelName)
if not channelId then if not channelId then
print("Channel", channelName, "not found, joining") print("Channel", tostring(channelName), "not found, joining")
if password then if password then
JoinPermanentChannel(channelName, password) JoinPermanentChannel(channelName, password)
else else
@@ -84,4 +42,48 @@ local ScanChannels = function()
local name = channels[i + 1] local name = channels[i + 1]
channelIdMap[name] = id channelIdMap[name] = id
end end
end end
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()
---@type Message
local message = data.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
-- 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.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)
end
--C_Timer.NewTicker(2, function()
-- print("Q")
-- table.insert(data.messenger.queue, {
-- channel = "CHANNEL",
-- data = "Foobar",
-- message = "TEST"
-- })
--end)