Refueled card: every counted Monthly Refuel posts a card with the member's name and streak month to the payments topic and General (plain line stays as the fallback); admin POST /api/admin/refuel/card posts one for a member's current streak (Marty 2026-11-24)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-24 09:38:51 -06:00
parent f4e54b7243
commit aae83329da
4 changed files with 40 additions and 5 deletions
+6 -3
View File
@@ -8,7 +8,7 @@ const path = require('path');
const { spawn } = require('child_process');
let PUBLIC_DIR = null;
const ART = { payouts: { file: 'badge-spark.jpg', ribbonY: 0.728 }, firstBuyer: { file: 'badge-surge.jpg', ribbonY: 0.76 }, level2: { file: 'badge-circuit.jpg', ribbonY: 0.72 }, level3: { file: 'badge-nexus.jpg', ribbonY: 0.73 }, fridays: { file: 'badge-fridays.jpg', ribbonY: 0.719 }, gamepass: { file: 'badge-gamepass.jpg', ribbonY: 0.84 }, stackpro: { file: 'badge-stackpro.jpg', ribbonY: 0.855 }, refuelStart: { file: 'badge-refuelstart.jpg', ribbonY: 0.735 }, refuel3: { file: 'badge-refuel3.jpg', ribbonY: 0.783 }, refuel6: { file: 'badge-refuel6.jpg', ribbonY: 0.716 }, refuel12: { file: 'badge-refuel12.jpg', ribbonY: 0.744 } };
const ART = { payouts: { file: 'badge-spark.jpg', ribbonY: 0.728 }, firstBuyer: { file: 'badge-surge.jpg', ribbonY: 0.76 }, level2: { file: 'badge-circuit.jpg', ribbonY: 0.72 }, level3: { file: 'badge-nexus.jpg', ribbonY: 0.73 }, fridays: { file: 'badge-fridays.jpg', ribbonY: 0.719 }, gamepass: { file: 'badge-gamepass.jpg', ribbonY: 0.84 }, stackpro: { file: 'badge-stackpro.jpg', ribbonY: 0.855 }, refuelStart: { file: 'badge-refuelstart.jpg', ribbonY: 0.735 }, refuelCard: { file: 'card-refuel.jpg', ribbonY: 0.868 }, refuel3: { file: 'badge-refuel3.jpg', ribbonY: 0.783 }, refuel6: { file: 'badge-refuel6.jpg', ribbonY: 0.716 }, refuel12: { file: 'badge-refuel12.jpg', ribbonY: 0.744 } };
let FONT;
function font() {
if (FONT !== undefined) return FONT;
@@ -22,7 +22,8 @@ function font() {
const ffText = t => String(t).replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/:/g, '\\:').replace(/%/g, '%%');
function init(opts) { PUBLIC_DIR = opts.publicDir; }
// returns a JPEG buffer, or null when ffmpeg or the font is missing (caller falls back to the upload)
function render(key, who) {
// extra: more centred lines on the art, [{ text, y (share of the height), size, color }] (the Refueled card puts the streak month in its dark band)
function render(key, who, extra) {
return new Promise(resolve => {
const a = ART[key]; const F = font(); if (!a || !F) return resolve(null);
const src = path.resolve(PUBLIC_DIR, 'badges', a.file); if (!fs.existsSync(src)) return resolve(null);
@@ -32,7 +33,9 @@ function render(key, who) {
const fontFile = winPath ? path.basename(F) : F;
// 1080-wide art: 59px bold gold text with a dark outline, centred on the ribbon (matches the old canvas layout)
const vf = name ? 'drawtext=fontfile=' + fontFile + ":text='" + ffText(name) + "':fontcolor=#ffd15c:fontsize=59:borderw=7:bordercolor=0x04140f@0.9:x=(w-text_w)/2:y=" + a.ribbonY + '*h-text_h/2' : 'null';
const p = spawn('ffmpeg', ['-v', 'error', '-i', src, '-vf', vf, '-frames:v', '1', '-q:v', '3', '-f', 'image2pipe', '-vcodec', 'mjpeg', 'pipe:1'], { stdio: ['ignore', 'pipe', 'pipe'], cwd: winPath ? path.dirname(F) : undefined });
const more = (extra || []).filter(l => l && l.text).map(l => 'drawtext=fontfile=' + fontFile + ":text='" + ffText(String(l.text).slice(0, 48)) + "':fontcolor=" + (l.color || '#ffd15c') + ':fontsize=' + (Number(l.size) || 48) + ':borderw=5:bordercolor=0x04140f@0.9:x=(w-text_w)/2:y=' + Number(l.y) + '*h-text_h/2');
const vfAll = more.length ? (vf === 'null' ? more.join(',') : [vf].concat(more).join(',')) : vf;
const p = spawn('ffmpeg', ['-v', 'error', '-i', src, '-vf', vfAll, '-frames:v', '1', '-q:v', '3', '-f', 'image2pipe', '-vcodec', 'mjpeg', 'pipe:1'], { stdio: ['ignore', 'pipe', 'pipe'], cwd: winPath ? path.dirname(F) : undefined });
const chunks = []; let err = '';
p.stdout.on('data', c => chunks.push(c)); p.stderr.on('data', c => { err += c; });
p.on('error', () => resolve(null));
Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

+14 -2
View File
@@ -227,7 +227,11 @@ async function record(p) {
if (!out.repeat && out.badges && X.badge) for (const b of out.badges) { try { await X.badge(email, b); } catch (e) { console.error('refuel badge', e.message); } }
// one short line in the payments feed for every counted refuel (never a Pit Stop), once per tx across app copies
if (!out.repeat && out.kind === 'refuel' && X.feed && (!X.marks || await X.marks.claim('rffeed:' + tx))) {
try { await X.feed(await feedLine(email, out)); } catch (e) { console.error('refuel feed', e.message); }
// every counted refuel gets a card with the member's name and streak month (Marty 2026-11-24: "others need to see
// that they're doing it"); the plain line is the fallback when the card cannot be drawn or sent
let carded = false;
if (X.card) { try { carded = !!(await X.card(email, { who: await whoOf(email), month: out.month, both: !!out.both, site: out.site, siteName: NAME[out.site] })); } catch (e) { console.error('refuel card', e.message); } }
if (!carded) { try { await X.feed(await feedLine(email, out)); } catch (e) { console.error('refuel feed', e.message); } }
}
// a counted refuel of $50+ (either site) earns a Downline Banners spot, paid by the company (Marty 2026-11-13), once per tx
if (!out.repeat && out.kind === 'refuel' && cents >= 5000 && X.refuelSpot && (!X.marks || await X.marks.claim('rfspot:' + tx))) {
@@ -242,6 +246,14 @@ async function whoOf(email) {
let a = null; try { a = await X.accounts.byEmail(email); } catch (e) {}
return a && a.username ? '@' + a.username : a && a.memberId ? 'member #' + a.memberId : 'a member';
}
// admin: post the Refueled card for a member's CURRENT streak (a refuel counted before the card existed, or a resend)
async function cardNow(email, o) {
email = String(email || '').toLowerCase(); o = o || {};
const rec = await getRec(email); if (!rec || !rec.active || !rec.streak) return { error: 'That member has no active refuel streak.' };
if (!X.card) return { error: 'No card sender.' };
const site = o.site === 'linkspin' ? 'linkspin' : 'iap';
return { ok: !!(await X.card(email, { who: await whoOf(email), month: rec.streak, both: !!o.both, site, siteName: NAME[site] })), month: rec.streak };
}
async function feedLine(email, out) {
const who = (await whoOf(email)).replace(/[<>&]/g, '');
const what = out.both ? 'refueled both engines' : 'refueled ' + NAME[out.site];
@@ -430,5 +442,5 @@ async function stats() {
recent: rows.slice(0, 40).map(r => ({ ref: r.ref, site: r.site, email: r.email, kind: r.kind === 'grant' ? r.payload.kind : 'reminder:' + r.payload.remind, credits: r.payload.credits || 0, status: r.status, at: r.created })) };
}
module.exports = { standing, setGoal, init, cfg, record, roundup, weekOf, feedLine, onIapPurchase, decide, settle, blank, view, streakLine, badgesOf, outbox, ack, drainLocal, tick, stats, reminderCopy,
module.exports = { standing, setGoal, init, cfg, record, roundup, weekOf, feedLine, cardNow, onIapPurchase, decide, settle, blank, view, streakLine, badgesOf, outbox, ack, drainLocal, tick, stats, reminderCopy,
_days: { ctDay, addDays, diffDays, label, ctHour }, SINGLE, BOTH };
+20
View File
@@ -747,6 +747,21 @@ async function boot() {
message: async (to, subject, html) => { await messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [to], subject, html, 'notice'); },
badge: (email, key) => postBadgeOnce(email, key, 'Monthly Refuel'),
refuelSpot: refuelSpotToBL, // $50+ counted refuel -> one Downline Banners spot (2026-11-13)
// the Refueled card: payments topic + General, like a badge. Returns false when nothing went out (refuel.js then posts the plain line)
card: async (email, r) => {
const sc = siteConfig(); if (!sc.telegramBotToken || !sc.telegramEchoChatId) return false;
const a = await accounts.byEmail(String(email || '').toLowerCase()).catch(() => null);
const name = a && a.username ? a.username : (a && a.memberId ? 'member #' + a.memberId : 'a member');
const jpeg = await badge.render('refuelCard', name, [{ text: 'STREAK MONTH ' + r.month, y: 0.662, size: 62 }, { text: r.both ? 'Both engines: InstantAdPay + LinkSpin' : 'Refueled on ' + r.siteName, y: 0.722, size: 32, color: '#bff5dc' }]);
if (!jpeg) return false;
const who = String(r.who || name).replace(/[<>&]/g, '');
const caption = '⛽ <b>InstantAdPay</b> · <b>' + who + '</b> ' + (r.both ? 'refueled both engines' : 'refueled ' + r.siteName) + ' · streak month ' + r.month + '\n' + (a && a.username ? 'instantadpay.com/join/' + a.username : 'instantadpay.com');
let sent = 0;
if (await telegramSendPhoto(sc.telegramEchoChatId, jpeg, caption, sc.telegramEchoTopicId)) sent++;
if (String(sc.telegramBadgeGeneral || '1') !== '0' && await telegramSendPhoto(sc.telegramEchoChatId, jpeg, caption, null)) sent++;
console.log('refuel card', name, 'month', r.month, 'sent', sent);
return sent > 0;
},
feed: async text => { const sc = siteConfig(); if (!sc.telegramBotToken || !sc.telegramEchoChatId) return false; return telegramSend(sc.telegramEchoChatId, '\u{1F7E0} <b>InstantAdPay</b> \u00b7 ' + text, sc.telegramEchoTopicId); } });
kit.init({ dataDir: DATA_DIR, program: 'iap', publicDir: PUBLIC_DIR, siteUrl: 'https://instantadpay.com',
entitled: async email => { const v = await refuel.view(email); return v && v.on ? { on: true, months: v.kits || {}, nextRefuel: v.refuelDayLabel || null, today: v.today || null } : { on: false }; },
@@ -6101,6 +6116,11 @@ const server = http.createServer(async (req, res) => {
if (r.error) return json(res, 400, r);
res.writeHead(200, { 'Content-Type': { png: 'image/png', jpg: 'image/jpeg', gif: 'image/gif' }[r.ext], 'Cache-Control': 'no-store' }); return fs.createReadStream(r.file).pipe(res);
}
if (p === '/api/admin/refuel/card' && req.method === 'POST') { // post the Refueled card for a member's current streak (2026-11-24)
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const b = await readBody(req); const r = await refuel.cardNow(b.email, { both: !!b.both, site: b.site });
return json(res, r.error ? 400 : 200, r);
}
if (p === '/api/admin/refuel' && req.method === 'GET') { // Monthly Refuel: settings, members on a streak, grants by kind, recent outbox rows
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
return json(res, 200, await refuel.stats());