Module:Sandbox

From Nookipedia, the Animal Crossing wiki

Module documentation (view)


Usage

This is the general sandbox page to test out Lua modules. The module should not be implemented in a template.


-- Generates random item name; adopted from Temtem Wiki, licensed under CC BY-NC-SA, authors listed here: https://temtem.wiki.gg/wiki/Module:Daily_tem?action=history
local p = {}
local cargo = mw.ext.cargo
local titleCase = require('Module:TitleCase')
local sentenceCase = require('Module:SentenceCase').firstToUpper

function p.main(frame)
	math.randomseed(os.date("%Y%m%d"))
	local tables = ''
	local game = ""
	local setTable = math.random(1,4)
	if setTable == 1 then
		tables = 'pg_identifier'
		game = cargo.query( 'pg_identifier', '_pageName', {'no html'} )[1]['_pageName']:gsub("Item:.*%((.-)%)","%1")
	elseif setTable == 2 then
		tables = 'ww_identifier'
		game = "Wild World"
	elseif setTable == 3 then
		tables = 'nl_identifier'
		game = "New Leaf"
	elseif setTable == 4 then
		tables = 'nh_identifier'
		game = "New Horizons"
	else
		tables = 'nh_identifier'
		game = "New Horizons"
	end
	local count = cargo.query( tables, 'COUNT(DISTINCT en_name)=n', {'no html'})[1]['n']
	
    local args = {
        limit = 1,
        offset = math.floor(math.random() * count),
    }
    local results = cargo.query( tables, '_pageName,en_name', args )
	local print = "[[" .. results[1]['_pageName'] .. "|" .. sentenceCase(results[1]['en_name']) .. " (''" .. game .. "'')]]"
	return print
end

return p