Module:Team icon

From Dota 2 Wiki
Jump to: navigation, search

Documentation for Module:Team icon Jump to code ↴ [ edit | purge ]

Reality Rift icon.png
▶️ Planeshift.
The documentation for this module can be found at Template:Team icon.
You may be forwarded to another wiki language, in case a translation is not available.


Dependencies

local p = {}
local cargo = mw.ext.cargo
local fileExists = require('Module:FileExists')
local getArgs = require('Module:Arguments').getArgs
local mFileLink = require('Module:File link')._main


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

function p._main(args)
  assert(args[1], 'Check your input')
  
  local name = args[1]
  local size = args[2] or '40px'
  local icon = 'Team icon Default.png'
    
  -- Attempt to get the data through Cargo.
  -- _pageName matches are prioritized over matches in the names table.
  -- If multiple teams have the same name in their names table the first one is used.
  local cargo_output = cargo.query( 'professional_teams', 'icon, name', { where='_pageName="' .. args[1] .. '"', groupBy='_pageID' } )[1]
  if not cargo_output then
    cargo_output = cargo.query( 'professional_teams', 'icon, name', { where='names HOLDS "' .. args[1] .. '"', groupBy='_pageID' } )[1]
  end

  if cargo_output and cargo_output['icon'] ~= '' then
    name = cargo_output['name']
    icon = cargo_output['icon']
  else
    if fileExists('File:Team icon ' .. args[1] .. '.png') then
      icon = 'Team icon ' .. args[1] .. '.png'
    end
  end
  
  return mFileLink{
    file = icon,
    size = size,
    link = args[1],
    alt = name
  }
end


return p