Puzzler that awards points. Maybe.

This commit is contained in:
Neale Pickett 2015-04-18 19:13:07 -06:00
parent 1419fabd76
commit 2d6ac84641
4 changed files with 35 additions and 3 deletions

0
TODO Normal file
View File

View File

@ -15,6 +15,9 @@ fi
# Collect new points
find state/points.new -type f | while read fn; do
# Skip partially-written files
[ $(wc -l $fn) -eq 1 ] || continue
cat $fn >> state/points.log
rm $fn
done

View File

@ -41,5 +41,32 @@ function koth.page(title, body)
os.exit(0)
end
--
-- We're going to rely on `bin/once` only processing files with the right number of lines.
--
function koth.award_points(team, category, points, comment)
local filename = team .. "." .. category .. "." points
local entry = team .. " " .. category .. " " .. points
if (comment) then
entry = entry .. " " .. comment
end
local ok = anchored_search("../state/points.log", entry, " ")
if (not ok) then
return false, "Points already awarded"
end
local f = io.open("../state/points.new/" .. filename, "a")
if (not f) then
return false, "Unable to write to points file"
end
f:write(os.time(), " ", entry, "\n")
f:close()
return true
end
return koth

View File

@ -20,11 +20,13 @@ if (not found) then
koth.page("Wrong answer")
end
local ok = koth.award_points(team, category, points, "P");
local ok, err = koth.award_points(team, category, points)
if (not ok) then
koth.page("Error awarding points", "You got the right answer, but something blew up trying to give you points. Try again in a few seconds.")
koth.page("Error awarding points",
"<p>You got the right answer, but something blew up trying to give you points.</p>" ..
"<p>" .. err .. "</p>")
end
koth.page("Points awarded",
"<p>" .. points .. " points for " .. team .. ".</p>" ..
"<p>" .. points .. " points for " .. team .. "!</p>" ..
"<p><a href=\"puzzles.html\">Back to puzzles</a></p>")