Badge cards post to the CTB Game Achievements topic (HUNT_TG_ACH_TOPIC); finds, Ad Detective payouts, bounties and prizes 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:
@@ -58,16 +58,16 @@ detective.init();
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
// ---- Telegram (outward: gated) ------------------------------------------------------------
|
// ---- Telegram (outward: gated) ------------------------------------------------------------
|
||||||
async function telegram(text) {
|
async function telegram(text, topicOverride) {
|
||||||
if (!outbound()) return false; // the gate
|
if (!outbound()) return false; // the gate
|
||||||
const tok = process.env.HUNT_TG_TOKEN, chat = process.env.HUNT_TG_CHAT, topic = process.env.HUNT_TG_TOPIC;
|
const tok = process.env.HUNT_TG_TOKEN, chat = process.env.HUNT_TG_CHAT, topic = topicOverride || process.env.HUNT_TG_TOPIC;
|
||||||
if (!tok || !chat) return false;
|
if (!tok || !chat) return false;
|
||||||
const body = JSON.stringify(Object.assign({ chat_id: chat, text, parse_mode: 'HTML', disable_web_page_preview: true }, topic ? { message_thread_id: Number(topic) } : {}));
|
const body = JSON.stringify(Object.assign({ chat_id: chat, text, parse_mode: 'HTML', disable_web_page_preview: true }, topic ? { message_thread_id: Number(topic) } : {}));
|
||||||
try { const r = await fetch('https://api.telegram.org/bot' + tok + '/sendMessage', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body }); return r.ok; } catch (e) { return false; }
|
try { const r = await fetch('https://api.telegram.org/bot' + tok + '/sendMessage', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body }); return r.ok; } catch (e) { return false; }
|
||||||
}
|
}
|
||||||
async function telegramPhoto(file, caption, general) {
|
async function telegramPhoto(file, caption, general, topicOverride) {
|
||||||
if (!outbound()) return false; // the gate
|
if (!outbound()) return false; // the gate
|
||||||
const tok = process.env.HUNT_TG_TOKEN, chat = process.env.HUNT_TG_CHAT, topic = process.env.HUNT_TG_TOPIC;
|
const tok = process.env.HUNT_TG_TOKEN, chat = process.env.HUNT_TG_CHAT, topic = topicOverride || process.env.HUNT_TG_TOPIC;
|
||||||
if (!tok || !chat || !file) return false;
|
if (!tok || !chat || !file) return false;
|
||||||
try {
|
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));
|
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));
|
||||||
@@ -99,7 +99,7 @@ async function notifyOther(kind, p) {
|
|||||||
}
|
}
|
||||||
async function notifyBadge(p) { const ok = await postBadge(p); if (ok) store.update('badges-posted', {}, all => { const k = String(p.me.memberId); all[k] = Array.from(new Set([...(all[k] || []), p.id])); return all; }); return ok; }
|
async function notifyBadge(p) { const ok = await postBadge(p); if (ok) store.update('badges-posted', {}, all => { const k = String(p.me.memberId); all[k] = Array.from(new Set([...(all[k] || []), p.id])); return all; }); return ok; }
|
||||||
async function postBadge(p) {
|
async function postBadge(p) {
|
||||||
{ const b = social.BADGES.find(x => x.id === p.id); if (!b) return false; const who = social.nameOf(p.me); const file = await badge.render(p.id, p.me.username || '#' + p.me.memberId); const cap = '\u{1F3C6} <b>PolHunter</b> \u00b7 <b>' + (p.me.username ? '@' + p.me.username : '#' + p.me.memberId) + '</b> unlocked <b>' + b.name + '</b>: ' + b.why + '\n' + SITE + '/b/' + who + '/' + p.id; if (!file) return telegram(cap); const ok = await telegramPhoto(file, cap); if (String(process.env.HUNT_TG_BADGE_GENERAL || 'on') === 'on') await telegramPhoto(file, cap, true); return ok; }
|
{ const b = social.BADGES.find(x => x.id === p.id); if (!b) return false; const who = social.nameOf(p.me); const file = await badge.render(p.id, p.me.username || '#' + p.me.memberId); const cap = '\u{1F3C6} <b>PolHunter</b> \u00b7 <b>' + (p.me.username ? '@' + p.me.username : '#' + p.me.memberId) + '</b> unlocked <b>' + b.name + '</b>: ' + b.why + '\n' + SITE + '/b/' + who + '/' + p.id; const ach = process.env.HUNT_TG_ACH_TOPIC || ''; /* badges = achievements topic (Marty, 2026-10-01); payouts stay in HUNT_TG_TOPIC */ if (!file) return telegram(cap, ach); const ok = await telegramPhoto(file, cap, false, ach); if (String(process.env.HUNT_TG_BADGE_GENERAL || 'on') === 'on') await telegramPhoto(file, cap, true); return ok; }
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Marty's rule (2026-09-19): when the day's pool is spent, say so; claims reopen at midnight Central
|
// Marty's rule (2026-09-19): when the day's pool is spent, say so; claims reopen at midnight Central
|
||||||
@@ -227,6 +227,13 @@ const server = http.createServer(async (req, res) => {
|
|||||||
if (p === '/logout') { const s = sso.fromRequest(req); if (s) sso.endSession(s.sid); res.writeHead(302, { Location: '/', 'Set-Cookie': sso.clearCookie() }); return res.end(); }
|
if (p === '/logout') { const s = sso.fromRequest(req); if (s) sso.endSession(s.sid); res.writeHead(302, { Location: '/', 'Set-Cookie': sso.clearCookie() }); return res.end(); }
|
||||||
|
|
||||||
// ---- public
|
// ---- public
|
||||||
|
// 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 pay = store.read('payouts', []).filter(x => x.status !== 'failed' && t(x.at) >= since && !x.prize && !(x.ref && x.ref.forName));
|
||||||
|
const hunters = Object.values(store.read('hunters', {}));
|
||||||
|
return json(res, 200, { finds: pay.filter(x => !x.detective).length, cases: pay.filter(x => x.detective).length, hunters: new Set(pay.map(x => x.memberId)).size, newHunters: hunters.filter(h => t(h.firstSeen || h.joinedAt) >= since).length });
|
||||||
|
}
|
||||||
if (p === '/api/config') { const ref = refOf(req); return json(res, 200, { name: 'PolHunter', signupsOpen: signupsOpen(), reward: rewards.settings(), iapUrl: 'https://instantadpay.com/my', explorer: explorer(), ref, joinUrl: ref ? 'https://instantadpay.com/join/' + encodeURIComponent(ref) + '?from=polhunter' : 'https://instantadpay.com/?from=polhunter' }); }
|
if (p === '/api/config') { const ref = refOf(req); return json(res, 200, { name: 'PolHunter', signupsOpen: signupsOpen(), reward: rewards.settings(), iapUrl: 'https://instantadpay.com/my', explorer: explorer(), ref, joinUrl: ref ? 'https://instantadpay.com/join/' + encodeURIComponent(ref) + '?from=polhunter' : 'https://instantadpay.com/?from=polhunter' }); }
|
||||||
if (p === '/api/leaders') { const per = ['week', 'month', 'all'].includes(u.searchParams.get('period')) ? u.searchParams.get('period') : 'week'; return json(res, 200, { period: per, rows: social.leaderboard(per, 25) }, { 'Cache-Control': 'public, max-age=60' }); }
|
if (p === '/api/leaders') { const per = ['week', 'month', 'all'].includes(u.searchParams.get('period')) ? u.searchParams.get('period') : 'week'; return json(res, 200, { period: per, rows: social.leaderboard(per, 25) }, { 'Cache-Control': 'public, max-age=60' }); }
|
||||||
if (p === '/api/badges') return json(res, 200, { badges: social.BADGES.map(b => Object.assign({ art: '/badges/badge-' + b.id + '.jpg' }, b)) });
|
if (p === '/api/badges') return json(res, 200, { badges: social.BADGES.map(b => Object.assign({ art: '/badges/badge-' + b.id + '.jpg' }, b)) });
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# Badge cards go to the Crypto Team Build "Game Achievements" topic (HUNT_TG_ACH_TOPIC); finds, Ad Detective payouts,
|
||||||
|
# bounties and weekly prizes stay in the payments topic (HUNT_TG_TOPIC). Plus /api/public/today for the 6 PM games summary.
|
||||||
|
p = 'D:/Projects/HighRisk/polhunter/server.js'
|
||||||
|
s = open(p, encoding='utf-8').read()
|
||||||
|
R = [
|
||||||
|
("async function telegramPhoto(file, caption, general) {\n if (!outbound()) return false; // the gate\n const tok = process.env.HUNT_TG_TOKEN, chat = process.env.HUNT_TG_CHAT, topic = process.env.HUNT_TG_TOPIC;",
|
||||||
|
"async function telegramPhoto(file, caption, general, topicOverride) {\n if (!outbound()) return false; // the gate\n const tok = process.env.HUNT_TG_TOKEN, chat = process.env.HUNT_TG_CHAT, topic = topicOverride || process.env.HUNT_TG_TOPIC;"),
|
||||||
|
("async function telegram(text) {\n if (!outbound()) return false; // the gate\n const tok = process.env.HUNT_TG_TOKEN, chat = process.env.HUNT_TG_CHAT, topic = process.env.HUNT_TG_TOPIC;",
|
||||||
|
"async function telegram(text, topicOverride) {\n if (!outbound()) return false; // the gate\n const tok = process.env.HUNT_TG_TOKEN, chat = process.env.HUNT_TG_CHAT, topic = topicOverride || process.env.HUNT_TG_TOPIC;"),
|
||||||
|
("if (!file) return telegram(cap); const ok = await telegramPhoto(file, cap); if (String(process.env.HUNT_TG_BADGE_GENERAL",
|
||||||
|
"const ach = process.env.HUNT_TG_ACH_TOPIC || ''; /* badges = achievements topic (Marty, 2026-10-01); payouts stay in HUNT_TG_TOPIC */ if (!file) return telegram(cap, ach); const ok = await telegramPhoto(file, cap, false, ach); if (String(process.env.HUNT_TG_BADGE_GENERAL"),
|
||||||
|
(" if (p === '/api/config') {",
|
||||||
|
" // 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 pay = store.read('payouts', []).filter(x => x.status !== 'failed' && t(x.at) >= since && !x.prize && !(x.ref && x.ref.forName));\n"
|
||||||
|
" const hunters = Object.values(store.read('hunters', {}));\n"
|
||||||
|
" return json(res, 200, { finds: pay.filter(x => !x.detective).length, cases: pay.filter(x => x.detective).length, hunters: new Set(pay.map(x => x.memberId)).size, newHunters: hunters.filter(h => t(h.firstSeen || h.joinedAt) >= since).length });\n"
|
||||||
|
" }\n"
|
||||||
|
" if (p === '/api/config') {"),
|
||||||
|
]
|
||||||
|
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('polhunter ok')
|
||||||
Reference in New Issue
Block a user