全站通知:
模块:角色语音
刷
历
编
跳到导航
跳到搜索
数据库 模块:角色语音/voice.json
模块 模块:角色语音
local p = {}
-- 加载 JSON 数据
local jsonPage = mw.title.new('模块:角色语音/voice.json')
if not jsonPage or not jsonPage.exists then
return { main = function() return "" end } -- 返回空字符串,表示数据不存在
end
local jsonContent = jsonPage:getContent()
local success, data = pcall(mw.text.jsonDecode, jsonContent)
if not success then
return { main = function() return "" end } -- 返回空字符串,表示 JSON 解析失败
end
function p.main(frame)
local category = frame.args[1] or ""
local key = frame.args[2] or ""
-- 检查分类是否存在
if not data[category] then
return "" -- 返回空字符串,表示分类不存在
end
-- 尝试数字键,否则用字符串键
local numericKey = tonumber(key)
local actualKey = numericKey or key
local result = data[category][actualKey]
-- 检查关键词是否存在
if not result then
return "" -- 返回空字符串,表示关键词不存在
elseif type(result) == "table" then
return table.concat(result, ", ") -- 如果是数组,返回逗号分隔的字符串
else
return result -- 直接返回字符串
end
end
return p

沪公网安备 31011002002714 号