Free tier and full tier (Marty 2026-11-02, every game must fund itself): a free InstantAdPay account hunts one code a day drawn on 0.02 to 0.10 POL; Game Pass holders keep five a day at the full draw, the weekly prizes and the Mystery Hunt Box (a box already open stays reachable); advertiser-funded finds pay what the advertiser set on every tier; with GAMEPASS off everyone stays on the full tier. New settings freeMissionsPerDay / freeMinPol / freeMaxPol (admin), tests updated
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,10 @@ const IAP_URL = String(process.env.IAP_URL || 'https://instantadpay.com').replac
|
||||
gp.use({ game: 'polhunter', secret: String(process.env.HUNT_SSO_SECRET || '').trim(), iap: IAP_URL, store, notify: (kind, p) => notify(kind, p) });
|
||||
const passActive = me => !!(gp.on() && me && gp.passOf(me.memberId, me.email).active);
|
||||
const passExtra = me => passActive(me) ? 2 : 0; // the perk: 5 missions a day instead of 3
|
||||
// the full tier (Marty 2026-11-02): Game Pass holders get the full allotment, the full draw, the weekly prizes and the Mystery Box;
|
||||
// a free account gets the free tier (lib/rewards.js freeMissionsPerDay / freeMinPol / freeMaxPol). With GAMEPASS off there is no
|
||||
// pass to buy, so everyone stays on the full tier as before.
|
||||
const fullTier = me => !gp.on() || passActive(me);
|
||||
// one reward through IAP: ask(pol, ref) -> IAP's answer (+ the player-facing note), wait(rowId, pol, ref) -> queue the ref (fail closed)
|
||||
const gpGate = me => ({
|
||||
ask: async (pol, ref) => { const r = await gp.grant({ memberId: me.memberId, email: me.email, kind: 'daily', pol, ref }); r.note = gp.note(r, 'daily', pol); return r; },
|
||||
@@ -124,7 +128,7 @@ async function postBadge(p) {
|
||||
return false;
|
||||
}
|
||||
// Marty's rule (2026-09-19): when the day's pool is spent, say so; claims reopen at midnight Central
|
||||
const dailyMsg = d => 'That is your ' + (['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight'][d.limit] || d.limit) + ' for today. Fresh missions at midnight Central.';
|
||||
const dailyMsg = d => 'That is your ' + (['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight'][d.limit] || d.limit) + ' for today. Fresh missions at midnight Central.' + (d.pass ? '' : ' Game Pass holders hunt five a day at the full reward.'); // free tier since 2026-11-02
|
||||
const SPENT_MSG = 'Today\u2019s POL pool is spent. No more claims today. Claims reopen at midnight Central.';
|
||||
function refOf(req) { const m = /(?:^|;\s*)ph\.ref=([^;]+)/.exec(req.headers.cookie || ''); const r = m ? decodeURIComponent(m[1]) : ''; return /^[A-Za-z0-9_.-]{1,40}$/.test(r) ? r : null; }
|
||||
function explorer() { return Number(process.env.HUNT_CHAIN_ID) === 80002 ? 'https://amoy.polygonscan.com' : 'https://polygonscan.com'; }
|
||||
@@ -279,14 +283,14 @@ const server = http.createServer(async (req, res) => {
|
||||
return json(res, 200, { me: { memberId: me.memberId, username: me.username, wallet: me.wallet }, missions: missions.forMember(me.memberId).map(m => Object.assign(pubMission(m), { done: done.has(m.id) || wdone.has(m.id) })), drips: rewards.mine(me.memberId).slice(0, 20), faucet: { on: faucetOn }, pool: rewards.pool(), daily: rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fbank.bonus, passExtra(me)), fridayBank: fbank, gamepass: gp.view(me.memberId, me.email),
|
||||
badges: social.badgesFor(me.memberId), badgeCards: (() => { const got = new Set(social.badgesFor(me.memberId).map(b => b.id)); const who = social.nameOf(me); return social.BADGES.map(b => ({ id: b.id, name: b.name, icon: b.icon, why: b.why, art: '/badges/badge-' + b.id + '.jpg', earned: got.has(b.id), page: got.has(b.id) ? SITE + '/b/' + who + '/' + b.id : null, image: got.has(b.id) ? SITE + '/badge-img/' + who + '/' + b.id + '.jpg' : null })); })(), rank: { week: social.rankOf(me.memberId, 'week'), month: social.rankOf(me.memberId, 'month'), all: social.rankOf(me.memberId, 'all') },
|
||||
share: { link: social.shareLink(SITE, me), joinUrl: 'https://instantadpay.com/join/' + encodeURIComponent(String(me.username || me.memberId)) + '?from=polhunter' },
|
||||
referral: referrals.state(me), box: detective.view(me) });
|
||||
referral: referrals.state(me), box: detective.view(me, fullTier(me)) });
|
||||
}
|
||||
if (p === '/api/my/start' && req.method === 'POST') {
|
||||
const b = await readBody(req); const m = missions.get(String(b.missionId || '')); if (!m || !m.active) return json(res, 404, { error: 'That mission is not open.' });
|
||||
if (!me.wallet) return json(res, 400, { error: 'Link a wallet on InstantAdPay first so the drip has somewhere to land, then open PolHunter again.' });
|
||||
if (rewards.completed(me.memberId, m.id, me.wallet)) return json(res, 400, { error: 'You already completed this one.' });
|
||||
{ const pool = rewards.pool(); if (pool.spent) return json(res, 400, { error: SPENT_MSG, spent: true, resetsAt: pool.resetsAt }); }
|
||||
{ const fb = await fbFor(me); const d = rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fb.bonus, passExtra(me)); if (!d.left) return json(res, 400, { error: dailyMsg(d), dailyDone: true, resetsAt: rewards.pool().resetsAt }); }
|
||||
{ const fb = await fbFor(me); const d = rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fb.bonus, passExtra(me), fullTier(me)); if (!d.left) return json(res, 400, { error: dailyMsg(d), dailyDone: true, resetsAt: rewards.pool().resetsAt }); }
|
||||
if (limited('start:' + me.memberId, 20, 3600000)) return json(res, 429, { error: 'Easy. Twenty starts an hour is plenty.' });
|
||||
const t = missions.issue(me.memberId, m.id);
|
||||
// a mission URL may place the token itself with {token} (a Telegram Mini App takes it in
|
||||
@@ -302,14 +306,14 @@ const server = http.createServer(async (req, res) => {
|
||||
const m = missions.get(c.rec.missionId); if (!m) return json(res, 404, { error: 'That mission is gone.' });
|
||||
if (rewards.completed(me.memberId, m.id, me.wallet)) return json(res, 400, { error: 'You already completed this one.' });
|
||||
{ const pool = rewards.pool(); if (pool.spent) return json(res, 400, { error: SPENT_MSG, spent: true, resetsAt: pool.resetsAt }); }
|
||||
{ const fb = await fbFor(me); const d = rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fb.bonus, passExtra(me)); if (!d.left) return json(res, 400, { error: dailyMsg(d), dailyDone: true, resetsAt: rewards.pool().resetsAt }); }
|
||||
{ const fb = await fbFor(me); const d = rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fb.bonus, passExtra(me), fullTier(me)); if (!d.left) return json(res, 400, { error: dailyMsg(d), dailyDone: true, resetsAt: rewards.pool().resetsAt }); }
|
||||
const before = new Set(social.badgesFor(me.memberId).map(b => b.id));
|
||||
let g, note = null;
|
||||
if (gp.on() && !m.paid) { // the Game Pass: IAP's account-wide daily cap first (a paid mission is the advertiser's money, not gated)
|
||||
const quote = rewards.quote(m), ref = 'find:' + m.id + ':' + missions.ctDay(), r = await gpGate(me).ask(quote, ref); note = r.note;
|
||||
const quote = rewards.quote(m, fullTier(me)), ref = 'find:' + m.id + ':' + missions.ctDay(), r = await gpGate(me).ask(quote, ref); note = r.note;
|
||||
if (r.retry) { g = rewards.grant(me, m, { pol: quote, status: 'gp-wait', nominal: quote, gp: { ref, kind: 'daily', nominal: quote, pending: true } }); if (!g.error) gpGate(me).wait(g.rec.id, quote, ref); }
|
||||
else g = rewards.grant(me, m, { pol: r.allowed, nominal: quote, gp: { ref, kind: 'daily', nominal: quote, pass: !!r.pass, capHit: r.capHit || null } });
|
||||
} else g = rewards.grant(me, m);
|
||||
} else g = rewards.grant(me, m, { pass: fullTier(me) });
|
||||
if (g.error) return json(res, 400, g);
|
||||
// whoever brought this hunter gets paid for it: the bounty on their first find, a match while they are new
|
||||
let refDrips = [];
|
||||
@@ -322,7 +326,7 @@ const server = http.createServer(async (req, res) => {
|
||||
message: g.waiting ? 'Found it. ' + note : g.capped ? 'Found it. ' + note : g.queued ? 'Found it. Today’s POL is spoken for, so yours is queued and pays out next.' : 'Found it. ' + fmt(g.rec.pol) + ' POL is on its way to your wallet.' + (note ? ' ' + note : '') });
|
||||
}
|
||||
// ---- Mystery Hunt Box + Ad Detective
|
||||
if (p === '/api/my/box/open' && req.method === 'POST') { const r = detective.open(me, passActive(me)); return json(res, r.error ? 400 : 200, r.error ? r : { ok: true, box: detective.view(me) }); } // pass: a second case a day
|
||||
if (p === '/api/my/box/open' && req.method === 'POST') { const r = detective.open(me, passActive(me), fullTier(me)); return json(res, r.error ? 400 : 200, r.error ? r : { ok: true, box: detective.view(me, fullTier(me)) }); } // pass: a second case a day
|
||||
if (p === '/api/my/box/start' && req.method === 'POST') {
|
||||
if (!me.wallet) return json(res, 400, { error: 'Link a wallet on InstantAdPay first so the reward has somewhere to land.' });
|
||||
if (limited('boxstart:' + me.memberId, 20, 3600000)) return json(res, 429, { error: 'Easy. Try again in a little while.' });
|
||||
@@ -336,7 +340,7 @@ const server = http.createServer(async (req, res) => {
|
||||
const unlocked = r.correct ? social.badgesFor(me.memberId).filter(x => !before.has(x.id)) : [];
|
||||
for (const x of unlocked) notify('badge', { me, id: x.id }).catch(() => {});
|
||||
const msg = r.correct ? (r.queued ? 'Case solved. Today\u2019s POL is spoken for, so your ' + fmt(r.pol) + ' POL is queued and pays out next.' : 'Case solved. ' + fmt(r.pol) + ' POL is on its way to your wallet.') : 'Not this time. The answer was: ' + r.answer + '. A new box unlocks tomorrow.';
|
||||
return json(res, 200, { ok: true, correct: r.correct, pol: r.pol, nominal: r.nominal, queued: r.queued, capped: r.capped, waiting: r.waiting, note: r.note || null, unlocked: unlocked.map(x => x.id), message: msg + (r.note ? ' ' + r.note : ''), box: detective.view(me), gamepass: gp.view(me.memberId, me.email) });
|
||||
return json(res, 200, { ok: true, correct: r.correct, pol: r.pol, nominal: r.nominal, queued: r.queued, capped: r.capped, waiting: r.waiting, note: r.note || null, unlocked: unlocked.map(x => x.id), message: msg + (r.note ? ' ' + r.note : ''), box: detective.view(me, fullTier(me)), gamepass: gp.view(me.memberId, me.email) });
|
||||
}
|
||||
return json(res, 404, { error: 'No such call.' });
|
||||
}
|
||||
@@ -355,7 +359,7 @@ const server = http.createServer(async (req, res) => {
|
||||
return json(res, 200, { ok: true, missions: missions.list() });
|
||||
}
|
||||
if (p === '/api/admin/mission' && req.method === 'DELETE') { const b = await readBody(req); missions.remove(String(b.id || '')); return json(res, 200, { ok: true, missions: missions.list() }); }
|
||||
if (p === '/api/admin/settings' && req.method === 'POST') { const b = await readBody(req); const patch = {}; for (const k of ['minPol', 'maxPol', 'dailyCapPol', 'lowBalancePol', 'weeklyMinFinds', 'drawSkew', 'missionsPerDay', 'detectiveOn', 'detectivePol', 'refEnabled', 'refBountyPol', 'refMatchPct', 'refMatchDays', 'refNewDays', 'refCapPol', 'refMatchMinPol']) if (b[k] != null && Number(b[k]) >= 0) patch[k] = Number(b[k]); for (const k of ['weeklyPrizes', 'leaderboardExclude']) if (Array.isArray(b[k])) patch[k] = b[k].map(Number).filter(n => n >= 0); return json(res, 200, { ok: true, settings: rewards.setSettings(patch) }); }
|
||||
if (p === '/api/admin/settings' && req.method === 'POST') { const b = await readBody(req); const patch = {}; for (const k of ['minPol', 'maxPol', 'dailyCapPol', 'lowBalancePol', 'weeklyMinFinds', 'drawSkew', 'missionsPerDay', 'freeMissionsPerDay', 'freeMinPol', 'freeMaxPol', 'detectiveOn', 'detectivePol', 'refEnabled', 'refBountyPol', 'refMatchPct', 'refMatchDays', 'refNewDays', 'refCapPol', 'refMatchMinPol']) if (b[k] != null && Number(b[k]) >= 0) patch[k] = Number(b[k]); for (const k of ['weeklyPrizes', 'leaderboardExclude']) if (Array.isArray(b[k])) patch[k] = b[k].map(Number).filter(n => n >= 0); return json(res, 200, { ok: true, settings: rewards.setSettings(patch) }); }
|
||||
// award a week by hand (its Monday key); already-awarded weeks are skipped
|
||||
if (p === '/api/admin/prizes/award' && req.method === 'POST') { const b = await readBody(req); const r = social.awardWeek(String(b.week || '')); if (r && r.winners && r.winners.length) notify('prize', r).catch(() => {}); return json(res, r && r.error ? 400 : 200, r); }
|
||||
// Ad Detective question bank: stats per question, add or edit one, retire or restore one
|
||||
|
||||
Reference in New Issue
Block a user