Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Command

From Vault Hunters Official Wiki
Revision as of 22:44, 16 June 2025 by Mnooseman (talk | contribs) (Created page with "local p = {} function p.cmd( f ) local args = f if f == mw.getCurrentFrame() then args = f:getParent().args end local commandName = args[1]:match( '^%s*/?([^%s]+)' ):lower() local params = {} local command = {} --getparams for i, v in ipairs( args ) do if i > 1 or v:match( '^%s*/?(.+)' ):lower() ~= commandName then table.insert( params, mw.text.trim( v ) ) end end --escape space and split args if #params == 1 and ( not args[2] or args[2] == '...' )...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Implements {{Command}}.




local p = {}
function p.cmd( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end
	local commandName = args[1]:match( '^%s*/?([^%s]+)' ):lower()
	local params = {}
	local command = {}
	
	--getparams
	for i, v in ipairs( args ) do
		if i > 1 or v:match( '^%s*/?(.+)' ):lower() ~= commandName then
			table.insert( params, mw.text.trim( v ) )
		end
	end

	--escape space and split args
	if #params == 1 and ( not args[2] or args[2] == '...' ) and params[1]:find( '%s' ) then
		params[1] = params[1]:match( '^[^%s]+%s(.+)' )
	end
	
	command = params
	
	if args.link then
		if args.link:lower() ~= 'none' then
			commandName = '[[' .. args.link .. '|' .. commandName .. ']]'
		end
	else
		commandName = '[[Commands/' .. commandName .. '|' .. commandName .. ']]'
	end
	table.insert( command, 1, commandName )
	
	local slash = '/'
	if args['/'] == '0' or args.slash == '0' then
		slash = ''
	end
	
	local attr = ''
	if args.long then
		attr = 'style="display: flex; padding: 0.8em 1em; margin-bottom: 0.4em; word-warp: break-word;"'
	end
	
	local result = table.concat( command, ' ' ):gsub( '〈space〉', ' ' ):gsub('〈lsqb〉', '%['):gsub('〈rsqb〉', '%]'):gsub('〈apos〉',"'"):gsub('〈quot〉','"')
	-- Don't encode if told not to or if there is a sub-command
	if args.escape ~= '0' then
		result = result:gsub( '<', '&lt;' ):gsub( '&lt;(!%-%- Command %-%->)&lt;','<%1<'):gsub( '&lt;/code>&lt;(!%-%- /Command %-%->)','</code><%1')
	end
	result = '<!-- Command --><code ' .. attr .. '><span>' .. slash .. result .. '</span></code><!-- /Command -->'
    return result
end
return p