Module:MiniEvent

--[[ LUA script to get Limited Time Mini Event information

getME: get Limited Time Mini Event based on input parameters Parameters: 1 = name    : Mini Event name 2 = number  : Event Number 3 = options : One or more Output Options Some Options are mutually exclusive D = Event Name with start date A = Display Alternate Text (parameter 4) I = Include Icon 4 = alt text : Alternate Text

Unknown Event is returned if Event is not in data.

getLast: get Last X Events (formatted for main page) Parameter: 1 = Count : return Last Count Events (default 5) --]]

local p = {}

local meData = mw.loadData( 'Module:MiniEvent/data' ) local npc = require('Module:NPC').getNPC local date = require('Dev:Date')

-- 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

-- Date Functions local function ordinal(n) local numb = tonumber(n) or 0 local idd = math.fmod(numb,10) return (idd==1 and numb~=11 and "st") or (idd==2 and numb~=12 and "nd") or (idd==3 and numb~=13 and "rd") or (numb~=0 and "th") or "" end

local function strDate(sDate, days, noYear, sNextDate) local theDate = date(sDate)

local nextDate local chkDate = false

if sNextDate then nextDate = date(sNextDate) chkDate = true end

local nDays = tonumber(days) or 0

local retText = ""

if nDays > 0 then local start = theDate:copy theDate:adddays(nDays) retText = string.gsub(start:fmt("%d"), "^0", "") .. ordinal(start:getday)

if start:getmonth ~= theDate:getmonth then retText = retText .. start:fmt(" %B") end

if not noYear and start:getyear ~= theDate:getyear then retText = retText .. start:fmt(" %Y") end

retText = retText .. " - "   end retText = retText .. string.gsub(theDate:fmt("%d"), "^0", "") .. ordinal(theDate:getday) .. theDate:fmt(" %B")

if not noYear and (not chkDate or theDate:getyear ~= nextDate:getyear) then retText = retText .. theDate:fmt(" %Y") end

return retText end

-- function get single event local function singleEvent(sName, sNumber, sOption, altText) local eventName = "Unknown Event" local eventNumb = {} local eventDate = "" local eventDays = nil local eventMain = nil local npcVer   = nil

local linkText = "Work In Progress" local outText = ""

if meData[sName] then eventName = meData[sName]["Name"] or "Data Error" imageNPC = meData[sName]["Icon"] or "" nameNPC  = meData[sName]["NPC"] or "" linkText = eventName .. " Mini Event"

for n in string.gmatch(sNumber, "%d+") do           if meData[sName][tonumber(n)] then table.insert(eventNumb, tonumber(n)) end end

if eventNumb[1] then eventDate = meData[sName][eventNumb[1]][1] or "" eventDays = meData[sName][eventNumb[1]][2] or 0 eventMain = meData[sName][eventNumb[1]][3] npcVer   = meData[sName][eventNumb[1]][4] linkText = linkText .. "#"               .. eventName .. " #"               .. tostring(eventNumb[1]) end end

if string.match(sOption, "[ETL]") then -- Fixed Formats if string.match(sOption, "E") then -- Event Page Format outText = "|-\n| align=\"center\" width=\"1\"|"

if nameNPC ~= "" then outText = outText .. npc({nameNPC, nil, nil, nil, eventMain or npcVer}) end

outText = outText .. "\n|"                   .. eventName                    .. "\n|"

if eventDate ~= "" then outText = outText .. strDate(eventDate, eventDays, true) end elseif string.match(sOption, "T") then -- Token Page Format

elseif string.match(sOption, "L") then -- Latest Info Main Page Format

end else -- Normal Mode outText = "[[" .. linkText

if eventNumb[1] and eventDate ~= "" then outText = outText .. "|"           if string.match(sOption, "9") then outText = outText .. eventName if not string.match(sOption, "S") then outText = outText .. " Mini Event" end local sNo = "" local sep = false

for _, n in ipairs(eventNumb) do                   if sNo ~= "" then outText = outText .. (sep and "," or "") .. " #" .. sNo sep = true end sNo = tostring(n) end outText = outText .. (sep and " and" or "") .. " #" .. sNo

elseif string.match(sOption, "A") and altText ~= "" then outText = outText .. altText else outText = outText .. eventName if not string.match(sOption, "S") then outText = outText .. " Mini Event" end end else if string.match(sOption, "A") and altText ~= "" then outText = outText .. "|" .. altText elseif string.match(sOption, "S") then outText = outText .. "|" .. eventName end end

outText = outText .. "]]"       if string.match(sOption, "D") then outText = outText .. " on the "

local sNo = nil local sep = false

for _, n in ipairs(eventNumb) do               if sNo then outText = outText .. (sep and ", " or "") .. strDate(meData[sName][sNo][1],                                   nil, nil, meData[sName][n][1]) sep = true end sNo = n           end outText = outText .. (sep and " and " or "") .. strDate(meData[sName][sNo][1]) end end

return outText end

-- function get Limited Time Event function p.getME(frame) local tArgs = getArgs(frame)

local sName   = tArgs[1] or "" local sNumber = tArgs[2] or "" local sOption = tArgs[3] or "" local altText = tArgs[4] or ""

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

sOption = sOption:upper

return singleEvent(sName, sNumber, sOption, altText) end

return p

-- --