Module:ChiselLink

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:ChiselLink/doc. [edit] [history] [purge]
Module:ChiselLink's function main is invoked by Template:Chisel link.
Function list
L 13 — p.main
L 18 — p._main

Generates a list (space separated) of chisel links for ids (item, npc or object).


local links = {
	item = 'https://chisel.weirdgloop.org/gazproj/mrid',
	npc = 'https://chisel.weirdgloop.org/gazproj/mrnd',
	object = 'https://chisel.weirdgloop.org/gazproj/mrod'
}
local labels = {
	item = 'MRID',
	npc = 'MRND',
	object = 'MROD'
}
local p = {}

function p.main(frame)
	local args = frame:getParent().args
	return p._main(args[1], args[2])
end

function p._main(idtype, ids)
	if not (type(ids) == 'string' and ids:match('^[ 0-9,]+$')) then
		return ''
	end
	local _ids = mw.text.split(mw.text.trim(ids), '%s*,%s*')
	local _type= string.lower( mw.text.split(mw.text.trim(idtype), '%s+')[1] )
	if not links[_type] then
		return ''
	end
	
	if #_ids == 0 then
		return ''
	elseif #_ids == 1 then
		if tonumber(_ids[1]) then
			return string.format(' [%sid?%s#%s-%s %s]', links[_type], _ids[1], math.max(_ids[1]-15,0), _ids[1]+15, labels[_type])
		else
			return string.format(' [%sid#%s %s]', links[_type], _ids[1], labels[_type])
		end
	else
		local ret = ''
		for _,i in ipairs(_ids) do
			if tonumber(i) then
				ret = ret .. string.format(' [%sid?%s#%s-%s %s%s]', links[_type], i, math.max(i-15,0), i+15, labels[_type], i)
			else
				ret = ret .. string.format(' [%sid#%s %s%s]', links[_type], i, labels[_type], i)
			end
		end
		return ret
	end
end

return p