Модуль:FetchData2: відмінності між версіями

нема опису редагування
Немає опису редагування
Немає опису редагування
Рядок 99: Рядок 99:
function p.recruiter(frame)
function p.recruiter(frame)
     local name = frame.args.player
     local name = frame.args.player
     local raw = fetch_from_table("Гравці", name, 4)  
    -- Don't clean wikilinks - keep them for clickable links
     local title = mw.title.new("Гравці")
    if not title or not title.exists then
        return error_output("Page Missing", "Гравці")
    end
   
    local content = title:getContent()
    if not content then
        return error_output("Content Read Fail", "Гравці")
    end
   
    local table_start = mw.ustring.find(content, "{|")
    local table_end = mw.ustring.find(content, "|}", table_start)
   
    if not table_start or not table_end then
        return error_output("Table Missing", "Гравці")
    end
   
    local table_content = mw.ustring.sub(content, table_start, table_end + 1)
    local escaped = mw.ustring.gsub(name, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1")
    local player_pattern = "%[%[" .. escaped .. "%]%]"
   
    local rows = {}
    for row in mw.ustring.gmatch(table_content, "|-\n(.-)\n|-") do
        table.insert(rows, row)
    end
      
      
     if type(raw) == "string" and mw.ustring.find(raw, "Error") then  
     local last_row = mw.ustring.match(table_content, "|-\n(.-)%s*|}")
         return raw
    if last_row then
         table.insert(rows, last_row)
     end
     end
      
      
     if raw == "Відсутній" or raw == "-" or not raw then  
     for _, row in ipairs(rows) do
        return "Не вказано"  
        if mw.ustring.find(row, player_pattern) then
            local cells = {}
            row = mw.ustring.gsub(row, "^%s*|%s*", "")
           
            for cell in mw.ustring.gmatch(row, "([^|]+)") do
                local trimmed = mw.text.trim(cell)
                if trimmed ~= "" then
                    table.insert(cells, trimmed)
                end
            end
           
            if 4 <= #cells then
                local raw = mw.text.trim(cells[4])
                if raw == "Відсутній" or raw == "-" then  
                    return "Не вказано"  
                end
                -- Return with wikilinks intact
                return raw
            end
        end
     end
     end
      
      
     return raw
     return "Не вказано"
end
end