Audio migration in progress. Some responses pages / audio files may have broken file links.

Module:Show

From Dota 2 Wiki
Jump to: navigation, search

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

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


Dependencies

local p = {}

local cargoQuery = mw.ext.cargo.query
local getArgs = require( 'Module:Arguments' ).getArgs

local i18n = {
  error = {
    incompleteInput = 'Missing or incomplete input'
  },
  stringLowerFunc = string.lower -- Change to mw.ustring.lower on wikis using non-latin characters.
}

local function preprocessProperty( property )
  property = i18n.stringLowerFunc( property )
  property = property:gsub( ' ', '_' )
  return property
end

local function query( table, page, property )
  property = preprocessProperty( property )
  return cargoQuery( table, property, {
    where = string.format( '_pageName="%s"', page ),
    groupBy = '_pageID'
  } )[1][property]
end

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

function p._main( args )
  assert( args[1] and args[2] and args[3], i18n.error.incompleteInput )
  local type = i18n.stringLowerFunc( args[1] )
  
  if type == 'h' then
    return query( 'heroes', args[2], args[3] )
  elseif type == 't' then
    return query( 'talents', args[2] .. '/Talents', args[3] )
  elseif type == 'i' then
    return query( 'items', args[2], args[3] )
  elseif type == 'u' then
    return query( 'units', args[2], args[3] )
  elseif type == 'c' then
    return query( 'camps', args[2], args[3] )
  elseif type == 'a' then
    assert( args[4], i18n.error.incompleteInput )

    local property = preprocessProperty( args[4] )
    if property:find( 'trait' ) or property:find( 'value' ) then
      return cargoQuery( 'abilities_traits', property, {
        where = string.format( 'uid="%s&%s"', args[2], args[3] ),
        groupBy = 'uid'
      } )[1][property]
    elseif property:find( 'buff' ) or property:find( 'debuff' ) then
      return cargoQuery( 'abilities_buffs', property, {
        where = string.format( 'uid="%s&%s"', args[2], args[3] ),
        groupBy = 'uid'
      } )[1][property]
    else
      return cargoQuery( 'abilities', property, {
        where = string.format( 'uid="%s&%s"', args[2], args[3] ),
        groupBy = 'source, title'
      } )[1][property]
    end
  end
end

return p