打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

Module:萌点

来自OGAS数据中枢

此模块的文档可以在Module:萌点/doc创建

local p = {}
local getArgs = require('Module:Arguments').getArgs
--local data = mw.loadJsonData('User:Liliaceae/MDJSON')

local data = mw.loadData('Module:萌点/data')
local splitString = require('Module:Split2')
--local stringx = require('Module:String')

function p.trim(x)
    --local pattern = "^(%s*)(.*)(%(.*%))(%s*)$"
    local pattern = "[%s]*[(][^))\n]*[)][%s]*$"
    local result, _ = mw.ustring.gsub(x, pattern, "", 1)
    return result
end
function p.proc(str1, control, frame)
	local ret = ''
	if control == '黑幕' or control == 'heimu' then
		ret = frame:expandTemplate{title = "黑幕", args = {str1}}
	elseif control == 'del' then
		ret = '<del>' .. str1 .. '</del>'
	elseif control == '加粗' or control == 'b' then
		ret = "'''" .. str1 .. "'''"
	else
		ret = str1
	end
	return ret
end
function p.proc2(str)
	--Link Rules
	--Part 1: Directly Map
	if data.link_rules.direct_mapping[str] ~= nil then
		return data.link_rules.direct_mapping[str]
	end
	if data.link_rules.suffix_mapping[str] ~= nil then
		return str .. "(" .. data.link_rules.suffix_mapping[str] .. ")"
	end
	if data.link_rules.special_professions[str] ~= nil then
		return str .. "(萌属性)"
	end	
	return "0"
end

function p.proc3(name, rawname, link, frame)
	--Cat Rules
	ret = ""
	--Need Check
	test1 = p.trim(rawname)
	--if data.skip_check[link] == nil and test1 ~= rawname then
	--	local title1 = mw.title.new(link)
	--	if title1.exists == true then
	--		ret = ret .. frame:expandTemplate{title = "ac", args = {"需要检查的萌点模板使用"}}
	--	end
	--end
	if test1 == name and link ~= name and data.skip_check[link] ~= nil or data.category_rules.use_link_value[name] ~= nil then -- 直接处理
		return ret .. frame:expandTemplate{title = "ac", args = {link}}
	end
	-- 能力者
	if mw.ustring.match(name, "能力", 1) ~= nil then
		local flag = 0
		for _, k in ipairs(data.ability_exceptions.patterns) do
			local result = mw.ustring.match(name, k, 1)
			if result ~= nil then
				flag = 1
			end
		end
		if flag == 0 then
			return ret .. frame:expandTemplate{title = "ac", args = {link .. "者"}}
		end
	end
	-- 两类特殊处理
	if data.special_handling.preserve_suffix[link] ~= nil then
		return frame:expandTemplate{title = "ac", args = {link}}
	end
	-- 直接对应
	if data.category_rules.direct_mapping[name] ~= nil then
		return ret .. frame:expandTemplate{title = "ac", args = {data.category_rules.direct_mapping[name]}}
	end
	if data.category_rules.suffix_mapping[name] ~= nil then
		return ret .. frame:expandTemplate{title = "ac", args = {name .. "(" .. data.category_rules.suffix_mapping[name] .. ")"}}
	end
	-- 默认规则
	local trim0 = p.trim(link)
	return ret .. frame:expandTemplate{title = "ac", args = {trim0}}
end
function p._main(args, frame)
	local arg = args
	code = ''
	counter = 0
	for index, moe in pairs(arg) do
		--Link Rules
		local done1 = 0
		local needSJ = 0
		if counter > 0 then
			code = code .. '、'
		end
		--local result = mw.ustring.find( moe, "_N", 1)
		--if result == 1 then
		--	result, _ = mw.ustring.gsub(moe, "_N", "", 1)
		--	code = code .. frame:expandTemplate{title = "User:Liliaceae/T:Moe", args = {result}}
		--	done1 = 1
		--end
		if done1 ~= 1 then 
			local moe1 = splitString.split(moe, '[,,]', 1)
			local moe2 = moe1.parts
			local link = ""
			local name = ""
			local rawname = ""
			if moe1.count == 1 or moe1.count == 2 then
				local procres = p.proc2(moe2[1])
				rawname = moe2[1]
				name = p.trim(moe2[1])
				if procres ~= "0" then
					link = procres
					procres = procres .. "|" .. name
				else
					if moe2[1] ~= name then
						procres = moe2[1] .. "|" .. name
					else
						procres = moe2[1]
					end
					link = moe2[1]
				end
				if data.special_handling.preserve_suffix[moe2[1]] ~= nil then
					link = moe2[1]
					name = moe2[1]
					procres = moe2[1]
				end
				local todo = '[[' .. procres .. ']]'
				if moe1.count == 2 then
					local todo2 = p.proc(todo, moe2[2], frame)
					if todo2 ~= todo then
						todo = todo2
					else
						needSJ = 1
					end
				end
				if needSJ ~= 1 then
					local cat = p.proc3(name, rawname, link, frame)
					code = code .. todo .. cat
				end
			end
			if moe1.count == 3 or needSJ == 1 then
				rawname = moe2[1]
				local procres = p.proc2(moe2[1])
				if procres == "0" then
					procres = moe2[1]
				end
				link = procres
				name = moe2[2]
				todo = '[[' .. procres .. '|' .. moe2[2] .. ']]'
				if needSJ ~= 1 then
					todo = p.proc(todo, moe2[3], frame)
				end
				local cat = ""
				if needSJ == 1 then
					cat = p.proc3(rawname, rawname, link, frame)
				else
					cat = p.proc3(name, rawname, link, frame)
				end
				code = code .. todo .. cat
			end
			--Cat Rules
		end
		counter = counter + 1
	end
    return code
end

function p.main(frame)
	local args = getArgs(frame, {
		parentFirst = true,
	})
    return p._main(args, frame)
end

return p