Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:MatchDay: Difference between revisions

From eSportsAmaze
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo


function p.store(frame)
local function sqlEscape(s)
local args = frame:getParent().args
    if not s then return "" end
 
    s = s:gsub("\\", "\\\\")
-- SMART TOURNAMENT NAME EXTRACTION
    s = s:gsub("'", "\\'")
local pageTitle = mw.title.getCurrentTitle().text
    return s
local tournament = args.tournament
 
if not tournament or tournament == "" then
local parts = mw.text.split(pageTitle, '/')
-- If path is like "BGMI/Tournaments/BGIS_2026/Matches", grab the 3rd part
if parts[2] == "Tournaments" and parts[3] then
tournament = parts[3]
else
-- Fallback to the base page name
tournament = mw.title.getCurrentTitle().baseText
end
end
end


local date = args.date or ""
function p.store(frame)
local stage = args.stage or ""
    local args = frame:getParent().args
    local pageTitle = mw.title.getCurrentTitle().text
    local tournament = args.tournament


if date == "" then return "Error: Date is required." end
    if not tournament or tournament == "" then
        local parts = mw.text.split(pageTitle, '/')
        if parts[2] == "Tournaments" and parts[3] then
            tournament = parts[3]
        else
            tournament = mw.title.getCurrentTitle().baseText
        end
    end


-- 1. Look up the Game Type from Tournaments Table
    local date = args.date or ""
local game = "BGMI" -- Default fallback
    local stage = args.stage or ""
local match_type = "BR" -- Default format
   
    -- TIMEZONE LOGIC
    local timezone = args.timezone or "IST"
    local tz_offset = "+00:00"
    if timezone == "IST" then tz_offset = "+05:30"
    elseif timezone == "JST" then tz_offset = "+09:00"
    elseif timezone == "PST" then tz_offset = "-08:00"
    elseif timezone == "EST" then tz_offset = "-05:00"
    elseif timezone == "CET" then tz_offset = "+01:00"
    elseif timezone:match("^[%+%-]%d%d:%d%d$") then tz_offset = timezone
    end


if cargo and cargo.query then
    if date == "" then return "Error: Date is required." end
-- Match exact tournament name to find the game
local tData = cargo.query("Tournaments", "game", { where = "name='" .. tournament:gsub("'", "\\'") .. "'", limit = 1 })


if tData and #tData > 0 and tData[1].game then
    local game = "BGMI"
game = tData[1].game
    local match_type = "BR"
local gLower = game:lower()


-- THE EWC FUTURE-PROOF DICTIONARY
    if cargo and cargo.query then
-- List of Head-to-Head (Team vs Team / 1v1) Games
        local tData = cargo.query("Tournaments", "game", { where = "name='" .. sqlEscape(tournament) .. "'", limit = 1 })
local vs_games = {
        if tData and #tData > 0 and tData[1].game then
"pokemon", "mlbb", "mobile legends", "honor of kings", "hok",  
            game = tData[1].game
"league of legends", "lol", "dota", "counter-strike", "cs2",  
            local gLower = game:lower()
"valorant", "rainbow six", "r6", "overwatch", "ow2", "rocket league",
            local vs_games = {"pokemon", "mlbb", "mobile legends", "honor of kings", "hok", "league of legends", "lol", "dota", "counter-strike", "cs2", "valorant", "rainbow six", "r6", "overwatch", "ow2", "rocket league", "ea sports fc", "fifa", "street fighter", "tekken", "fatal fury", "starcraft", "crossfire", "chess", "black ops", "modern warfare"}
"ea sports fc", "fifa", "street fighter", "tekken", "fatal fury",  
            for _, v in ipairs(vs_games) do
"starcraft", "crossfire", "chess", "black ops", "modern warfare"
                if gLower:find(v) then match_type = "VS"; break end
}
            end
        end
    end


-- Check if the game matches anything in the VS dictionary
    -- MULTIPLE STREAMS LOGIC
for _, v in ipairs(vs_games) do
    local streams = {}
if gLower:find(v) then
    for k, v in pairs(args) do
match_type = "VS"
        if type(k) == "string" and k:match("^stream") and v ~= "" then
break
            local label = "Watch"
end
            if k:match("^stream_(.+)$") then
end
                label = k:match("^stream_(.+)$")
                label = label:gsub("_", " ") -- Convert underscores to spaces (e.g., Watch_Party -> Watch Party)
            end
            streams[label] = v
        end
    end
   
    local stream_json = ""
    if next(streams) ~= nil then
        stream_json = mw.text.jsonEncode(streams)
    end


-- Explicitly define BR/Lobby games (Just in case, though it defaults to BR)
    -- MATCH DATA LOGIC
local br_games = {
    local matches = {}
"bgmi", "pubg", "free fire", "apex", "warzone", "fortnite",
    for i = 1, 15 do
"teamfight tactics", "tft", "rennsport", "trackmania"
        local mTime = args['m'..i..'_time']
}
        if mTime and mTime ~= "" then
            local match = {}
            match.time = date .. "T" .. mTime .. ":00" .. tz_offset
           
            if match_type == "BR" then
                match.map = args['m'..i..'_map'] or "TBD"
                match.group = args['m'..i..'_group'] or ""
            else
                match.t1 = args['m'..i..'_t1'] or "TBD"
                match.t2 = args['m'..i..'_t2'] or "TBD"
                match.group = args['m'..i..'_group'] or ""
            end
            table.insert(matches, match)
        end
    end


