|
|
| (Не показано одну проміжну версію цього користувача) |
| Рядок 1: |
Рядок 1: |
| local p = {} | | local p = {} |
|
| |
|
| local TARGET_DATE_STR = "25.10.2024"
| | -- ================================================ |
| local TARGET_TIMESTAMP = os.time({year=2024, month=10, day=25, hour=0, min=0, sec=0})
| | -- КЕШУВАННЯ |
| | -- ================================================ |
|
| |
|
| local function fetch_data_from_table(page_title, player_name, column_index) | | local page_cache = {} |
| local title = mw.title.new(page_title)
| |
| local content = title and title:getContent()
| |
|
| |
|
| if not content then
| | local function get_page_content(page_name) |
| return nil
| | if page_cache[page_name] then |
| end
| | return page_cache[page_name] |
| | |
| local table_content = mw.ustring.match(content, "{|%s*class%s*=%s*\"wikitable\"(.-)|}")
| |
| if not table_content then | |
| table_content = mw.ustring.match(content, "{|(.+?)|}")
| |
| end
| |
| | |
| if not table_content then
| |
| return nil | |
| end
| |
| | |
| local escaped_player = mw.ustring.gsub(player_name, "([%(%)%.%-%+%[%]])", "%%%1")
| |
|
| |
| local player_link_pattern = "%[?%[" .. escaped_player .. "%]%]?"
| |
|
| |
| -- Використовуємо більш гнучкий пошук, очікуючи на |...||...||
| |
|
| |
| local row_pattern_link = "[|]%s*([%d%-]+)%s*[%|%s*]*[%|]%s*%[%[" .. escaped_player .. "%]%](.-)[|]"
| |
| local row_pattern_plain = "[|]%s*([%d%-]+)%s*[%|%s*]*[%|]%s*" .. escaped_player .. "%s*[%|](.-)[|]"
| |
|
| |
| local match = mw.ustring.match(table_content, row_pattern_link) or mw.ustring.match(table_content, row_pattern_plain)
| |
|
| |
| if not match then
| |
| return nil
| |
| end | | end |
|
| |
| -- Витягуємо весь рядок (після |-) для надійного розділення.
| |
| -- Ми шукаємо |000||[[Демон]]||29.12.2022||...
| |
| -- УВАГА: Нам потрібно знайти рядок, що починається з | і містить гравця.
| |
| | | |
| local search_pattern = "([|]%s*.-" .. player_link_pattern .. ".-[|])" | | local title = mw.title.new(page_name) |
| local full_row_match = mw.ustring.match(table_content, search_pattern)
| | if not title or not title.exists then |
|
| | page_cache[page_name] = nil |
| if not full_row_match then | |
| return nil | | return nil |
| end | | end |
| | | |
| local cells = {} | | local content = title:getContent() |
|
| | page_cache[page_name] = content |
| -- РОЗДІЛЕННЯ: Тепер розділяємо вміст, використовуючи || як основний роздільник.
| | return content |
| -- Спочатку замінюємо || на | для стандартизації обробки,
| |
| -- але тільки якщо вміст не є посиланням, яке містить || у назві (малоймовірно).
| |
|
| |
| local normalized_row = mw.ustring.gsub(full_row_match, "||", "|")
| |
|
| |
| -- Якщо рядок починається з |-, видалимо його, щоб не плутати з коміркою.
| |
| normalized_row = mw.ustring.gsub(normalized_row, "^[%s|]*-", "")
| |
|
| |
| -- Розділяємо за |
| |
| for cell in mw.ustring.gmatch(normalized_row, "[|](.-)") do
| |
| table.insert(cells, mw.text.trim(cell))
| |
| end
| |
|
| |
| -- Індекси: cells[1] = Нумерація, cells[2] = Гравець, cells[3] = Дані 1 (Дата), cells[4] = Дані 2 (Провідник)
| |
| | |
| local result = cells[column_index]
| |
| | |
| if result then
| |
| result = mw.text.trim(mw.ustring.gsub(result, "%[?%[?(.+)%]%]?", "%1"))
| |
| return result
| |
| else | |
| return nil
| |
| end
| |
| end | | end |
|
| |
|
| function p.date_added(frame)
| | -- ================================================ |
| local player = frame.args.player
| | -- АВТОМАТИЧНЕ МЕНЮ СЕКЦІЙ |
| local date_str = fetch_data_from_table("Гравці", player, 3)
| | -- ================================================ |
| | |
| if not date_str or date_str == "" then
| |
| return "''Невідомо''"
| |
| end
| |
|
| |
|
| local day, month, year = mw.ustring.match(date_str, "(%d%d)%.(%d%d)%.(%d%d%d%d)") | | function p.section_menu(frame) |
| | local page_name = frame.args.page or mw.title.getCurrentTitle().text |
| | local content = get_page_content(page_name) |
| | | |
| if not day then | | if not content then |
| return date_str .. " (Помилка формату)" | | return "" |
| end | | end |
|
| |
| local join_timestamp = os.time({year=tonumber(year), month=tonumber(month), day=tonumber(day), hour=0, min=0, sec=0})
| |
| | | |
| local diff_seconds = TARGET_TIMESTAMP - join_timestamp | | local sections = {} |
| | | |
| if diff_seconds < 0 then | | for line in mw.ustring.gmatch(content, "[^\n]+") do |
| return date_str | | -- ТІЛЬКИ заголовки рівня 2: == Назва == |
| | if mw.ustring.match(line, "^==[^=]") and mw.ustring.match(line, "[^=]==$") then |
| | local section_name = mw.ustring.match(line, "^==%s*(.-)%s*==$") |
| | |
| | if section_name and section_name ~= "" then |
| | -- Виконуємо шаблони щоб отримати реальний текст |
| | local processed = frame:preprocess(section_name) |
| | processed = mw.text.trim(processed) |
| | |
| | -- Anchor |
| | local anchor = mw.ustring.gsub(processed, " ", "_") |
| | |
| | if processed ~= "" then |
| | table.insert(sections, { |
| | display = processed, |
| | anchor = anchor |
| | }) |
| | end |
| | end |
| | end |
| end | | end |
|
| |
| local diff_days = math.floor(diff_seconds / 86400)
| |
| | | |
| return string.format("%s (%d д)", date_str, diff_days)
| | if #sections == 0 then |
| end
| | return "" |
| | |
| function p.recruiter(frame)
| |
| local player = frame.args.player
| |
| local recruiter_name = fetch_data.from_table("Гравці", player, 4)
| |
| | |
| if not recruiter_name or recruiter_name == "" or recruiter_name == "Не вказано" or recruiter_name == "-" then | |
| return "Не вказано" | |
| end | | end |
| | | |
| if mw.ustring.match(recruiter_name, "%[?%[?") then | | -- Будуємо HTML |
| return recruiter_name
| | local html_parts = {} |
| else | | |
| return string.format("[[%s|%s]]", recruiter_name, recruiter_name)
| | table.insert(html_parts, '<div class="l-box" style="position:fixed; top:20px; left:20px; z-index:100; border-radius:16px; background-color:#23232c; width:220px; box-sizing:border-box; overflow:hidden;">') |
| end | |
| end
| |
| | |
| function p.prize_pool(frame)
| |
| local player = frame.args.player | |
| local amount = fetch_data_from_table("Призовий_фонд", player, 3)
| |
| | |
| if not amount or amount == "" then
| |
| return "0 ₴"
| |
| end
| |
| | |
| amount = mw.ustring.gsub(amount, "[^%d%s]", "")
| |
| amount = mw.text.trim(amount)
| |
| | | |
| return amount .. " ₴" | | table.insert(html_parts, '<div style="padding:15px 20px; font-weight:bold; font-size:15px; color:#fff; border-bottom:1px solid rgba(255,255,255,0.1);">Зміст</div>') |
| end
| |
| | |
| function p.foundation(frame)
| |
| local player = frame.args.player
| |
| local amount = fetch_data.from_table("Фундація", player, 3)
| |
| | |
| if not amount or amount == "" then
| |
| return "0 ₴"
| |
| end
| |
| | |
| amount = mw.ustring.gsub(amount, "[^%d%s]", "")
| |
| amount = mw.text.trim(amount)
| |
| | | |
| return amount .. " ₴" | | for i, section in ipairs(sections) do |
| end
| | local border = "" |
| | | if i < #sections then |
| function p.final(frame)
| | border = "border-bottom:1px solid rgba(255,255,255,0.05);" |
| local player = frame.args.player
| | end |
| local count = fetch_data_from_table("Фіналіст", player, 3)
| | |
| | | table.insert(html_parts, string.format( |
| if not count or count == "" then
| | '<div class="l-box-item" style="padding:12px 20px; %s">[[#%s|%s]]</div>', |
| return "0/9" | | border, section.anchor, section.display |
| | )) |
| end | | end |
|
| |
| count = mw.ustring.match(count, "(%d+)")
| |
| | | |
| if not count then | | table.insert(html_parts, '</div>') |
| return "0/9"
| |
| end
| |
| | | |
| return count .. "/9" | | return table.concat(html_parts, '\n') |
| end | | end |
|
| |
|
| return p | | return p |