# Unlock / chapter / refuel badge cards go to the Crypto Team Build "Game Achievements" topic (DR_TG_ACH_TOPIC); payout
# cards stay in DR_TG_PUBLIC_TOPIC (the payments topic). Plus /api/public/today for the shared 6 PM games summary.
p = 'D:/Projects/HighRisk/drip-runner/server.js'
s = open(p, encoding='utf-8').read()
R = [
("async function telegramPhoto(file, caption, general) {\n if (!outbound()) return false;\n const tok = process.env.DR_TG_TOKEN, chat = process.env.DR_TG_PUBLIC_CHAT || process.env.DR_TG_CHAT, topic = process.env.DR_TG_PUBLIC_CHAT ? process.env.DR_TG_PUBLIC_TOPIC : null;",
"async function telegramPhoto(file, caption, general, topicOverride) {\n if (!outbound()) return false;\n const tok = process.env.DR_TG_TOKEN, chat = process.env.DR_TG_PUBLIC_CHAT || process.env.DR_TG_CHAT, topic = process.env.DR_TG_PUBLIC_CHAT ? (topicOverride || process.env.DR_TG_PUBLIC_TOPIC) : null;"),
(" const ok = await telegramPhoto(file, cap);\n if (ok && String(process.env.DR_TG_PUBLIC_GENERAL || 'off') === 'on') await telegramPhoto(file, cap, true);",
" const ok = await telegramPhoto(file, cap, false, opts.topic);\n if (ok && String(process.env.DR_TG_PUBLIC_GENERAL || 'off') === 'on') await telegramPhoto(file, cap, true);"),
("const ITEM_NAMES = { magnet:",
"// badges and milestones = the achievements topic (Marty, 2026-10-01); payout cards keep DR_TG_PUBLIC_TOPIC\nconst ACH = () => process.env.DR_TG_ACH_TOPIC || '';\nconst ITEM_NAMES = { magnet:"),
("unlocked the ' + ITEM_NAMES[item] + ' (' + paid + ')' }).catch(() => {}); }",
"unlocked the ' + ITEM_NAMES[item] + ' (' + paid + ')', topic: ACH() }).catch(() => {}); }"),
("'' + (pol ? ' \\u00b7 +' + fmt(pol) + ' POL' : '') }).catch(() => {}); }",
"'' + (pol ? ' \\u00b7 +' + fmt(pol) + ' POL' : ''), topic: ACH() }).catch(() => {}); }"),
("Every refuel is a verified visit to a member\\u2019s page on InstantAdPay.' }).catch(() => {}); }",
"Every refuel is a verified visit to a member\\u2019s page on InstantAdPay.', topic: ACH() }).catch(() => {}); }"),
(" if (p === '/api/public/stats' && req.method === 'GET') {",
" // the last 24 hours for the shared 6 PM games summary in the achievements topic (counts only, no POL amounts)\n"
" if (p === '/api/public/today' && req.method === 'GET') {\n"
" const since = Date.now() - 24 * 3600000, t = v => typeof v === 'number' ? v : Date.parse(v) || 0;\n"
" const refuels = store.read('refuels', []).filter(x => t(x.ts) >= since), clears = store.read('drips', []).filter(x => t(x.ts) >= since);\n"
" const players = Object.values(store.read('players', {})).filter(x => x.memberId > 0);\n"
" return json(res, 200, { refuels: refuels.length, clears: clears.length, runners: new Set([...refuels, ...clears].map(x => x.memberId)).size, newRunners: players.filter(x => t(x.since) >= since).length });\n"
" }\n"
" if (p === '/api/public/stats' && req.method === 'GET') {"),
]
for a, b in R:
if s.count(a) != 1: raise SystemExit('anchor %d: %s' % (s.count(a), a[:90]))
s = s.replace(a, b)
open(p, 'w', encoding='utf-8').write(s); print('drip runner ok')