for _, b in ipairs(br_games) do
    local json_data = mw.text.jsonEncode(matches)
if gLower:find(b) then
match_type = "BR"
break
end
end
end
end


-- 2. Build the Match Data JSON
    if cargo and cargo.store then
local matches = {}
        cargo.store("Tournament_Schedule", {
for i = 1, 15 do
            tournament = tournament,
local mTime = args['m'..i..'_time']
            game = game,
if mTime and mTime ~= "" then
            match_type = match_type,
local match = { time = mTime }
            date = date,
 
            stage = stage,
-- If Battle Royale / FFA Lobby
            stream = stream_json,
if match_type == "BR" then
            day_data = json_data
match.map = args['m'..i..'_map'] or "TBD"
        })
match.group = args['m'..i..'_group'] or ""
    end
-- If Head-to-Head (MOBA, FPS, Fighting, Sports)
else
match.t1 = args['m'..i..'_t1'] or "TBD"
match.t2 = args['m'..i..'_t2'] or "TBD"
match.group = args['m'..i..'_group'] or ""
end
 
table.insert(matches, match)
end
end
 
local json_data = mw.text.jsonEncode(matches)
 
-- 3. Store in Cargo
if cargo and cargo.store then
cargo.store("Tournament_Schedule", {
tournament = tournament,
game = game,
match_type = match_type,
date = date,
stage = stage,
day_data = json_data
})
end


return "<div style='display:none;'>Schedule saved for " .. date .. " (" .. match_type .. " Format)</div>"
    return "<div style='display:none;'>Schedule saved.</div>"
end
end


return p
return p

Latest revision as of 01:33, 3 March 2026

Documentation for this module may be created at Module:MatchDay/doc

local p = {}
local cargo = mw.ext.cargo

local function sqlEscape(s)
    if not s then return "" end
    s = s:gsub("\\", "\\\\")
    s = s:gsub("'", "\\'")
    return s
end

function p.store(frame)
    local args = frame:getParent().args
    local pageTitle = mw.title.getCurrentTitle().text
    local tournament = args.tournament

    if not tournament or tournament == "" then
        local parts = mw.text.split(pageTitle, '/')
        if parts[2] == "Tournaments" and parts[3] then
            tournament = parts[3]
        else
            tournament = mw.title.getCurrentTitle().baseText
        end
    end

    local date = args.date or ""
    local stage = args.stage or ""
    
    -- TIMEZONE LOGIC
    local timezone = args.timezone or "IST"
    local tz_offset = "+00:00"
    if timezone == "IST" then tz_offset = "+05:30"
    elseif timezone == "JST" then tz_offset = "+09:00"
    elseif timezone == "PST" then tz_offset = "-08:00"
    elseif timezone == "EST" then tz_offset = "-05:00"
    elseif timezone == "CET" then tz_offset = "+01:00"
    elseif timezone:match("^[%+%-]%d%d:%d%d$") then tz_offset = timezone
    end

    if date == "" then return "Error: Date is required." end

    local game = "BGMI" 
    local match_type = "BR" 

    if cargo and cargo.query then
        local tData = cargo.query("Tournaments", "game", { where = "name='" .. sqlEscape(tournament) .. "'", limit = 1 })
        if tData and #tData > 0 and tData[1].game then
            game = tData[1].game
            local gLower = game:lower()
            local vs_games = {"pokemon", "mlbb", "mobile legends", "honor of kings", "hok", "league of legends", "lol", "dota", "counter-strike", "cs2", "valorant", "rainbow six", "r6", "overwatch", "ow2", "rocket league", "ea sports fc", "fifa", "street fighter", "tekken", "fatal fury", "starcraft", "crossfire", "chess", "black ops", "modern warfare"}
            for _, v in ipairs(vs_games) do
                if gLower:find(v) then match_type = "VS"; break end
            end
        end
    end

    -- MULTIPLE STREAMS LOGIC
    local streams = {}
    for k, v in pairs(args) do
        if type(k) == "string" and k:match("^stream") and v ~= "" then
            local label = "Watch"
            if k:match("^stream_(.+)$") then
                label = k:match("^stream_(.+)$")
                label = label:gsub("_", " ") -- Convert underscores to spaces (e.g., Watch_Party -> Watch Party)
            end
            streams[label] = v
        end
    end
    
    local stream_json = ""
    if next(streams) ~= nil then
        stream_json = mw.text.jsonEncode(streams)
    end

    -- MATCH DATA LOGIC
    local matches = {}
    for i = 1, 15 do
        local mTime = args['m'..i..'_time']
        if mTime and mTime ~= "" then
            local match = {}
            match.time = date .. "T" .. mTime .. ":00" .. tz_offset
            
            if match_type == "BR" then
                match.map = args['m'..i..'_map'] or "TBD"
                match.group = args['m'..i..'_group'] or ""
            else
                match.t1 = args['m'..i..'_t1'] or "TBD"
                match.t2 = args['m'..i..'_t2'] or "TBD"
                match.group = args['m'..i..'_group'] or ""
            end
            table.insert(matches, match)
        end
    end

    local json_data = mw.text.jsonEncode(matches)

    if cargo and cargo.store then
        cargo.store("Tournament_Schedule", {
            tournament = tournament,
            game = game,
            match_type = match_type,
            date = date,
            stage = stage,
            stream = stream_json,
            day_data = json_data
        })
    end

    return "<div style='display:none;'>Schedule saved.</div>"
end

return p