Game Pass bridge (GAMEPASS=on): finds and Ad Detective cases via InstantAdPay polgrant (daily, fail closed), 5 missions + 2 cases perks, Pass Tournament prize payer from this faucet (claims before send, dry run, alerts), tests
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
+29
-16
@@ -35,13 +35,16 @@ function draw(min, max, skew) {
|
||||
// day defaults to today: called without it the comparison was against undefined and silently
|
||||
// returned 0 for everyone, which would read as "no finds yet" to any new caller
|
||||
function findsToday(memberId, day) { const d = day || ctDay(); return store.read('payouts', []).filter(p => p.memberId === Number(memberId) && p.day === d && p.status !== 'failed' && !p.prize && !p.ref && !p.detective).length; }
|
||||
function daily(memberId, doneIds, bonus) { const s = settings(); const base = Math.max(1, Number(s.missionsPerDay) || 3);
|
||||
// passExtra: the Game Pass perk, +2 missions a day while the member's pass is active (GAME-PASS.md 4: 3 -> 5); 0 otherwise
|
||||
function daily(memberId, doneIds, bonus, passExtra) { const s = settings(); const base = Math.max(1, Number(s.missionsPerDay) || 3);
|
||||
// every live paid mission this hunter has not done yet adds one, because the company is not
|
||||
// funding that completion
|
||||
let extra = 0; try { extra = require('./paid').extraAllowance(doneIds); } catch (e) {}
|
||||
// Friday Bonus Hunts: extra hunts banked Sat-Thu on InstantAdPay, usable on Friday only (lib/fridaybank.js)
|
||||
const fb = Math.max(0, Number(bonus) || 0);
|
||||
const limit = base + extra + fb; const done = findsToday(memberId, ctDay()); return { limit, done, left: Math.max(0, limit - done), base, friday: fb }; }
|
||||
const fb = Math.max(0, Number(bonus) || 0), pe = Math.max(0, Number(passExtra) || 0);
|
||||
const limit = base + extra + fb + pe; const done = findsToday(memberId, ctDay()); return { limit, done, left: Math.max(0, limit - done), base, friday: fb, pass: pe }; }
|
||||
// the nominal amount a completion of `mission` would pay (the Game Pass asks InstantAdPay about it before grant() records it)
|
||||
function quote(mission) { const s = settings(); return mission.paid ? Math.round(Number(mission.hunterPol || 0) * 10000) / 10000 : draw(Number(s.minPol), Number(s.maxPol)); }
|
||||
// What the COMPANY has spent today. Advertiser-funded completions are excluded on purpose: the
|
||||
// hunter is paid out of what the advertiser already put in the faucet, so counting it here would
|
||||
// let a paid mission use up the house budget (Marty, 2026-09-24).
|
||||
@@ -62,28 +65,37 @@ function doneToday(memberId, wallet) {
|
||||
return new Set(store.read('payouts', []).filter(p => p.day === day && p.status !== 'failed' && !p.prize && !p.ref && !p.detective && (p.memberId === Number(memberId) || (w && p.wallet && String(p.wallet).toLowerCase() === w))).map(p => p.missionId));
|
||||
}
|
||||
|
||||
// record a completion; decide paid-today vs queued
|
||||
function grant(member, mission) {
|
||||
const s = settings();
|
||||
// record a completion; decide paid-today vs queued.
|
||||
// opts (the Game Pass, GAME-PASS.md 3a): { pol, status, gp, nominal }: `pol` is what InstantAdPay allowed (0 = the account-wide daily
|
||||
// cap is reached: the find is recorded with status 'capped', pays nothing, and still counts as today's find); status 'gp-wait' = IAP
|
||||
// could not be reached, the row holds the nominal amount and is settled by settleQueued() when the retry queue gets an answer.
|
||||
function grant(member, mission, opts) {
|
||||
opts = opts || {}; const s = settings();
|
||||
// An advertiser-funded mission pays exactly what the advertiser set, every time. No draw, so
|
||||
// the reserve taken at purchase is exact and can never come up short.
|
||||
const isPaid = !!mission.paid;
|
||||
const pol = isPaid ? Math.round(Number(mission.hunterPol || 0) * 10000) / 10000
|
||||
: draw(Number(s.minPol), Number(s.maxPol));
|
||||
const pol = opts.pol != null ? Math.round(Number(opts.pol) * 10000) / 10000 : quote(mission);
|
||||
const day = ctDay();
|
||||
const budgetLeft = mission.budget ? mission.budget - store.read('payouts', []).filter(p => p.missionId === mission.id && p.status !== 'failed').length : Infinity;
|
||||
if (budgetLeft <= 0) return { error: 'This mission has paid out all it was funded for.' };
|
||||
// the house cap governs house spend only; a paid completion is already funded
|
||||
const overCap = !isPaid && (paidToday(day) + pol > Number(s.dailyCapPol));
|
||||
const overCap = pol > 0 && !isPaid && (paidToday(day) + pol > Number(s.dailyCapPol));
|
||||
const rec = {
|
||||
id: Date.now().toString(36) + Math.random().toString(36).slice(2, 8),
|
||||
memberId: Number(member.memberId), email: member.email, wallet: member.wallet, username: member.username || null,
|
||||
missionId: mission.id, site: mission.site, pol, day, at: Date.now(),
|
||||
paid: isPaid || undefined, // marks advertiser-funded spend so the house accounting skips it
|
||||
status: overCap ? 'queued' : 'due', tx: null, paidAt: null, error: null,
|
||||
status: opts.status || (pol > 0 ? (overCap ? 'queued' : 'due') : 'capped'), tx: null, paidAt: null, error: null,
|
||||
gp: opts.gp || undefined, nominal: opts.nominal != null ? opts.nominal : undefined,
|
||||
};
|
||||
store.update('payouts', [], all => { all.push(rec); return all; });
|
||||
return { ok: true, rec, queued: overCap };
|
||||
return { ok: true, rec, queued: rec.status === 'queued', capped: rec.status === 'capped', waiting: rec.status === 'gp-wait' };
|
||||
}
|
||||
// a 'gp-wait' row gets InstantAdPay's answer: pay what was allowed (due, or queued past the house cap), or record the cap hit
|
||||
function settleQueued(id, allowed, gp) {
|
||||
const s = settings(); const pol = Math.round(Number(allowed) * 10000) / 10000; let row = null;
|
||||
store.update('payouts', [], all => { const p = all.find(x => x.id === id); if (p && p.status === 'gp-wait') { const over = pol > 0 && !p.paid && (paidToday(p.day) + pol - (p.pol || 0) > Number(s.dailyCapPol)); Object.assign(p, { pol, status: pol > 0 ? (over ? 'queued' : 'due') : 'capped', gp: Object.assign({}, p.gp || {}, gp || {}, { pending: false }) }); row = p; } return all; });
|
||||
return row;
|
||||
}
|
||||
|
||||
// A fixed, disclosed amount for a non-find task (an Ad Detective case). House money, so it sits inside
|
||||
@@ -91,16 +103,17 @@ function grant(member, mission) {
|
||||
// of the daily limit, the leaderboard, prizes, referral matches and the find badges).
|
||||
function grantFixed(member, t) {
|
||||
const s = settings(); const day = ctDay(); const pol = Math.round(Number(t.pol) * 10000) / 10000;
|
||||
if (!(pol > 0)) return { error: 'no reward set' };
|
||||
const overCap = paidToday(day) + pol > Number(s.dailyCapPol);
|
||||
if (!(pol > 0) && !t.gp) return { error: 'no reward set' }; // the Game Pass may record a 0 (account-wide cap reached), see grant()
|
||||
const overCap = pol > 0 && paidToday(day) + pol > Number(s.dailyCapPol);
|
||||
const rec = {
|
||||
id: Date.now().toString(36) + Math.random().toString(36).slice(2, 8),
|
||||
memberId: Number(member.memberId), email: member.email, wallet: member.wallet, username: member.username || null,
|
||||
missionId: t.missionId, site: t.site, pol, day, at: Date.now(), detective: t.detective || true,
|
||||
status: overCap ? 'queued' : 'due', tx: null, paidAt: null, error: null,
|
||||
status: t.status || (pol > 0 ? (overCap ? 'queued' : 'due') : 'capped'), tx: null, paidAt: null, error: null,
|
||||
gp: t.gp || undefined, nominal: t.nominal != null ? t.nominal : undefined,
|
||||
};
|
||||
store.update('payouts', [], all => { all.push(rec); return all; });
|
||||
return { ok: true, rec, queued: overCap };
|
||||
return { ok: true, rec, queued: rec.status === 'queued', capped: rec.status === 'capped', waiting: rec.status === 'gp-wait' };
|
||||
}
|
||||
|
||||
// what the faucet should pay now: due entries, then queued ones as long as today's cap allows
|
||||
@@ -141,4 +154,4 @@ function totals() {
|
||||
return { paid: paid.length, pol: Math.round(paid.reduce((n, p) => n + p.pol, 0) * 10000) / 10000, queued: all.filter(p => p.status === 'queued').length, today: paidToday(ctDay()), hunters: new Set(paid.map(p => p.memberId)).size };
|
||||
}
|
||||
|
||||
module.exports = { settings, setSettings, draw, grant, grantFixed, completed, doneToday, payable, mark, ledger, mine, totals, paidToday, pool, nextResetAt, daily, findsToday, unposted };
|
||||
module.exports = { settings, setSettings, draw, quote, grant, grantFixed, settleQueued, completed, doneToday, payable, mark, ledger, mine, totals, paidToday, pool, nextResetAt, daily, findsToday, unposted };
|
||||
|
||||
Reference in New Issue
Block a user