// Friday Bonus Hunts (Marty, 2026-09-26). // // PolHunter hunters bank one extra FRIDAY hunt for each day, Saturday through Thursday (Central), // that they do both of the things InstantAdPay's two slowest ad types need: // - watch at least one video ad (video_seen has a row for that day), and // - open at least one inbox (solo) ad that day (solo_inbox.read_ts falls on that day). // Fairness rule: a member whose inbox had NO unread solo ad at the end of a day can't open one, // so for them the video alone counts that day. Nobody is blocked by an empty inbox. // // Why these two: they were the worst-delivering ad types on 2026-09-26 (about 6-7 views per // campaign per day against 40-50 for banners and text), because they only get a view when a // member chooses to open them. The game gives members a reason to. // // This module only COUNTS. PolHunter decides how many of the banked hunts can be used (capped // by how many missions exist) and only on the Friday itself. 'use strict'; let db = null; function init(deps) { db = deps && deps.db; } const TZ = 'America/Chicago'; const dayOf = ms => new Date(ms).toLocaleDateString('en-CA', { timeZone: TZ }); // Midnight Central at the START of a 'YYYY-MM-DD' day, as epoch ms. Found by testing the two // possible offsets (CDT -5, CST -6) instead of assuming one, so it stays right across DST. function ctStart(dayKey) { for (const off of [5, 6]) { const t = Date.parse(dayKey + 'T00:00:00Z') + off * 3600000; if (dayOf(t) === dayKey && dayOf(t - 1) !== dayKey) return t; } return Date.parse(dayKey + 'T05:00:00Z'); } function addDays(dayKey, n) { const d = new Date(dayKey + 'T12:00:00Z'); d.setUTCDate(d.getUTCDate() + n); return d.toISOString().slice(0, 10); } function weekdayOf(dayKey) { return new Date(dayKey + 'T12:00:00Z').getUTCDay(); } // 0 Sun .. 5 Fri // The Friday this week's banking counts toward: today if today is Friday, otherwise the next one. function fridayFor(now) { const today = dayOf(now || Date.now()); const wd = weekdayOf(today); return addDays(today, (5 - wd + 7) % 7); } // { friday, today, isFriday, window:[Sat..Thu], days:[{day, video, solo, soloNeeded, banked, future}], banked } async function bankFor(email, now) { now = now || Date.now(); const e = String(email || '').trim().toLowerCase(); const friday = fridayFor(now), today = dayOf(now); const days = []; for (let i = 6; i >= 1; i--) days.push(addDays(friday, -i)); // Sat .. Thu const out = { friday, today, isFriday: today === friday, days: [], banked: 0 }; if (!e || !db || !db.enabled()) { out.days = days.map(d => ({ day: d, video: false, solo: false, soloNeeded: true, banked: false, future: d > today })); return out; } const winStart = ctStart(days[0]), winEnd = ctStart(friday); const vids = await db.q('SELECT DISTINCT day FROM video_seen WHERE email=? AND day>=? AND day<=?', [e, days[0], days[5]]); const vset = new Set(vids.map(r => String(r.day instanceof Date ? r.day.toISOString().slice(0, 10) : r.day).slice(0, 10))); // every solo row that could matter: delivered before the window closed const solos = await db.q('SELECT delivered, read_ts FROM solo_inbox WHERE email=? AND delivered < ?', [e, winEnd]); for (const d of days) { const s = ctStart(d), eod = ctStart(addDays(d, 1)); const future = d > today; const video = vset.has(d); const solo = solos.some(r => r.read_ts && Number(r.read_ts) >= s && Number(r.read_ts) < eod); // unread at the end of that day = delivered before end of day and not read by then const unreadAtEnd = solos.some(r => Number(r.delivered) < eod && (!r.read_ts || Number(r.read_ts) >= eod)); // for today, "end of day" hasn't happened; they still need to open one if one is waiting now const soloNeeded = d === today ? solos.some(r => Number(r.delivered) <= now && !r.read_ts) || solo : unreadAtEnd || solo; const banked = !future && video && (solo || !soloNeeded); out.days.push({ day: d, video, solo, soloNeeded, banked, future }); if (banked) out.banked++; } return out; } module.exports = { init, bankFor, fridayFor, ctStart };