FANDOM


-- <pre>
local p = {}
 
function p.main(frame)
	-- This template is fairly expensive to use, so it should be limited
	mw.incrementExpensiveFunctionCount()
 
	local args = frame:getParent().args
 
	local store = string.gsub(args['?store'] or args.store or '','[][]','')
	store = mw.text.decode(store)
 
	local item = string.lower(args.userparam or args.item or '')
	item = mw.text.decode(item)
 
	-- escape lua characters
	local _item = item:gsub('([%^%$%(%)%%%.%[%]%*%+%-%?])','%%%1')
 
	local smwdata = frame:preprocess('{{'..
					'{{{|safesubst:}}}#show:'..
					store..
				[[
					|?Store JSON
					|headers=plain
					|format=list
					}}
				]])
 
	smwdata = mw.text.decode(tostring(smwdata))
 
	local _found = false
 
	local json = smwdata
 
	json = string.format('[ %s ]',json)
 
	_found = mw.ustring.find(json:lower(), '%{ "name": "'.._item..'"')
 
	if not _found then
		return ''
	end
 
	local mems = frame:preprocess('{{{{{|safesubst:}}}#show:'..store..'|?Is members only}}')
 
	local stock,price,currency = mw.ustring.match(json:lower(), '%{ "name": "'.._item..'", "stock": "(.-)", "price": "([%d%?]+)", "currency": "([%w ]+)"')
 
	stock = stock or 0
	price = price or ''
	currency = currency:gsub("^%l", string.upper) or 'coins'
 
	return frame:preprocess(string.format('{{SellersLine|store=[[%s]]|stock=%s|price=%s|currency=%s|members=%s}}',store,stock,price,currency,mems))
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.