mirror of https://github.com/dirtbags/moth.git
Puzzler that awards points. Maybe.
This commit is contained in:
parent
bf3dc9a19e
commit
752165cb0b
3
bin/once
3
bin/once
|
@ -15,6 +15,9 @@ fi
|
||||||
|
|
||||||
# Collect new points
|
# Collect new points
|
||||||
find state/points.new -type f | while read fn; do
|
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
|
cat $fn >> state/points.log
|
||||||
rm $fn
|
rm $fn
|
||||||
done
|
done
|
||||||
|
|
27
cgi/koth.lua
27
cgi/koth.lua
|
@ -41,5 +41,32 @@ function koth.page(title, body)
|
||||||
os.exit(0)
|
os.exit(0)
|
||||||
end
|
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
|
return koth
|
||||||
|
|
|
@ -20,11 +20,13 @@ if (not found) then
|
||||||
koth.page("Wrong answer")
|
koth.page("Wrong answer")
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok = koth.award_points(team, category, points, "P");
|
local ok, err = koth.award_points(team, category, points)
|
||||||
if (not ok) then
|
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
|
end
|
||||||
|
|
||||||
koth.page("Points awarded",
|
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>")
|
"<p><a href=\"puzzles.html\">Back to puzzles</a></p>")
|
||||||
|
|
Loading…
Reference in New Issue