Module:Daily tem

From Official Temtem Wiki
Jump to navigation Jump to search
Template-info.png Documentation

This module returns a random Temtem name from the Temtem Cargo table using the current day (UTC) as a seed.

Temtem with variants[edit]

For Temtem that have variants (Koish and Chromeon), the module returns a random variant such as "Koish (Nature)". It does this after the base Temtem is selected, so having these variants does not give these Tems a higher chance of being selected than those without.

Caching[edit]

Because of page caching, using content that's supposed to regularly change without page edits is unreliable. To help with this, User:Mr Pie 5 runs a script that automatically purges the cache of all pages transcluding this module at 00:01 daily (UTC).

Usage[edit]

The module can be called with {{#invoke:Daily tem|main}}. The output is a simple string, formatting is left to be done by whatever page is invoking the module.

Example[edit]

Today's Temtem is: {{#invoke:Daily tem|main}}

produces:
Today's Temtem is: Smazee


-- outputs the name of a random Temtem from the Temtem Cargo table

local p = {}
local cargo = mw.ext.cargo

function p.main(frame)
	
	local tables = 'Temtem'
	local count = cargo.query( tables, 'COUNT(DISTINCT name)=n', {'no html'})[1]['n']
	
	math.randomseed(os.date("%Y%m%d"))

    local args = {
        limit = 1,
        offset = math.floor(math.random() * count),
    }
    local results = cargo.query( tables, 'name', args )
	local name = results[1]['name']
	
	-- if we have a koish or chromeon, pick a random type
	if name == "Koish" or name == "Chromeon" then
		local types = {"Neutral", "Wind", "Earth", "Water", "Fire", "Nature", "Electric", "Mental", "Digital", "Melee", "Crystal", "Toxic"}
		local variantType = types[math.random(#types)]
		
		name = name .. " (" .. variantType .. ")"
	end
	
	return name
	
end

return p