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));