Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 218: | Строка 218: | ||
local ok, json = pcall(mw.text.jsonEncode, v) | local ok, json = pcall(mw.text.jsonEncode, v) | ||
if ok and json then | if ok and json then | ||
parts[#parts + 1] = key .. "=" .. | parts[#parts + 1] = key .. "=" .. to_nowiki(json) | ||
end | end | ||
else | else | ||
| Строка 475: | Строка 475: | ||
return result | return result | ||
end | |||
function p.hasComp(frame) | |||
local args = frame.args or {} | |||
local entityId = args[1] or "" | |||
local compName = args[2] or "" | |||
if entityId == "" or compName == "" then | |||
return "false" | |||
end | |||
local moduleName = "Module:IanComradeBot/component.json/data" | |||
local data = cache[moduleName] | |||
if not data then | |||
local ok, loaded = pcall(mw.loadData, moduleName) | |||
if not ok or not loaded then | |||
return "false" | |||
end | |||
data = loaded | |||
cache[moduleName] = data | |||
end | |||
if type(data) ~= "table" then | |||
return "false" | |||
end | |||
local entry = data[entityId] | |||
if type(entry) ~= "table" then | |||
return "false" | |||
end | |||
for _, v in ipairs(entry) do | |||
if tostring(v) == tostring(compName) then | |||
return "true" | |||
end | |||
end | |||
return "false" | |||
end | end | ||
return p | return p | ||