Module:Player link

From nUSA Wiki Archive
Jump to navigation Jump to search

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

--- Functions to create links for players
-- <nowiki>
local links = require("Dev:Links")
local roblox_urls = require("Module:RobloxUrls")
local utils = require("Module:Utils")

local p = {}

--- Create a link for a Roblox player.
-- If the player has a page on the wiki, link to it.
-- Otherwise, link to the Roblox profile.
-- Can generate an error if the expensive function call limit is exceeded.
-- @param {string} player Player name.
-- @param {string} id Player ID, optional.
-- @return {string} Player link wikitext.
function p.make_player_link(player, id)
    if player:lower() == 'none' or player:lower() == 'no owner' or player:lower() == 'nobody' then
        return "None"
    else
        local player_page = mw.title.makeTitle('Community', player)
        if player_page and player_page.exists then
            return links.link(player_page.fullText, player, "local")
        elseif id then
            return links.link(tostring(roblox_urls.user_from_id(id)), player, "ext")
        else
            return links.link(tostring(roblox_urls.user_from_username(player)), player, "ext")
        end
    end
end

function p._player_link(args)
	return p.make_player_link(args.player, args.id)
end

p.player_link = utils.make_wrapper_function(p._player_link)

return p