Mystery Hunt Box + Ad Detective, badge tiers

Finish the day's Code Hunts to unlock one box a day. It opens to an Ad
Detective case on one site with a fixed 0.15 POL reward shown up front:
visit (the embed records the visit after the dwell, no code), then answer
one question, one attempt. Paid inside the house cap, never counted as a
find. 34-question bank seeded from lib/detective-bank.json; a hunter never
repeats a question until they have seen every one for that site. Admin
panel with per-question stats and retire/restore.

New badges (all ledger-derived): Detective, Sleuth, Investigator, Master
Detective; Scout, Guide, Trail Boss; Week Sweep; 7-Day Streak. Badges
already earned on deploy are marked announced without posting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-26 16:10:17 -05:00
parent 64ab0b505f
commit 469cbf69a5
25 changed files with 1334 additions and 423 deletions
+7 -3
View File
@@ -41,9 +41,10 @@ function forMember(memberId) {
}
// ---- tokens ------------------------------------------------------------------------------
function issue(memberId, missionId) {
// extra: { kind: 'detective', boxId } for an Ad Detective case (lib/detective.js); a Code Hunt token has no kind
function issue(memberId, missionId, extra) {
const t = crypto.randomBytes(16).toString('hex');
const rec = { t, memberId: Number(memberId), missionId, iat: Date.now(), exp: Date.now() + TOKEN_TTL };
const rec = Object.assign({ t, memberId: Number(memberId), missionId, iat: Date.now(), exp: Date.now() + TOKEN_TTL }, extra || {});
store.update('tokens', {}, all => { for (const k of Object.keys(all)) if (all[k].exp < Date.now() - 3600000) delete all[k]; all[t] = rec; return all; });
return rec;
}
@@ -64,6 +65,8 @@ function codeForEmbed(t, origin) {
if (!allowed.includes(host)) return { error: 'origin' };
const waited = (Date.now() - rec.iat) / 1000;
if (waited < (m.dwell || 30)) return { wait: Math.ceil((m.dwell || 30) - waited) };
// an Ad Detective case shows no code: the visit itself is the receipt, and the question waits on the board
if (rec.kind === 'detective') { try { if (module.exports.onVisit) module.exports.onVisit(rec); } catch (e) { console.error('detective visit', e.message); } return { visited: true, slot: slotFor(rec, m.slots || 1) }; }
return { code: codeFor(rec), slot: slotFor(rec, m.slots || 1) };
}
@@ -71,6 +74,7 @@ function codeForEmbed(t, origin) {
function check(t, memberId, typed) {
const rec = token(t); if (!rec) return { error: 'That mission timed out. Start it again from your board.' };
if (rec.memberId !== Number(memberId)) return { error: 'That mission belongs to a different account.' };
if (rec.kind) return { error: 'That is an Ad Detective case. Answer its question on your board.' };
const want = codeFor(rec);
const got = String(typed || '').trim().toUpperCase();
if (got.length !== 6) return { error: 'Codes are 6 characters and you typed ' + got.length + '. Look at the site again: the code sits in six boxes, and a tap on it copies all six.' };
@@ -78,4 +82,4 @@ function check(t, memberId, typed) {
return { ok: true, rec };
}
module.exports = { list, get, save, remove, forMember, issue, token, codeForEmbed, check, ctDay };
module.exports = { list, get, save, remove, forMember, issue, token, codeForEmbed, check, ctDay, onVisit: null };