Module:Team ID

local p = {} local cargo = mw.ext.cargo local caching = require( 'Module:Cache' ).auto local getArgs = require( 'Module:Arguments' ).getArgs local tooltip = require( 'Module:Tooltip' )._main

local specials = { ["tbd"] = { "TBD", "To be decided" }, ["tba"] = { "TBD", "To be announced" }, ["grp. s."] = { "Grp. S.", "Group Stage (W/D/L)" }, ["grp.s."] = { "Grp. S.", "Group Stage (W/D/L)" }, ["grp"] = { "Grp. S.", "Group Stage (W/D/L)" }, ["league"] = { "League Play", "League Play (W/D/L)" }, ["league play"] = { "League Play", "League Play (W/D/L)" }, }

function p.main( frame ) local args = getArgs(frame, {   wrappers = {      'Template:Team ID'    }  }) return caching(p._main, args, 'teamid') end

function p._main( args ) assert( args and args[1], 'No team name entered' ) -- Check if a special rule exists for this input. local special = specials[string.lower(args[1])] if special then local values = special return tostring(tooltip( { values[1], values[2] } )) else local icon = 'Team icon Default.png' local name = args[1] -- Attempt to get the data through Cargo. local cargo_info = cargo.query( 'professional_teams', 'icon, name', { where='_pageName="' .. args[1] .. '"', groupBy='_pageID' } )[1] if cargo_info then if cargo_info['icon'] ~= '' or nil then icon = cargo_info['icon'] end if cargo_info['name'] ~= '' or nil then name = cargo_info['name'] end else -- Manually create the image name and check if it exsts. -- Using pcall to prevent breakage when the limit for expensive parser functions is exceeded. success, result = pcall( function( file ) return mw.title.new( file ).fileExists end, 'File:Team icon ' .. args[1] .. '.png' ) if success == true and result == true then icon = 'Team icon ' .. args[1] .. '.png' end end

return ' ' .. name .. ' ' end end

return p