5261
редагування
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 1: | Рядок 1: | ||
local p = {} | local p = {} | ||
-------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
-- | -- Функція: шукає у таблиці рядок, де друга колонка = player_name | ||
-------------------------------------------------------------------- | -- Повертає дані з column_index того ж рядка | ||
---------------------------------------------------------------------- | |||
local function fetch_data_from_table(page_title, player_name, column_index) | local function fetch_data_from_table(page_title, player_name, column_index) | ||
local title = mw.title.new(page_title) | local title = mw.title.new(page_title) | ||
| Рядок 11: | Рядок 13: | ||
if not content then return nil end | if not content then return nil end | ||
local table_content = mw.ustring.match(content, "{|.-|}") | local table_content = mw.ustring.match(content, "{|.-|}") | ||
if not table_content then return nil end | if not table_content then return nil end | ||
-- | -- Обробляємо можливі варіанти написання імені в таблиці | ||
local escaped = mw.ustring.gsub(player_name, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1") | local escaped = mw.ustring.gsub(player_name, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1") | ||
local player_pattern = | |||
local | |||
"%[%[" .. escaped .. "%]%]" .. | "%[%[" .. escaped .. "%]%]" .. | ||
"|%[%[" .. escaped .. "|.-%]%]" .. | "|%[%[" .. escaped .. "|.-%]%]" .. | ||
"|" .. escaped | "|" .. escaped | ||
local target_row = nil | |||
local | |||
for line in mw.ustring.gmatch(table_content, "[^\n]+") do | for line in mw.ustring.gmatch(table_content, "[^\n]+") do | ||
if mw.ustring.match(line, | if mw.ustring.match(line, player_pattern) then | ||
target_row = line | |||
break | break | ||
end | end | ||
end | end | ||
if not | if not target_row then return nil end | ||
-- | -- очищення "|-" | ||
target_row = mw.ustring.gsub(target_row, "^%s*|%-", "") | |||
-- | -- розбиття на комірки | ||
local cells = {} | local cells = {} | ||
for cell in mw.ustring.gmatch( | for cell in mw.ustring.gmatch(target_row, "%s*|%s*([^|]+)") do | ||
table.insert(cells, mw.text.trim(cell)) | table.insert(cells, mw.text.trim(cell)) | ||
end | end | ||
| Рядок 47: | Рядок 46: | ||
if not result then return nil end | if not result then return nil end | ||
-- | -- прибираємо [[link]] | ||
result = mw.ustring.gsub(result, "%[%[([^%]|]+)|?([^%]]*)%]%]", "%2") | result = mw.ustring.gsub(result, "%[%[([^%]|]+)|?([^%]]*)%]%]", "%2") | ||
result = mw.text.trim(result) | |||
result = result ~= "" and result or nil | |||
return | return result | ||
end | end | ||
-- | ---------------------------------------------------------------------- | ||
-- Рахує різницю в днях між датою у таблиці та 25.10.2024 | |||
local | ---------------------------------------------------------------------- | ||
return | |||
local function getDaysDifference(dateString) | |||
if not dateString then return "" end | |||
local d, m, y = dateString:match("(%d%d)%.(%d%d)%.(%d%d%d%d)") | |||
if not d then return dateString end | |||
local start = os.time({day = d, month = m, year = y}) | |||
local finish = os.time({day = 25, month = 10, year = 2024}) | |||
local diff = math.floor((finish - start) / 86400) | |||
return string.format("%s (%d днів)", dateString, diff) | |||
end | end | ||
-- | |||
function p. | ---------------------------------------------------------------------- | ||
local name = | -- ДАНІ З ТАБЛИЦІ "Гравці" | ||
return fetch_data_from_table("Гравці", name, 4) or " | ---------------------------------------------------------------------- | ||
function p.recruiter(frame) | |||
local name = mw.title.getCurrentTitle().text | |||
return fetch_data_from_table("Гравці", name, 4) or "Невідомо" | |||
end | end | ||
function p.date_added(frame) | |||
function p. | local name = mw.title.getCurrentTitle().text | ||
local name = | local raw_date = fetch_data_from_table("Гравці", name, 3) | ||
return raw_date and getDaysDifference(raw_date) or "Невідомо" | |||
end | end | ||
-- | |||
function p. | ---------------------------------------------------------------------- | ||
local name = | -- ДАНІ З ТАБЛИЦІ "Призовий_фонд" | ||
return fetch_data_from_table("Призовий_фонд", name, | ---------------------------------------------------------------------- | ||
function p.prize_pool(frame) | |||
local name = mw.title.getCurrentTitle().text | |||
return fetch_data_from_table("Призовий_фонд", name, 3) or "0" | |||
end | end | ||
-- | |||
function p. | ---------------------------------------------------------------------- | ||
local name = | -- ДАНІ З ТАБЛИЦІ "Фундація" | ||
return fetch_data_from_table(" | ---------------------------------------------------------------------- | ||
function p.foundation(frame) | |||
local name = mw.title.getCurrentTitle().text | |||
return fetch_data_from_table("Фундація", name, 2) or "0" | |||
end | end | ||
-- | |||
function p. | ---------------------------------------------------------------------- | ||
local name = | -- ДАНІ З ТАБЛИЦІ "Фіналіст" | ||
return fetch_data_from_table(" | ---------------------------------------------------------------------- | ||
function p.final(frame) | |||
local name = mw.title.getCurrentTitle().text | |||
return fetch_data_from_table("Фіналіст", name, 2) or "Ні" | |||
end | end | ||
return p | return p | ||