Badge and milestone cards post to the CTB Game Achievements topic (DR_TG_ACH_TOPIC); payout cards stay in the payments topic. /api/public/today for the shared 6 PM games summary
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -49,9 +49,9 @@ async function telegram(text) {
|
||||
const fmt = n => Number(n).toLocaleString('en-US', { maximumFractionDigits: 4 });
|
||||
// ---- public badge posts (Marty, 2026-09-30): unlocks, chapter and refuel milestones, payouts, as photo cards ----
|
||||
// DR_TG_PUBLIC_CHAT / DR_TG_PUBLIC_TOPIC = the room (PolHunter's), DR_TG_PUBLIC_GENERAL=on also posts the photo to the general channel.
|
||||
async function telegramPhoto(file, caption, general) {
|
||||
async function telegramPhoto(file, caption, general, topicOverride) {
|
||||
if (!outbound()) return false;
|
||||
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;
|
||||
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;
|
||||
if (!tok || !chat || !file) return false;
|
||||
try {
|
||||
const fd = new FormData(); fd.append('chat_id', chat); fd.append('caption', caption); fd.append('parse_mode', 'HTML'); if (topic && !general) fd.append('message_thread_id', String(topic));
|
||||
@@ -77,14 +77,16 @@ async function announce(id, me, opts) {
|
||||
const foot = trial() ? '<i>Testers are playing a preview. When Drip Runner goes live, amounts like this pay out in POL to the wallet on your InstantAdPay account.</i>' : '<i>Play from your InstantAdPay dashboard.</i>';
|
||||
const cap = head + '\n' + line2 + '\n' + foot;
|
||||
if (!file) return telegram(cap);
|
||||
const ok = await telegramPhoto(file, cap);
|
||||
const ok = await telegramPhoto(file, cap, false, opts.topic);
|
||||
if (ok && String(process.env.DR_TG_PUBLIC_GENERAL || 'off') === 'on') await telegramPhoto(file, cap, true);
|
||||
return ok;
|
||||
}
|
||||
// badges and milestones = the achievements topic (Marty, 2026-10-01); payout cards keep DR_TG_PUBLIC_TOPIC
|
||||
const ACH = () => process.env.DR_TG_ACH_TOPIC || '';
|
||||
const ITEM_NAMES = { magnet: 'Drip Magnet', ship: 'Courier Mk II', shield: 'Shield Core', slow: 'Slow Field' };
|
||||
function announceUnlock(me, item, paid) { if (!badge.BADGES[item]) return; announce(item, me, { caption: '\u{1F3AE} <b>Drip Runner</b> \u00b7 <b>' + nameOf(me) + '</b> unlocked the <b>' + ITEM_NAMES[item] + '</b> (' + paid + ')' }).catch(() => {}); }
|
||||
function announceChapter(me, ch, pol) { const id = badge.CHAPTER_BADGES[ch]; if (!id) return; announce(id, me, { caption: '\u{1F3C1} <b>Drip Runner</b> \u00b7 <b>' + nameOf(me) + '</b> cleared <b>Chapter ' + ch + '</b>' + (pol ? ' \u00b7 <b>+' + fmt(pol) + ' POL</b>' : '') }).catch(() => {}); }
|
||||
function announceRefuels(me) { const n = store.read('refuels', []).filter(r => r.memberId === Number(me.memberId)).length; const id = badge.REFUEL_BADGES[n]; if (!id) return; announce(id, me, { caption: '\u26FD <b>Drip Runner</b> \u00b7 <b>' + nameOf(me) + '</b> has refuelled <b>' + n + ' times</b>. Every refuel is a verified visit to a member\u2019s page on InstantAdPay.' }).catch(() => {}); }
|
||||
function announceUnlock(me, item, paid) { if (!badge.BADGES[item]) return; announce(item, me, { caption: '\u{1F3AE} <b>Drip Runner</b> \u00b7 <b>' + nameOf(me) + '</b> unlocked the <b>' + ITEM_NAMES[item] + '</b> (' + paid + ')', topic: ACH() }).catch(() => {}); }
|
||||
function announceChapter(me, ch, pol) { const id = badge.CHAPTER_BADGES[ch]; if (!id) return; announce(id, me, { caption: '\u{1F3C1} <b>Drip Runner</b> \u00b7 <b>' + nameOf(me) + '</b> cleared <b>Chapter ' + ch + '</b>' + (pol ? ' \u00b7 <b>+' + fmt(pol) + ' POL</b>' : ''), topic: ACH() }).catch(() => {}); }
|
||||
function announceRefuels(me) { const n = store.read('refuels', []).filter(r => r.memberId === Number(me.memberId)).length; const id = badge.REFUEL_BADGES[n]; if (!id) return; announce(id, me, { caption: '\u26FD <b>Drip Runner</b> \u00b7 <b>' + nameOf(me) + '</b> has refuelled <b>' + n + ' times</b>. Every refuel is a verified visit to a member\u2019s page on InstantAdPay.', topic: ACH() }).catch(() => {}); }
|
||||
function announcePaid(p) { announce('paid', { memberId: p.memberId, username: p.username }, { key: 'paid:' + p.id, caption: '\u{1F4B8} <b>Drip Runner</b> \u00b7 <b>' + nameOf(p) + '</b> was paid <b>' + fmt(p.pol) + ' POL</b> \u00b7 <a href="' + explorer() + '/tx/' + p.tx + '">verify</a>', line2: 'paid ' + fmt(p.pol) + ' POL to their wallet \u00b7 ' + earningsLine(p.memberId).replace(/^earned [^\u00b7]+\u00b7 /, '') }).catch(() => {}); }
|
||||
const explorer = () => Number(process.env.DR_CHAIN_ID) === 80002 ? 'https://amoy.polygonscan.com' : 'https://polygonscan.com';
|
||||
async function notify(kind, p) {
|
||||
@@ -225,6 +227,13 @@ const server = http.createServer(async (req, res) => {
|
||||
// ---- member API ----
|
||||
if (p.startsWith('/api/')) {
|
||||
// the landing page's live numbers (public, no personal data)
|
||||
// the last 24 hours for the shared 6 PM games summary in the achievements topic (counts only, no POL amounts)
|
||||
if (p === '/api/public/today' && req.method === 'GET') {
|
||||
const since = Date.now() - 24 * 3600000, t = v => typeof v === 'number' ? v : Date.parse(v) || 0;
|
||||
const refuels = store.read('refuels', []).filter(x => t(x.ts) >= since), clears = store.read('drips', []).filter(x => t(x.ts) >= since);
|
||||
const players = Object.values(store.read('players', {})).filter(x => x.memberId > 0);
|
||||
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 });
|
||||
}
|
||||
if (p === '/api/public/stats' && req.method === 'GET') {
|
||||
const players = Object.values(store.read('players', {})).filter(x => x.memberId > 0).length;
|
||||
const paid = store.read('payouts', []).filter(x => x.status === 'paid');
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# 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 <b>' + ITEM_NAMES[item] + '</b> (' + paid + ')' }).catch(() => {}); }",
|
||||
"unlocked the <b>' + ITEM_NAMES[item] + '</b> (' + paid + ')', topic: ACH() }).catch(() => {}); }"),
|
||||
("'</b>' + (pol ? ' \\u00b7 <b>+' + fmt(pol) + ' POL</b>' : '') }).catch(() => {}); }",
|
||||
"'</b>' + (pol ? ' \\u00b7 <b>+' + fmt(pol) + ' POL</b>' : ''), 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')
|
||||
Reference in New Issue
Block a user