|
Мітки: Очищення Ручний відкіт |
| (Не показано 49 проміжних версій цього користувача) |
| Рядок 1: |
Рядок 1: |
| local p = {}
| |
|
| |
|
| --------------------------------------------------------------------
| |
| -- UNIVERSAL TABLE PARSER
| |
| --------------------------------------------------------------------
| |
| local function fetch_data_from_table(page_title, player_name, column_index)
| |
| local title = mw.title.new(page_title)
| |
| if not title then return nil end
| |
|
| |
| local content = title:getContent()
| |
| if not content then return nil end
| |
|
| |
| -- Беремо будь-яку wikitable
| |
| local table_content = mw.ustring.match(content, "{|.-|}")
| |
| if not table_content then return nil end
| |
|
| |
| -- Escape special chars
| |
| local escaped = mw.ustring.gsub(player_name, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1")
| |
|
| |
| -- Патерн для пошуку імені
| |
| local name_pattern =
| |
| "%[%[" .. escaped .. "%]%]" ..
| |
| "|%[%[" .. escaped .. "|.-%]%]" ..
| |
| "|" .. escaped
| |
|
| |
| -- Знаходимо рядок
| |
| local row = nil
| |
| for line in mw.ustring.gmatch(table_content, "[^\n]+") do
| |
| if mw.ustring.match(line, name_pattern) then
| |
| row = line
| |
| break
| |
| end
| |
| end
| |
|
| |
| if not row then return nil end
| |
|
| |
| -- Чистимо від |-
| |
| row = mw.ustring.gsub(row, "^%s*|%-", "")
| |
|
| |
| -- Розбиваємо комірки
| |
| local cells = {}
| |
| for cell in mw.ustring.gmatch(row, "%s*|%s*([^|]+)") do
| |
| table.insert(cells, mw.text.trim(cell))
| |
| end
| |
|
| |
| local result = cells[column_index]
| |
| if not result then return nil end
| |
|
| |
| -- Забираємо вікі-лінки
| |
| result = mw.ustring.gsub(result, "%[%[([^%]|]+)|?([^%]]*)%]%]", "%2")
| |
| if result == "" then
| |
| result = mw.ustring.gsub(result, "%[%[([^%]]+)%]%]", "%1")
| |
| end
| |
|
| |
| return mw.text.trim(result)
| |
| end
| |
|
| |
| --------------------------------------------------------------------
| |
| -- PUBLIC FUNCTIONS
| |
| --------------------------------------------------------------------
| |
|
| |
| -- 1) Дата приєднання
| |
| function p.join_date(frame)
| |
| local name = frame.args[1]
| |
| return fetch_data_from_table("Гравці", name, 3) or "Невідомо"
| |
| end
| |
|
| |
| -- 2) Провідник
| |
| function p.leader(frame)
| |
| local name = frame.args[1]
| |
| return fetch_data_from_table("Гравці", name, 4) or "Відсутній"
| |
| end
| |
|
| |
| -- 3) Фундація
| |
| function p.fund(frame)
| |
| local name = frame.args[1]
| |
| return fetch_data_from_table("Фундація", name, 2) or "0"
| |
| end
| |
|
| |
| -- 4) Призовий фонд
| |
| function p.prize(frame)
| |
| local name = frame.args[1]
| |
| return fetch_data_from_table("Призовий_фонд", name, 2) or "0"
| |
| end
| |
|
| |
| -- 5) Фіналіст
| |
| function p.finalist(frame)
| |
| local name = frame.args[1]
| |
| return fetch_data_from_table("Фіналіст", name, 2) or "Невідомо"
| |
| end
| |
|
| |
| -- 6) Титул
| |
| function p.title(frame)
| |
| local name = frame.args[1]
| |
| return fetch_data_from_table("Гравці", name, 5) or "Відсутній"
| |
| end
| |
|
| |
| --------------------------------------------------------------------
| |
| -- EXPORT MODULE
| |
| --------------------------------------------------------------------
| |
| return p
| |