---@type mw
local mw = mw
local p = {}
local getArgs = require('Module:Arguments').getArgs
---@param frame Frame
function p.main(frame)
---@type table<string, string|nil>
local args = getArgs(frame)
local avatMap = {}
local rStudList = {}
local listLen = 0
local lastStudent = 1
local messages = {}
for i = 1, 100, 1 do
local from = args[tostring(i)]
if from == nil then
break
end
local mtype = args['type' .. i]
local content = args['content' .. i] or ''
content = string.gsub(content, "=", "{{=}}")
local mtitle = args['title' .. i]
if from == "t" then
if mtype == 'rep' then
local chooses = {}
for j = 1, 10, 1 do
local opt = args['choose' .. i .. '_' .. j]
if opt == nil then
break
end
table.insert(chooses, opt)
end
local line = string.format('|c|%s|%s|end', content or mtitle or '',
table.concat(chooses, '|'))
table.insert(messages, line)
elseif mtype == 'kzn' then
local line = string.format('|k|%s|%s', mtitle or '', content)
table.insert(messages, line)
else
table.insert(messages, string.format("|t|%s", content))
end
elseif from == 's' or from == 'ss' then
local mName = args['name' .. i]
if mName ~= nil then
if rStudList[mName] == nil then
local mAvat = args['avatar' .. i]
avatMap[mName] = mAvat
listLen = listLen + 1
lastStudent = listLen
rStudList[mName] = lastStudent
else
lastStudent = rStudList[mName]
end
end
if mtype == 'img' then
local line = string.format("|i|%d|%s", lastStudent, content)
table.insert(messages, line)
else
local line = string.format("|s|%d|%s", lastStudent, content)
table.insert(messages, line)
end
end
end
local studSetting = {}
for n, i in pairs(rStudList) do
local sAvat = avatMap[n]
table.insert(studSetting, string.format('|talker_%d = %s', i, n))
table.insert(studSetting, string.format('|talker_avatar_%d = %s', i, sAvat))
end
return string.format("{{MomoTalkPro\n%s\n%s\n}}", table.concat(studSetting, '\n'),
table.concat(messages, '\n'))
end
return p