Модуль:Песочница/Pok: различия между версиями

м Содержимое страницы заменено на «local p = {} local frame = mw.getCurrentFrame() function p.listUncategorizedGIFs() local uncategorized = {} local allFiles = mw.site.allPages('', 'File') for title in allFiles do local filename = title.text if filename:match("%.gif$") then local file = mw.title.new('File:' .. filename) if file then local content = file:getContent() if content and not content:match('%[%[Category:') then table.insert(...»
Метка: замена
мНет описания правки
Строка 1: Строка 1:
-- Загрузка данных
local priceData = mw.loadData("Модуль:IanComradeBot/prototypes/StaticPrice.json/data")
local p = {}
local p = {}
local frame = mw.getCurrentFrame()


function p.listUncategorizedGIFs()
function p.main(frame)
local uncategorized = {}
    -- Получаем первый параметр, который должен быть id
local allFiles = mw.site.allPages('', 'File')
    local id = frame.args[1] or frame.args.id
    if not id then
        return "Ошибка: не передан id"
    end


for title in allFiles do
    -- Проходим по всем записям в priceData
local filename = title.text
    for _, item in ipairs(priceData) do
if filename:match("%.gif$") then
        if item.id == id then
local file = mw.title.new('File:' .. filename)
            return frame:preprocess("{{ColorPalette|Other|price|" .. item.StaticPrice.price .. "}}$")
if file then
        end
local content = file:getContent()
    end
if content and not content:match('%[%[Category:') then
table.insert(uncategorized, '* [[:File:' .. filename .. ']]')
end
end
end
end


if #uncategorized == 0 then
    -- Если не нашли совпадение, возвращаем стандартный текст
return 'Все gif-файлы категоризированы.'
    return frame:preprocess("нет")
end
end


return table.concat(uncategorized, '\n')
function p.table(frame)
    local output = {}
    table.insert(output, '{| class="wikitable"')
    for _, item in ipairs(priceData) do
        local name = frame:preprocess('{{#invoke:Entity Lookup|getname|' .. item.id .. '}}')
        local price = frame:preprocess('{{ColorPalette|Other|price|' .. item.StaticPrice.price .. '}}') .. '$'
        table.insert(output, '|-')
        table.insert(output, '| {{Cut-Layout|' .. name .. '|' .. price .. '}}')
    end
    table.insert(output, '|}')
    return frame:preprocess(table.concat(output, "\n"))
end
end


return p
return p