2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

Module:VOCALOID殿堂曲/Random Song

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索
Template-info.svg 模块文档  [创建] [刷新]
local module = {}

local getArgs = require('Module:Arguments').getArgs

function getRandomNumber(mtr6)
	local max = tonumber(mtr6)
	local ran = math.random(1, max) + tonumber(os.time())
	return ran % max
end

function random_count(count, mtr6, content_table)
	local result = {}
	repeat
		local ran = getRandomNumber(mtr6)
		result[#result + 1] = content_table[ran]
	until (#result >= count)

	return table.concat(result, "\n")
end

function module.temple(args, frame)
	local titleName = args['page'] or ''
	local title = mw.title.new(titleName)
	local content_before = title:getContent()
	local mtr1, mtr2 = string.gsub(content_before, "Temple ?_?Song", "")

	local content_table = {}
	local pattern = "{{Temple ?_?Song.-|image.-}}\n"
	local mtr4 = content_before
	for i = 1, mtr2, 1 do
		local mtr3 = string.match(mtr4, pattern)
		mtr4 = string.gsub(mtr4, pattern, "", 1)
		content_table[i] = mtr3
	end

	local count = tonumber(args['count']) or 6
	local mtr5 = random_count(count, mtr2, content_table)
	--local content = frame:preprocess(content_before)
	return frame:preprocess(mtr5)
end

function module.templemain(frame)
	local args = getArgs(frame)
	return module.temple(args, frame)
end

return module