Módulo:DidYouKnow
Ir para navegação
Ir para pesquisar
local p = {}
local factTable = require("Module:DidYouKnow/facts")
local function getAllFacts(factTable, factsType)
local facts = factTable.facts
if factsType == 'dungeons' then
facts = factTable.dungeons
elseif factsType == 'legends' then
facts = factTable.legends
elseif factsType == 'movie' or factsType == 'filme' then
facts = factTable.movie
elseif factsType == 'storymode' then
facts = factTable.storymode
elseif factsType == 'earth' then
facts = factTable.earth
elseif factsType == 'comunidade' then
facts = factTable.comunidade
end
return facts
end
local function formatFact(factText)
return "* ... que " .. factText .. "?"
end
function p.getFacts(frame)
local facts = getAllFacts(factTable, frame:getParent().args['type'] or 'minecraft')
local s = ""
local length = #facts
local count = math.min(length, tonumber(frame:getParent().args['count']) or 8)
if frame:getParent().args['random'] then
math.randomseed(os.time())
else
-- Semente aleatória diferente todos os dias (exibe o mesmo conjunto de fatos para um dia, depois um conjunto diferente no dia seguinte, etc.)
math.randomseed(math.floor(os.time()/(60*60*24))*2) -- *2 para que tenhamos um conjunto diferente de fatos em comparação com o Fandom
end
-- Ensure duplicate facts are not displayed
local chosen = {}
while #chosen < count do
local random = math.random(1, length)
local isPresent = false
for i, v in ipairs(chosen) do
if v == random then
isPresent = true
break
end
end
if not isPresent then
table.insert(chosen, random)
end
end
-- Now we actually get to write the output.
local result = {}
for i, v in ipairs(chosen) do
result[i] = formatFact(facts[v])
end
return table.concat(result, "\n")
end
local function formatFactList(facts)
local length = #facts
local result = {}
for i = 1, length do
result[i] = formatFact(facts[i])
end
return table.concat(result, "\n")
end
-- List all facts. Intended to allow easier debugging.
function p.listAllFacts(frame)
local facts = getAllFacts(factTable, frame.args['type'] or 'minecraft')
return formatFactList(facts)
end
function p.listEditcopyFacts()
local editcopyFacts = require("Módulo:DidYouKnow/facts/editcopy")
local facts = getAllFacts(editcopyFacts, frame.args['type'] or 'minecraft')
return formatFactList(facts)
end
return p