Module:MiniEvent

-- Test LUA script to get Mini Event information --

local p = {}

local meData = mw.loadData( 'Module:MiniEvent/data' )

Local Functions local function getArgs(frame) local tArgs

if frame == mw.getCurrentFrame then fParent = frame:getParent tArgs = fParent.args

if (fParent.args[1]) then tArgs = fParent.args else tArgs = frame.args end else tArgs = frame end return tArgs end

local function strDate(numDate) local months = {"January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December "} local day = math.min(math.fmod(numDate, 100), 31)

local idd = math.fmod(day, 10) local nth = (idd==1 and day~=11 and "st ") or (idd==2 and day~=12 and "nd ") or (idd==3 and day~=13 and "rd ") or "th "

local year = math.floor(numDate / 100)

local mon = math.min(math.fmod(year, 100), 12)

year = math.floor(year/100)

return (day .. nth .. months[mon] .. year) end

local function singleEvent(sName, eType, outType, altText) local eventName = "Work In Progress" local collection = "Unknown Event" local eventYear = nil

local outText = eventName local dispText = "" local dateText = ""

if meData[eType] and meData[eType][sName] then eventName    = meData[eType][sName][2] eventYear    = meData[eType][sName][3] eventDate    = meData[eType][sName][4] eventNumber  = meData[eType][sName][5] or meData[eType][sName][2] outText = eventName .. " Mini Event" end

if outType:match("^[ANLMD]$") then if outType == "A" then dispText = altText elseif outType == "N" then dispText = eventName .. " Mini Event#" .. eventNumber elseif outType == "D" then if altText ~= "" then dispText = altText end dateText = " on " .. strDate(eventDate) .. " " .. eventYear end end return outText end

local function multiEvent(eType, outType, year) local tIndex = {} local tOutput = {}

if meData[eType] then if year and year ~= 0 then for k, v in pairs(meData[eType]) do               if year == v[3] then table.insert(tIndex,v[1]) tOutput[v[1]] = v               end end else for k, v in pairs(meData[eType]) do               table.insert(tIndex,v[1]) tOutput[v[1]] = v           end end end

table.sort(tIndex)

local outText = "" local sDot   = ""

for _, idx in ipairs(tIndex) do

outText = outText .. sDot .. "[["                .. tOutput[idx][2]                 .. " Mini Event "

if outType == "N" then outText = outText .. "|" .. tOutput[idx][1] .. "#" .. tOutput[idx][2] else outText = outText .. "|" .. tOutput[idx][1] end

if outType == "L" then outText = outText .. "]] * Leaderboard Reward " elseif outType == "M" then outText = outText .. "]] * Milestone Reward " else outText = outText .. "]]"       end

sDot = " · " end return outText end

-- function get Limited Time Event function p.getLTE(frame)

local tArgs = getArgs(frame)

local sName   = tArgs[1] or "" local eType   = tArgs[2] local outType = tArgs[3] or "N" local altText = tArgs[4] or ""

sName = sName:lower:gsub("^%s*(.-)%s*$", "%1") or ''

if not eType or eType == "" then eType = "N" end

eType = eType:upper outType = outType:upper

local multi, year = sName:match("^(multi)(%d*)$")

if multi then return multiEvent(eType, outType, tonumber(year)) else return singleEvent(sName, eType, outType, altText) end end

return p