5261
редагування
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 10: | Рядок 10: | ||
local function clean_wikilinks(text) | local function clean_wikilinks(text) | ||
if not text then return nil end | if not text then return nil end | ||
-- [[link|text]] -> text | |||
text = mw.ustring.gsub(text, "%[%[([^%]|]+)|([^%]]+)%]%]", "%2") | text = mw.ustring.gsub(text, "%[%[([^%]|]+)|([^%]]+)%]%]", "%2") | ||
-- [[link]] -> link | |||
text = mw.ustring.gsub(text, "%[%[([^%]]+)%]%]", "%1") | text = mw.ustring.gsub(text, "%[%[([^%]]+)%]%]", "%1") | ||
return mw.text.trim(text) | return mw.text.trim(text) | ||
| Рядок 16: | Рядок 18: | ||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
-- ГОЛОВНИЙ ПОШУК ( | -- ГОЛОВНИЙ ПОШУК (Виправлено парсинг, використовує ім'я гравця) | ||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
local function fetch_from_table(page_title, | local function fetch_from_table(page_title, player_name, column_index) | ||
if not player_name or player_name == "" then | if not player_name or player_name == "" then | ||
return error_output("No Player Name | -- Повертаємо помилку, якщо ім'я гравця не передано | ||
return error_output("No Player Name", page_title) | |||
end | end | ||
| Рядок 35: | Рядок 36: | ||
if not content then return error_output("Content Read Fail", page_title) end | if not content then return error_output("Content Read Fail", page_title) end | ||
-- Шукаємо вміст таблиці | |||
local table_content = mw.ustring.match(content, "{|.-([|].-.-[|]})") | local table_content = mw.ustring.match(content, "{|.-([|].-.-[|]})") | ||
if not table_content then | if not table_content then | ||
| Рядок 41: | Рядок 43: | ||
local escaped = mw.ustring.gsub(player_name, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1") | local escaped = mw.ustring.gsub(player_name, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1") | ||
-- Шукаємо гравця у форматі [[Player]] | |||
local player_pattern = "%[%[" .. escaped .. "%]%]" | local player_pattern = "%[%[" .. escaped .. "%]%]" | ||
| Рядок 48: | Рядок 51: | ||
for row in mw.ustring.gmatch(table_content, "\n%s*|-[^%s]*\n(.-)") do | for row in mw.ustring.gmatch(table_content, "\n%s*|-[^%s]*\n(.-)") do | ||
-- Перевіряємо, чи містить рядок ім'я гравця | -- Перевіряємо, чи містить рядок ім'я гравця | ||
if mw.ustring.find(row, player_pattern, 1, true) then | if mw.ustring.find(row, player_pattern, 1, true) then | ||
-- --- ПОКРАЩЕНА ЛОГІКА ПАРСИНГУ КОМІРОК --- | |||
local cell_data = {} | local cell_data = {} | ||
-- 1. Видаляємо маркер початку рядка (пробіли та перший '|') | |||
local cleaned_row = mw.ustring.gsub(row, "^%s*[|]%s*", "") | |||
-- 2. Розділяємо рядок за '||'. Це надійно захоплює всі комірки. | |||
local cell_parts = mw.text.split(cleaned_row, '||') | |||
-- 3. Обрізаємо пробіли для кожної частини і заповнюємо cell_data | |||
for _, cell in ipairs(cell_parts) do | |||
table.insert(cell_data, mw.text.trim(cell)) | |||
-- | |||
end | end | ||
-- --- КІНЕЦЬ ПОКРАЩЕНОЇ ЛОГІКИ --- | |||
-- | -- Перевіряємо, що ми знайшли [[Player]] саме в Колонці 2 | ||
if #cell_data >= 2 and mw.ustring.find(cell_data[2], player_pattern) then | if #cell_data >= 2 and mw.ustring.find(cell_data[2], player_pattern) then | ||
| Рядок 82: | Рядок 75: | ||
if column_index <= #cell_data and cell_data[column_index] then | if column_index <= #cell_data and cell_data[column_index] then | ||
result = clean_wikilinks(cell_data[column_index]) | result = clean_wikilinks(cell_data[column_index]) | ||
break -- Знайшли, виходимо | break -- Знайшли, виходимо | ||
end | end | ||
end | end | ||
| Рядок 92: | Рядок 85: | ||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
-- ФУНКЦІЇ ДЛЯ {{MCC Player New}} ( | -- ФУНКЦІЇ ДЛЯ {{MCC Player New}} (використовують fetch_from_table) | ||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
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) | local raw = fetch_from_table("Гравці", name, 4) -- Колонка 4 | ||
if type(raw) == "string" and mw.ustring.find(raw, "Error") then return raw end | if type(raw) == "string" and mw.ustring.find(raw, "Error") then return raw end | ||
| Рядок 107: | Рядок 100: | ||
function p.date_added(frame) | function p.date_added(frame) | ||
local name = frame.args.player | local name = frame.args.player | ||
local raw = fetch_from_table("Гравці", name, 3) | local raw = fetch_from_table("Гравці", name, 3) -- Колонка 3 | ||
if type(raw) == "string" and mw.ustring.find(raw, "Error") then return raw end | if type(raw) == "string" and mw.ustring.find(raw, "Error") then return raw end | ||
| Рядок 155: | Рядок 148: | ||
end | end | ||
-- Ця функція залишається порожньою, як ви просили на початку, щоб не чіпати сезони | |||
function p.season_result(frame) | function p.season_result(frame) | ||
return nil | return nil | ||