Stack POL Pro badge: granted or comped Pro no longer posts to Telegram (the 111 pre-launch grants were posting one by one as members opened their dashboards); Pro from a member's own purchase still posts (Marty 2026-11-21)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-21 09:18:16 -06:00
parent 50bd2e3557
commit 7ca7514c42
+6
View File
@@ -1768,8 +1768,12 @@ 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).
// Stack POL Pro given by a grant or comp never posts its badge to Telegram; Pro from the member's own purchase still does (Marty 2026-11-21:
// "If someone purchases one, that's fine but it's just too noisy when all the grants are popping up"). The admin re-post button still works.
function badgeSilent(email, key) { if (key !== 'stackpro') return false; let r = null; try { r = gamepass.stackPro(email); } catch (e) {} return !!(r && (r.via === 'comp' || r.note)); }
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;
if (badgeSilent(e, key)) { mine[key] = { ts: Date.now(), sent: 0, silent: true }; log[e] = mine; try { fs.writeFileSync(BADGE_LOG(), JSON.stringify(log)); } catch (er) {} 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';
@@ -3658,6 +3662,8 @@ const server = http.createServer(async (req, res) => {
if (!held.includes(key)) return json(res, 400, { error: 'You have not unlocked that badge yet.' });
const log = badgeLog(); const mine = log[s.email] || {};
if (mine[key]) return json(res, 200, { ok: true, already: true });
// granted Stack POL Pro is silent (see badgeSilent): logged so the page stops asking, nothing sent
if (badgeSilent(s.email, key) && u.searchParams.get('manual') !== '1') { mine[key] = { ts: Date.now(), sent: 0, silent: true }; log[s.email] = mine; try { fs.writeFileSync(BADGE_LOG(), JSON.stringify(log)); } catch (e) {} return json(res, 200, { ok: true, already: true, silent: true }); }
// manual re-posts (the button) are Marty's only; members' badges go out automatically on unlock
if (u.searchParams.get('manual') === '1' && s.email !== ADMIN_EMAIL) return json(res, 403, { error: 'Badges post automatically when they unlock.' });
const a = await accounts.byEmail(s.email);