Documentation for this module may be created at Module:Homepage/doc

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

function p.randomCharacter(frame)
	local query = {
		limit = '1000',
		where = 'Characters.type="horsegirl" AND Characters.media IS NULL AND Characters.icon IS NOT NULL'
	}
	local fields = {'_pageName','name_en','icon','color_main','color_sub'}
	local characters = cargo.query('Characters', table.concat(fields, ','), query)
	math.randomseed(os.time())
	local ri = math.random(#characters)
	
	local ch = characters[ri]
	local template = frame:expandTemplate{
		title='Character Icon',
		args={
			icon=ch.icon,
			name_en=ch.name_en,
			color_main=ch.color_main,
			color_sub=ch.color_sub,
			link=ch._pageName
		}
	}
	return mw.text.trim(template)
end

function p.randomIcon()
	local query = {
		limit = '1000',
		where = 'Characters.type="horsegirl" AND Characters.media IS NULL AND Characters.icon IS NOT NULL'
	}
	local fields = {'icon'}
	local characters = cargo.query('Characters', table.concat(fields, ','), query)
	math.randomseed(os.time())
	local ri = math.random(#characters)
	
	local ch = characters[ri]
	
	return string.format('[[File:%s|200px|class=img|link=List of Characters]]', ch.icon)
end

function p.randomCover()
	local query = {
		limit = '1000'
	}
	local fields = {'cover'}
	local covers = cargo.query('Albums', table.concat(fields, ','), query)
	math.randomseed(os.time())
	local ri = math.random(#covers)
	
	local rs = covers[ri]
	
	return string.format('[[File:%s|200px|class=img|link=List of Albums]]', rs.cover)
end

return p