Weekly award asks InstantAdPay fresh for every contender's Game Pass before deciding (the stored copy said @bizventures had no pass while InstantAdPay had it active to 11-27, costing him 2nd place for the week of 11-16); no answer = wait for the next tick, never decide on the stored copy; a repeated grant ref no longer overwrites the stored pass with its old value

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-23 08:33:19 -06:00
parent a71d8ea276
commit d915884409
3 changed files with 37 additions and 4 deletions
+16 -2
View File
@@ -58,7 +58,9 @@ async function grant({ memberId, email, game, kind, pol, ref }) {
const { status, json } = await post('/api/partner/polgrant', body);
if (status !== 200 || !json || typeof json.allowed !== 'number') return { allowed: 0, deferred: 0, carried: 0, pass: false, retry: true, error: 'http ' + status + (json && json.error ? ': ' + json.error : '') };
const out = { allowed: r4(Math.max(0, json.allowed)), deferred: r4(Math.max(0, Number(json.deferred) || 0)), carried: r4(Math.max(0, Number(json.carried) || 0)), pass: !!(json.pass && (json.pass === true || json.pass.active)), day: json.day || ctDay(), capHit: json.capHit || null, enforced: json.enforced !== false, repeat: !!json.repeat, suspended: !!json.suspended, lifetimeHit: !!json.lifetimeHit, freeLifetime: Number(json.freeLifetime) || 0, waiting: r4(Math.max(0, Number(json.waiting) || 0)), retry: false };
rememberPass(body.memberId, body.email, json.pass, json.passUntil || (json.pass && json.pass.until));
// a REPEATED ref answers with the pass state of the day it was first granted (IAP gamepass.grant prev.pass), which can be weeks
// old: never let that overwrite what we know now (2026-11-23, @bizventures recorded as no pass while holding one)
if (!json.repeat) rememberPass(body.memberId, body.email, json.pass, json.passUntil || (json.pass && json.pass.until));
return out;
} catch (e) { return { allowed: 0, deferred: 0, carried: 0, pass: false, retry: true, error: String(e && e.message || e).slice(0, 120) }; }
}
@@ -92,6 +94,18 @@ async function fetchPass(memberId, email) {
return passOf(memberId, email);
} catch (e) { return cur; }
}
// ask InstantAdPay NOW, whatever the stored copy says (the weekly prize run, 2026-11-23): { ok, active }. ok false = IAP did not
// answer, so the caller must wait and ask again, never decide on the stored copy.
async function freshPass(memberId, email) {
const who = whoOf(memberId, email); if (!ready() || !who) return { ok: false, active: false };
try {
const { status, json } = await get('/api/partner/player', who, { m: Number(memberId) || 0, e: String(email || '').toLowerCase() });
if (status === 404) { rememberPass(memberId, email, false); return { ok: true, active: false }; }
if (status !== 200 || !json || json.pass == null) return { ok: false, active: false };
rememberPass(memberId, email, json.pass, json.pass && json.pass.until);
return { ok: true, active: passOf(memberId, email).active };
} catch (e) { return { ok: false, active: false }; }
}
// what the lobby shows: { on, active, until, untilText, url }
function view(memberId, email) {
const p = whoOf(memberId, email) ? passOf(memberId, email) : { active: false, until: null };
@@ -172,4 +186,4 @@ async function credits({ memberId, email, credits: n, ref, note }) {
try { const { status, json } = await post('/api/partner/credits', body); if (status === 200 && json && json.ok) return { ok: true, credits: Number(json.credits) || 0, repeat: !!json.repeat }; return { ok: false, error: 'http ' + status + (json && json.error ? ': ' + json.error : '') }; }
catch (e) { return { ok: false, error: String(e && e.message || e).slice(0, 120) }; }
}
module.exports = { use, on, whoOf, grant, voidGrant, credits, passOf, rememberPass, fetchPass, view, note, enqueue, queue, queued, dequeue, retry, startRetry, stopRetry, tournamentPending, tournamentPaid, PASS_URL, RETRY_MS, GIVE_UP_MS, ctDay, r4, _cfg: () => cfg };
module.exports = { use, on, whoOf, grant, voidGrant, credits, passOf, rememberPass, fetchPass, freshPass, view, note, enqueue, queue, queued, dequeue, retry, startRetry, stopRetry, tournamentPending, tournamentPaid, PASS_URL, RETRY_MS, GIVE_UP_MS, ctDay, r4, _cfg: () => cfg };
+20 -1
View File
@@ -133,8 +133,27 @@ function awardFill(monday) {
return { week: monday, winners: added, filled: added.length };
}
// on every tick: the most recent completed week gets awarded on the first tick after it ends
function awardDue(notify) {
// 2026-11-23: before the award, every hunter who could win (minimum finds reached) has their Game Pass asked fresh from InstantAdPay,
// because awardWeek reads the stored copy and a stale "no pass" cost @bizventures 2nd place. If InstantAdPay does not answer for any
// of them, nothing is awarded on this tick and the next tick (2 minutes) tries again.
let awarding = false;
async function awardDue(notify) {
const last = dayMinus(weekOf(ctDay()), 7);
if (awarding || store.read('prizes', []).some(x => x.week === last)) return null;
awarding = true;
try {
let gp = null; try { gp = require('./polgrant'); } catch (e) {}
if (gp && gp.on && gp.on() && gp.freshPass) {
const rules = prizeRules();
for (const r of weekRows(last).filter(x => x.finds >= rules.minFinds)) {
const f = await gp.freshPass(r.memberId, r.email);
if (!f.ok) { console.warn('prizes: pass check did not answer for', r.who, '- award waits for the next tick'); return null; }
}
}
return awardNow(last, notify);
} finally { awarding = false; }
}
function awardNow(last, notify) {
if (store.read('prizes', []).some(x => x.week === last)) return null;
const r = awardWeek(last);
if (r && r.winners && r.winners.length && notify) notify('prize', r).catch(() => {});