Module:TotallyNotFactions

From BTAWiki
Revision as of 05:21, 28 March 2023 by Amidatelion (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:TotallyNotFactions/doc

-- Module:TotallyNotFactions handles translating faction tags to their full names while testing SPAM

local p = {}

local mechs = require('Module:Mech').core
local getArgs = require('Module:Arguments').getArgs

p.factionTags = {
  AuriganDirectorate = 'Aurigan Directorate',
  AuriganMercenaries = 'Mercenaries',
  AuriganPirates = "[[Local Pirates|Pirates]]",
  AuriganRestoration = "[[Aurigan Coalition|Aurigan Restoration (Arano)]]",
  Chainelane = "[[Chainelane Isles]]",
  Circinus = "[[Circinus Federation]]",
  ClanDiamondShark = "[[Clan Diamond Shark]]",
  ClanGhostBear = "[[Clan Ghost Bear]]",
  ClanJadeFalcon = "[[Clan Jade Falcon]]",
  ClanNovaCat = "[[Clan Nova Cat]]",
  ClanWolf = "[[Clan Wolf]]",
  ComStar = "[[ComStar]]",
  DaneSacellum = "[[Dane Sacellum]]",
  Davion = "[[Federated Suns|Federated Suns (Davion)]]",
  DarkCaste = "[[Dark Caste]]",
  Delphi = "[[New Delphi Compact]]",
  Hanse = "[[Hanseatic League]]",
  Ives = "[[St. Ives Compact]]",
  JacobsonHaven = "[[Jacobson Haven]]",
  JarnFolk = "[[JàrnFòlk]]",
  Kurita = "[[Draconis Combine|Draconis Combine (Kurita)]]",
  Liao = "[[Capellan Confederation|Capellan Confederation (Liao)]]",
  Locals = 'Local Government',
  MagistracyofCanopus = "[[Magistracy of Canopus]]",
  MallardRepublic = "[[Mallard Republic]]",
  Marian = "[[Marian Hegemony]]",
  Marik = "[[Free Worlds League|Free Worlds League (Marik)]]",
  Outworld = "[[Outworlds Alliance]]",
  Rasalhague = "[[Free Rasalhague Republic]]",
  Rim = "[[Rim Collection]]",
  SanctuaryAlliance = "[[Sanctuary Alliance]]",
  Steiner = "[[Lyran Commonwealth|Lyran Commonwealth (Steiner)]]",
  TaurianConcordat = "[[Taurian Concordat]]",
  Tortuga = "[[Tortuga Dominions]]",
  WordOfBlake = "[[Word of Blake]]",
  ["10thLyranGuards"] = "[[List of Major Power Subcommands For SPAM|10th Lyran Guards (Federated Suns)]]",
  ["11thArmyVEta"] = "[[List of Major Power Subcommands For SPAM|11th Army V-Eta (ComStar)]]",
  ["11thAvalonHussars"] = "[[List of Major Power Subcommands For SPAM|11th Avalon Hussars (Lyran Commonwealth)]]",
  ["12thVeganRangers"] = "[[List of Major Power Subcommands For SPAM|12th Vegan Rangers (Federated Suns)]]",
  ["15thLyranRegulars"] = "[[List of Major Power Subcommands For SPAM|15th Lyran Regulars (Lyran Commonwealth)]]",
  ["1stAllianceAirWing"] = "[[List of Major Power Subcommands For SPAM|1st Alliance Air Wing (Outworlds Alliance)]]",
  ["1stKitteryBorderers"] = "[[List of Major Power Subcommands For SPAM|1st Kittery Borderers (Federated Suns)]]",
  ["1stKnightsOfTheInnerSphere"] = "[[List of Major Power Subcommands For SPAM|1st Knights of the Inner Sphere (Free Worlds League)]]",
  ["1stMcCarronsArmoredCavalry"] = "[[List of Major Power Subcommands For SPAM|1st McCarron's Armored Cavalry (Capellan Confederation)]]",
  ["1stSwordOfLight"] = "[[List of Major Power Subcommands For SPAM|1st Sword of Light (Draconis Combine)]]",
  ["1stTyr"] = "[[List of Major Power Subcommands For SPAM|1st Tyr (Free Rasalhague Republic)]]",
  ["21stCentauriLancers"] = "[[2List of Major Power Subcommands For SPAM|1st Centauri Lancers (Comstar)]]",
  ["2ndArmyVMu"] = "[[List of Major Power Subcommands For SPAM|2nd Army V-Mu (ComStar)]]",
  ["2ndCanopianFusiliers"] = "[[List of Major Power Subcommands For SPAM|2nd Canopian Fusiliers (Magistracy of Canopus)]]",
  ["2ndCrucisLancers"] = "[[List of Major Power Subcommands For SPAM|2nd Crucis Lancers (Federated Suns)]]",
  ["2ndFreeWorldsGuards"] = "[[List of Major Power Subcommands For SPAM|2nd Free Worlds Guards (Free Worlds League)]]",
  ["2ndFreemen"] = "[[List of Major Power Subcommands For SPAM|2nd Freemen (Free Rasalhague Republic)]]",
  ["2ndLegionOfVega"] = "[[List of Major Power Subcommands For SPAM|2nd Legion of Vega (Draconis Combine)]]",
  ["30thMarikMilitia"] = "[[List of Major Power Subcommands For SPAM|0th Marik Militia (Free Worlds League)]]",
  ["3rdAllianceAirWing"] = "[[List of Major Power Subcommands For SPAM|3rd Alliance Air Wing (Outworlds Alliance)]]",
  ["3rdNightStalkers"] = "[[List of Major Power Subcommands For SPAM|3rd Night Stalkers (Draconis Combine)]]",
  ["3rdTaurianLancers"] = "[[List of Major Power Subcommands For SPAM|3rd Taurian Lancers (Taurian Concordat)]]",
  ["40thShadowDivision"] = "[[List of Major Power Subcommands For SPAM|40th Shadow Division (Word of Blake)]]",
  ["4thAllianceAirWing"] = "[[List of Major Power Subcommands For SPAM|4th Alliance Air Wing (Outworlds Alliance)]]",
  ["4thKavalleri"] = "[[List of Major Power Subcommands For SPAM|4th Kavalleri (Free Rasalhague Republic)]]",
  ["51stDarkPanzerJaegers"] = "[[List of Major Power Subcommands For SPAM|51st Dark Panzer Jaegers (Word of Blake)]]",
  ["5thDonegalGuards"] = "[[List of Major Power Subcommands For SPAM|5th Donegal Guards (Lyran Commonwealth)]]",
  ["6thConfederationReserveCavalry"] = "[[List of Major Power Subcommands For SPAM|6th Confederation Reserve Cavalry (Capellan Confederation)]]",
  ["6thLyranGuards"] = "[[List of Major Power Subcommands For SPAM|6th Lyran Guards (Lyran Commonwealth)]]",
  ["7thArmyVIota"] = "[[List of Major Power Subcommands For SPAM|7th Army V-Iota (ComStar)]]",
  ["9thDivisionWoB"] = "[[List of Major Power Subcommands For SPAM|9th Division WoB (Word of Blake)]]",
  ["AlwaysFaithful"] = "[[List of Mercenary Factions For SPAM|Always Faithful (Capellan Confederation)]]",
  ["AntianLanciarii"] = "[[List of Mercenary Factions For SPAM|Antian Lanciarii (Aurigan Coalition)]]",
  ["AvantisAngels"] = "[[List of Mercenary Factions For SPAM|Avanti's Angels (Lyran Commonwealth)]]",
  ["BandOfTheDamned"] = "[[List of Mercenary Factions For SPAM|Band of the Damned (Pirate Bands)]]",
  ["BannockburnsBandits"] = "[[List of Mercenary Factions For SPAM|Bannockburn's Bandits (Taurian Concordat)]]",
  ["BarrettsFusiliers"] = "[[List of Mercenary Factions For SPAM|Barrett's Fusiliers (Free Worlds League)]]",
  ["BlackCaravel"] = "[[List of Mercenary Factions For SPAM|Black Caravel (Aurigan Coalition)]]",
  ["BlackOutlaws"] = "[[List of Mercenary Factions For SPAM|Black Outlaws (Free Rasalhague Republic)]]",
  ["Blackhearts"] = "[[List of Mercenary Factions For SPAM|Blackhearts (Free Worlds League)]]",
  ["BlueStarIrregulars"] = "[[List of Mercenary Factions For SPAM|Blue Star Irregulars (Federated Suns)]]",
  ["BroadswordLegion"] = "[[List of Mercenary Factions For SPAM|Broadsword Legion (Word of Blake)]]",
  ["BronsonsHorde"] = "[[List of Mercenary Factions For SPAM|Bronson's Horde (Marian Hegemony)]]",
  ["BullardsArmoredCavalry"] = "[[List of Mercenary Factions For SPAM|Bullard's Armored Cavalry (Circinus Federation)]]",
  ["BurrsBlackCobras"] = "[[List of Mercenary Factions For SPAM|Burr's Black Cobras (Word of Blake)]]",
  ["CGBThetaGalaxy"] = "[[Clan Ghost Bear|Clan Ghost Bear Theta Galaxy]]",
  ["CJFIotaGalaxy"] = "[[Clan Jade Falcon|Clan Jade Falcon Iota Galaxy]]",
  ["CNCOmicronGalaxy"] = "[[Clan Nova Cat|Clan Nova Cat Omicron Galaxy]]",
  ["CWEpsilonGalaxy"] = "[[Clan Wolf|Clan Wolf Epsilon Galaxy]]",
  ["CaesarsCohorts"] = "[[List of Mercenary Factions For SPAM|Caesar's Cohorts (Magistracy of Canopus)]]",
  ["CamachosCaballeros"] = "[[List of Mercenary Factions For SPAM|Camacho's Caballeros (Lyran Commonwealth)]]",
  ["CanopianHighlanders"] = "[[List of Mercenary Factions For SPAM|Canopian Highlanders (Magistracy of Canopus)]]",
  ["CleanKill"] = "[[List of Mercenary Factions For SPAM|Clean Kill (Taurian Concordat)]]",
  ["CohorsMorituri"] = "[[List of Major Power Subcommands For SPAM|Cohors Morituri (Marian Hegemony)]]",
  ["DavionAssaultGuards"] = "[[Davion Assault Guards (Federated Suns)]]",
  ["DeathCommandos"] = "[[Death Commandos (Capellan Confederation)]]",
  ["DeathsConsorts"] = "[[List of Mercenary Factions For SPAM|Deaths Consorts (Pirate Bands)]]",
  ["Dioscuri"] = "[[List of Mercenary Factions For SPAM|Dioscuri (Federated Suns)]]",
  ["DismalDisinherited"] = "[[List of Mercenary Factions For SPAM|Dismal Disinherited (Magistracy of Canopus)]]",
  ["Dragonslayers"] = "[[List of Mercenary Factions For SPAM|Dragonslayers (Magistracy of Canopus)]]",
  ["EridaniLightHorse"] = "[[List of Mercenary Factions For SPAM|Eridani Light Horse (St. Ives)]]",
  ["FederatedFreemen"] = "[[List of Mercenary Factions For SPAM|Federated Freemen (Federated Suns)]]",
  ["FistOfMokal"] = "[[List of Mercenary Factions For SPAM|Fist Of Mokal (Word of Blake)]]",
  ["GraysGhosts"] = "[[List of Mercenary Factions For SPAM|Grays Ghosts (Circinus Federation)]]",
  ["GreenburgsGodzillas"] = "[[List of Mercenary Factions For SPAM|Greenburg's Godzillas (Draconis Combine)]]",
  ["GrimDetermination"] = "[[List of Mercenary Factions For SPAM|Grim Determination]]",
  ["HarcourtsDestructors"] = "[[List of Mercenary Factions For SPAM|Harcourts Destructors (Magistracy of Canopus)]]",
  ["HarlocksWarriors"] = "[[List of Mercenary Factions For SPAM|Harlocks Warriors (Federated Suns)]]",
  ["HsienHotheads"] = "[[List of Mercenary Factions For SPAM|Hsien Hotheads (Word of Blake)]]",
  ["ILegioMartiaVictrix"] = "[[List of Major Power Subcommands For SPAM|I Legio Martia Victrix (Marian Hegemony)]]",
  ["IrukjandiCompany"] = "[[List of Mercenary Factions For SPAM|Irukjandi Company (Aurigan Coalition)]]",
  ["JacobsJuggernauts"] = "[[List of Mercenary Factions For SPAM|Jacobs Juggernauts (Chaos March)]]",
  ["KellHounds"] = "[[List of Mercenary Factions For SPAM|Kell Hounds (Lyran Commonwealth)]]",
  ["KhorsakovsCossacks"] = "[[List of Mercenary Factions For SPAM|Khorsakovs Cossacks (St. Ives)]]",
  ["KnightsOfCaerbannog"] = "[[List of Mercenary Factions For SPAM|Knights Of Caerbannog (Aurigan Coalition)]]",
  ["KnightsOfStCameron"] = "[[List of Mercenary Factions For SPAM|Knights Of St. Cameron (Lyran Commonwealth)]]",
  ["LangendorfLancers"] = "[[List of Mercenary Factions For SPAM|Langendorf Lancers (Capellan Confederation)]]",
  ["LethalInjection"] = "[[List of Mercenary Factions For SPAM|Lethal Injection (Capellan Confederation)]]",
  ["LindonsBattalion"] = "[[List of Mercenary Factions For SPAM|Lindon's Battalion (Chaos March)]]",
  ["LoneStarRegiment"] = "[[List of Mercenary Factions For SPAM|Lone Star Regiment (Taurian Concordat)]]",
  ["LongwoodsBluecoats"] = "[[List of Mercenary Factions For SPAM|Longwood's Bluecoats (Taurian Concordat)]]",
  ["MagistracyCavaliers"] = "[[List of Major Power Subcommands For SPAM|Magistracy Cavaliers (Magistracy of Canopus)]]",
  ["MobileFire"] = "[[List of Mercenary Factions For SPAM|Mobile Fire (Lyran Commonwealth)]]",
  ["MorrisonsExtractors"] = "[[List of Mercenary Factions For SPAM|Morrison's Extractors (Pirate Bands)]]",
  ["NarhalsRaiders"] = "[[List of Mercenary Factions For SPAM|Narhal's Raiders (Lyran Commonwealth)]]",
  ["NewBeltPirates"] = "[[List of Mercenary Factions For SPAM|New Belt Pirates (Pirate Bands)]]",
  ["NorthwindHighlanders"] = "[[List of Mercenary Factions For SPAM|Northwind Highlanders (Lyran Commonwealth)]]",
  ["OlsonsRangers"] = "[[List of Mercenary Factions For SPAM|Olson's Rangers (Capellan Confederation)]]",
  ["PleiadesHussars"] = "[[List of Mercenary Factions For SPAM|Pleiades Hussars (Taurian Concordat)]]",
  ["QuintsOlympianGroundpounders"] = "[[List of Mercenary Factions For SPAM|Quint's Olympian Groundpounders (Circinus Federation)]]",
  ["RamiliesRaiders"] = "[[List of Mercenary Factions For SPAM|Ramilies Raiders (Magistracy of Canopus)]]",
  ["RaventhirsIronHand"] = "[[List of Mercenary Factions For SPAM|Raventhir's Iron Hand (Magistracy of Canopus)]]",
  ["RomanovsCrusaders"] = "[[List of Mercenary Factions For SPAM|Romanov's Crusaders (Free Worlds League)]]",
  ["RubinskysLightHorse"] = "[[List of Mercenary Factions For SPAM|Rubinsky's Light Horse (St. Ives)]]",
  ["ScreamingEagles"] = "[[List of Mercenary Factions For SPAM|Screaming Eagles (Federated Suns)]]",
  ["ShenSeTian"] = "[[List of Mercenary Factions For SPAM|Shen Se Tian (Pirate Bands)]]",
  ["SimonsonsCutthroats"] = "[[List of Mercenary Factions For SPAM|Simonson's Cutthroats (Word of Blake)]]",
  ["SmithsonsChineseBandits"] = "[[List of Mercenary Factions For SPAM|Smithson's Chinese Bandits (Federated Suns)]]",
  ["SnordsIrregulars"] = "[[List of Mercenary Factions For SPAM|Snord's Irregulars (Lyran Commonwealth)]]",
  ["SolarisVIIMercLeague"] = "[[List of Mercenary Factions For SPAM|Solaris VII Mercenary League]]",
  ["TaurianGuard"] = "[[List of Major Power Subcommands For SPAM|Taurian Guard (Taurian Concordat)]]",
  ["TheArcadians"] = "[[List of Mercenary Factions For SPAM|The Arcadians (Federated Suns)]]",
  ["TheKrushers"] = "[[List of Mercenary Factions For SPAM|The Krushers (Free Worlds League)]]",
  ["ThermoPolice"] = "[[List of Mercenary Factions For SPAM|Thermo Police (Outworlds Alliance)]]",
  ["ToothOfYmir"] = "[[List of Mercenary Factions For SPAM|Tooth Of Ymir (Chaos March)]]",
  ["TortugaFusiliers"] = "[[List of Mercenary Factions For SPAM|Tortuga Fusiliers (Pirate Bands)]]",
  ["VLegioRipariensis"] = "[[List of Major Power Subcommands For SPAM|V Legio Ripariensis (Marian Hegemony)]]",
  ["VanguardLegion"] = "[[List of Mercenary Factions For SPAM|Vanguard Legion (Federated Suns)]]",
  ["WarriorHouseImarra"] = "[[Warrior House Imarra (Capellan Confederation)]]",
  ["WinfieldsRegiment"] = "[[List of Mercenary Factions For SPAM|Winfields Regiment (Chaos March)]]",
  ["WoBProtectorateMilitia"] = "[[List of Major Power Subcommands For SPAM|WoB Protectorate Militia (Word of Blake)]]",
  ["Wolfs_Dragoons"] = "[[List of Mercenary Factions For SPAM|Wolfs_Dragoons (Draconis Combine)]]"
}


function p.factionMechs(frame)
  local tpl_args = getArgs(frame, {parentFirst=true})

  local faction = tpl_args[1]
  local where = string.format('Mech.MechTags HOLDS "%s"', faction)

  -- some mechs share the same name but have different tonnages and therefore
  -- different pages to be linked to
  local function MakeMechLink(name, variant, tonnage)
    if (name == "Blackjack" and tonnage ~= "45") or
       (name == "Centurion" and tonnage ~= "50") or
       (name == "Corsair" and tonnage ~= "95") or
       (name == "Stalker" and tonnage ~= "85") or
       (name == "Mad Cat MK II" and tonnage ~= "90") then
      return string.format("[[%s_(%sT)#%s|%s (%sT) %s]]", name, tonnage, variant, name, tonnage, variant)
    elseif string.find(variant, "ZEU-X", 1, true) then
      return string.format("[[Zeus_X#%s|Zeus X %s]]", variant, variant)
    else
      return string.format("[[%s#%s|%s %s]]", name, variant, name, variant)
    end
  end

  -- when querying for mechs, set the limit to 2000. this is arbitrarily high
  -- (larger than the total number of mechs). without this, factions with lots
  -- of mechs would not show all of them.
  local factionMechData = mw.ext.cargo.query(
    'Mech,Chassis','Chassis.Name=Name,Chassis.VariantName=VariantName,Chassis.Tonnage=Tonnage',
    { join = 'Mech.ChassisID=Chassis.Id', where=where, limit=2000 }
  )

  local mechsList = mw.html.create('ul')
  mechsList:cssText('column-count: 3;-moz-column-count: 3;-webkit-column-count: 3')
  for _, mech in ipairs(factionMechData) do
    mechsList:tag('li'):wikitext(MakeMechLink(mech.Name, mech.VariantName, tostring(mech.Tonnage)))
  end
  return mechsList
end

function p.mechFactions(frame)
  local tpl_args = getArgs(frame, {parentFirst=true})
  variant = tpl_args[1]

  local mech = mechs.mech.byVariant(variant)

  if mech == nil then
    return mw.html.create('div').wikitext("''Mech not found''")
  end

  local tags = {}

  local factionList = mw.html.create('ul')

  for _, tag in ipairs(mech.tags) do
    if p.factionTags[tag] ~= nil then
      table.insert(tags, p.factionTags[tag])
    end
  end

  table.sort(tags)
  for _, tag in ipairs(tags) do
    factionList:tag('li'):wikitext(tag)
  end
  
  return factionList
end

return p