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
Line 3: Line 3:


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


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


    local date = args.date or ""
local date = args.date or ""
    local stage = args.stage or ""
local stage = args.stage or ""
   
local stream = args.stream 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 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


    local game = "BGMI"  
if date == "" then return "Error: Date is required." end
    local match_type = "BR"  


    if cargo and cargo.query then
local game = "BGMI"  
        local tData = cargo.query("Tournaments", "game", { where = "name='" .. tournament:gsub("'", "\\'") .. "'", limit = 1 })
local match_type = "BR"
        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"}
if cargo and cargo.query then
            for _, v in ipairs(vs_games) do
local tData = cargo.query("Tournaments", "game", { where = "name='" .. tournament:gsub("'", "\\'") .. "'", limit = 1 })
                if gLower:find(v) then match_type = "VS"; break end
if tData and #tData > 0 and tData[1].game then
            end
game = tData[1].game
        end
local gLower = game:lower()
    end


    local matches = {}
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 i = 1, 15 do
for _, v in ipairs(vs_games) do
        local mTime = args['m'..i..'_time']
if gLower:find(v) then match_type = "VS"; break end
        if mTime and mTime ~= "" then
end
            local match = {}
end
            -- Store as Full ISO 8601 String for JS Conversion
end
            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)
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 cargo and cargo.store then
if match_type == "BR" then
        cargo.store("Tournament_Schedule", {
match.map = args['m'..i..'_map'] or "TBD"
            tournament = tournament,
match.group = args['m'..i..'_group'] or ""
            game = game,
else
            match_type = match_type,
match.t1 = args['m'..i..'_t1'] or "TBD"
            date = date,
match.t2 = args['m'..i..'_t2'] or "TBD"
            stage = stage,
match.group = args['m'..i..'_group'] or ""
            day_data = json_data
end
        })
table.insert(matches, match)
    end
end
end


    return "<div style='display:none;'>Schedule saved.</div>"
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,
day_data = json_data
})
end
 
return "<div style='display:none;'>Schedule saved.</div>"
end
end


return p
return p

Revision as of 02:41, 23 February 2026

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

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

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 ""
local stream = args.stream or ""

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='" .. tournament:gsub("'", "\\'") .. "'", 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

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,
day_data = json_data
})
end

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

return p