5261
редагування
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 99: | Рядок 99: | ||
function p.recruiter(frame) | function p.recruiter(frame) | ||
local name = frame.args.player | local name = frame.args.player | ||
local | -- 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 | |||
local last_row = mw.ustring.match(table_content, "|-\n(.-)%s*|}") | |||
if last_row then | |||
table.insert(rows, last_row) | |||
end | end | ||
if raw == "Відсутній" or raw == "-" | for _, row in ipairs(rows) do | ||
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 | return "Не вказано" | ||
end | end | ||