Five Dollar Friday Game Pass perk, automatic (Marty 2026-10-23): a $5+ Friday package also gives the buyer a free 7-day Game Pass, once per member per Friday (event_marks claim), not on top of a purchase that itself started a paid pass; on-site notice; the Game Pass badge posts once ever (postBadgeOnce). Switch: fridayPassPerk '0'. Counts as no sale (comp).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -528,10 +528,11 @@ async function boot() {
|
||||
if (!mine) return;
|
||||
emailOnEvent(ev).catch(() => {});
|
||||
telegramOnEvent(ev).catch(() => {});
|
||||
friday.onEvent(ev).catch(e => console.error('friday bonus', e.message));
|
||||
starter.onEvent(ev).catch(e => console.error('starter bonus', e.message));
|
||||
pwMintOnEvent(ev).catch(e => console.error('polywarriors mint', e.message));
|
||||
gamepass.onEvent(ev).catch(e => console.error('gamepass order', e.message));
|
||||
// the Friday bonus and the pass order first, then the Friday pass perk, which needs both results (Marty 2026-10-23)
|
||||
Promise.all([friday.onEvent(ev).catch(e => { console.error('friday bonus', e.message); return null; }), gamepass.onEvent(ev).catch(e => { console.error('gamepass order', e.message); return null; })])
|
||||
.then(([bonus, gp]) => fridayPassPerk(ev, bonus, gp)).catch(e => console.error('friday pass perk', e.message));
|
||||
wednesday.onEvent(ev).catch(e => console.error('wednesday bonus', e.message));
|
||||
sponsorSyncOnEvent(ev).catch(e => console.error('sponsor sync', e.message));
|
||||
}).catch(e => console.error('marks claim', e.message));
|
||||
@@ -1465,6 +1466,47 @@ async function telegramSendPhoto(chatId, jpeg, caption, threadId) {
|
||||
const BADGE_META = { payouts: ['Spark', 'payouts switched on'], firstBuyer: ['Surge', 'first qualifying buyer'], level2: ['Circuit', 'two qualifying buyers, level 2 open'], level3: ['Nexus', 'five qualifying buyers, fully qualified'], fridays: ['Five Fridays', 'five Five Dollar Fridays in a row'], gamepass: ['Game Pass', 'Game Pass holder'] };
|
||||
const BADGE_LOG = () => path.join(DATA_DIR, 'badge-posts.json');
|
||||
function badgeLog() { try { return JSON.parse(fs.readFileSync(BADGE_LOG(), 'utf8')); } catch (e) { return {}; } }
|
||||
// Post a member's badge to the payments topic + General ONCE ever (the same card and caption as an unlock). Used by the
|
||||
// automatic Friday Game Pass perk; returns how many chats it reached (0 when already posted or not configured).
|
||||
async function postBadgeOnce(email, key, note) {
|
||||
const e = String(email || '').toLowerCase(); const log = badgeLog(); const mine = log[e] || {}; if (mine[key] || !BADGE_META[key]) return 0;
|
||||
const a = await accounts.byEmail(e); if (!a) return 0;
|
||||
const who = a.username ? '@' + a.username : (a.memberId ? 'member #' + a.memberId : 'a member');
|
||||
const link = a.username ? 'instantadpay.com/join/' + a.username : 'instantadpay.com';
|
||||
const [label, sub] = BADGE_META[key];
|
||||
const caption = '\u{1F3C6} <b>InstantAdPay</b> · <b>' + who.replace(/[<>&]/g, '') + '</b> unlocked <b>' + label + '</b>: ' + sub + (note ? ' · ' + note : '') + '\n' + link;
|
||||
const jpeg = await badge.render(key, a.username || ('member #' + a.memberId)); if (!jpeg) return 0;
|
||||
mine[key] = { ts: Date.now(), sent: 0, auto: note || true }; log[e] = mine; try { fs.writeFileSync(BADGE_LOG(), JSON.stringify(log)); } catch (er) {} // claim first: no double post
|
||||
const sc = siteConfig(); let sent = 0;
|
||||
if (sc.telegramBotToken && sc.telegramEchoChatId) {
|
||||
if (await telegramSendPhoto(sc.telegramEchoChatId, jpeg, caption, sc.telegramEchoTopicId)) sent++;
|
||||
if (String(sc.telegramBadgeGeneral || '1') !== '0' && await telegramSendPhoto(sc.telegramEchoChatId, jpeg, caption, null)) sent++;
|
||||
}
|
||||
mine[key].sent = sent; log[e] = mine; try { fs.writeFileSync(BADGE_LOG(), JSON.stringify(log)); } catch (er) {}
|
||||
pushFeed({ type: 'Badge', member: who, label, ts: Date.now() });
|
||||
console.log('badge posted (auto)', e, key, 'sent', sent);
|
||||
return sent;
|
||||
}
|
||||
// Five Dollar Friday Game Pass perk (Marty 2026-10-23: "this should happen automatically every Friday"): a $5+ package on a
|
||||
// Friday (the Friday bonus landed, so it qualified) also gives the buyer a free 7-day Game Pass, once per member per Friday.
|
||||
// A purchase that itself started a paid pass gets no second week on top. The Game Pass badge posts only the first time a
|
||||
// member ever holds a pass. Counts as no sale (comp). Switch: site setting fridayPassPerk '0' turns it off.
|
||||
async function fridayPassPerk(ev, bonus, gp) {
|
||||
if (!(Number(bonus) > 0) || gp) return null;
|
||||
if (String(siteConfig().fridayPassPerk || '1') === '0' || !gamepass.cfg().enabled) return null;
|
||||
const a = await accounts.byMemberId(ev.buyerId); if (!a || !a.email) return null;
|
||||
const ms = Number(ev.ts) > 1e12 ? Number(ev.ts) : (Number(ev.ts) > 0 ? Number(ev.ts) * 1000 : Date.now());
|
||||
const day = new Date(ms).toLocaleDateString('en-CA', { timeZone: 'America/Chicago' });
|
||||
if (!(await marks.claim('fdfpass:' + day + ':' + a.email))) return null; // once per member per Friday, across app copies
|
||||
const r = gamepass.comp(a.email, 'Five Dollar Friday perk ' + day, 'weekly');
|
||||
console.log('friday pass perk', a.email, day, 'until', new Date(r.until).toISOString());
|
||||
try {
|
||||
const until = new Date(r.until).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' });
|
||||
await messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [a.email], 'Five Dollar Friday: a free Game Pass week', '<p>Your Friday package came with a free 7-day Game Pass, on top of the Friday bonus credits. It runs until ' + until + ' Central, across all nine games.</p>', 'notice');
|
||||
} catch (e) { console.error('friday pass notice', e.message); }
|
||||
try { await postBadgeOnce(a.email, 'gamepass', 'Five Dollar Friday'); } catch (e) { console.error('friday pass badge', e.message); }
|
||||
return r;
|
||||
}
|
||||
|
||||
// ---- live feed (SSE) ----
|
||||
const feedClients = new Set();
|
||||
|
||||
Reference in New Issue
Block a user