Модуль:Entity Tags
Материал из Space Station 14 Вики
Для документации этого модуля может быть создана страница Модуль:Entity Tags/doc
local p = {}
local tagsData = mw.loadData("Модуль:IanComradeBot/prototypes/entity tags.json/data") or {}
function p.main(frame)
local args = frame.args
local mode = args[1] or ""
local searchParam = args[2] or ""
if searchParam == "" then
return "Ошибка: не указан параметр поиска."
end
if mode == "id" then
for _, entry in ipairs(tagsData) do
if entry.id == searchParam then
if entry.Tag and type(entry.Tag.tags) == "table" then
local tagList = {}
for _, tag in ipairs(entry.Tag.tags) do
table.insert(tagList, "* " .. tag)
end
return "ID: " .. entry.id .. "\nТеги:\n" .. table.concat(tagList, "\n")
else
return "Теги не найдены для id «" .. searchParam .. "»."
end
end
end
return "Запись с id «" .. searchParam .. "» не найдена."
elseif mode == "tag" then
local foundIds = {}
for _, entry in ipairs(tagsData) do
if entry.Tag and type(entry.Tag.tags) == "table" then
for _, tag in ipairs(entry.Tag.tags) do
if tag == searchParam then
table.insert(foundIds, entry.id)
break
end
end
end
end
if #foundIds > 0 then
return "Найденные ID:\n* " .. table.concat(foundIds, "\n* ")
else
return "Нет записей с тегом «" .. searchParam .. "»."
end
else
return "Ошибка: неизвестный режим поиска («" .. mode .. "»). Используйте «id» или «tag»."
end
end
return p