diff --git a/chatbot.js b/chatbot.js index 99ddcf6..c53330c 100644 --- a/chatbot.js +++ b/chatbot.js @@ -12,7 +12,11 @@ const core = require('./chatcore'); const C = require('./config').get(); -const KNOWLEDGE_DATE = '2026-11-16'; +const KNOWLEDGE_DATE = '2026-11-17'; +// Network Weekend (Black Friday to Cyber Monday 2026): live Fri 11-27 00:00 CT to Tue 12-01 00:00 CT (CST = UTC-6); WEEKEND_NOW = test clock +const NW_START = Date.parse('2026-11-27T06:00:00Z'), NW_END = Date.parse('2026-12-01T06:00:00Z'); +const nwNow = () => { const t = process.env.WEEKEND_NOW ? Date.parse(process.env.WEEKEND_NOW) : NaN; return Number.isNaN(t) ? Date.now() : t; }; +const nwLive = () => { const t = nwNow(); return t >= NW_START && t < NW_END; }; const URL_ = 'https://' + C.site; const SUPPORT = 'https://instantadpay.com/support'; const NOT_PROMISED = 'Nothing is promised: you are paid only when spots sell after yours, and a spot can earn back less than it cost.'; @@ -83,8 +87,9 @@ const FACTS = () => [ '- TAKEDOWN: the admin can take down a spot that breaks the rules, with a reason. It is hidden everywhere (board, gate, links, Network Ad Space), keeps its place (a house banner holds it, nobody moves), counts no views while down; the owner sees "Taken down" with the reason on My Spots. On-chain payments already happened at purchase and never change; there is no refund. The admin can restore it.', '- REFUEL SPOTS: a counted Monthly Refuel of $50+ on InstantAdPay or LinkSpin earns one spot, bought for the member under their network sponsor, paid by the company.', '- BOARD: open slots show members\' LinkSpin Banner Spins, then network house ads (InstantAdPay, LinkSpin, network games). Pages: /, /board, /how, /join, /my, /promote, /ledger, /contract, /terms, /disclaimer, /privacy.', + (nwLive() ? '- NETWORK WEEKEND (live now, Black Friday to Cyber Monday, Fri 11-27 to Mon 11-30, midnight to midnight Central): Downline Banners has no price or split change (a spot stays $5). The weekend idea here is gifting: on /join, "Buy a spot for someone else" pays a $5 spot for a teammate, the spot is theirs and the payment splits exactly like any other spot. Every network deal: https://instantadpay.com/weekend' : null), '- NO REFUNDS: blockchain payments are final. SUPPORT for account or payment problems: network support at ' + SUPPORT + ' (InstantAdPay runs the one desk for every network site). This is advertising with a share of later sales, not an investment. Nothing is promised.' -].join('\n'); +].filter(Boolean).join('\n'); const SITE = { id: 'bannerline', hubSite: 'bannerline', netId: 'dlb', name: 'Downline Banners', url: URL_, supportUrl: SUPPORT, knowledgeDate: KNOWLEDGE_DATE, diff --git a/netdeals.js b/netdeals.js new file mode 100644 index 0000000..e708583 --- /dev/null +++ b/netdeals.js @@ -0,0 +1,54 @@ +// Network deals for this site's "Network Weekend" ribbon (Marty 2026-11-17). One source: the hub's public GET /v1/network-deals +// (HUB_URL). Cached 2 minutes, refreshed in the background, never waits on a slow hub (2.5 s timeout); hub down = no ribbon. +// The same file lives in every network site. Never RM Circle, never the games (the hub list never names them). +// The page (/assets/netweekend.js) switches the ribbon on and off by its own clock at startsAt / endsAt, so a cached copy never +// shows early or late. setLocal(fn) lets a site rewrite its own deal line from live data (for example a price read from chain), +// so the ribbon never shows a number the contract does not charge: fn(deal) returns the deal, a changed copy, or null to drop it. +const TTL = 2 * 60 * 1000; +let cache = { at: 0, body: { events: [] } }; +let inflight = null; +let local = null; + +const hubUrl = () => String(process.env.HUB_URL || 'https://hub.saasy.top').trim().replace(/\/+$/, ''); +const safeUrl = u => (/^https:\/\/[a-z0-9.-]+(\/[^\s"'<>]*)?$/i.test(String(u || '')) ? String(u) : ''); +const str = (v, n) => String(v == null ? '' : v).slice(0, n || 300); +function clean(j) { + if (!j || !Array.isArray(j.events)) return null; + return { events: j.events.slice(0, 5).filter(e => e && e.id && !Number.isNaN(Date.parse(e.startsAt)) && !Number.isNaN(Date.parse(e.endsAt))).map(e => ({ + id: str(e.id, 60), name: str(e.name, 60), tagline: str(e.tagline, 160), url: safeUrl(e.url), startsAt: e.startsAt, endsAt: e.endsAt, + days: e.days && typeof e.days === 'object' ? Object.fromEntries(Object.entries(e.days).slice(0, 20).map(([k, v]) => [str(k, 10), str(v, 40)])) : {}, + deals: (Array.isArray(e.deals) ? e.deals : []).slice(0, 40).map(d => { + const x = { site: str(d.site, 30), name: str(d.name, 80), url: safeUrl(d.url), text: str(d.text), endsAt: Number.isNaN(Date.parse(d.endsAt)) ? e.endsAt : d.endsAt }; + if (d.note) x.note = str(d.note, 120); + if (d.byDay && typeof d.byDay === 'object') x.byDay = Object.fromEntries(Object.entries(d.byDay).slice(0, 20).map(([k, v]) => [str(k, 10), str(v)])); + return x; + }) + })) }; +} +function refresh() { + if (inflight || process.env.NETWORK_DEALS_HUB === '0') return inflight; + const ac = new AbortController(); const t = setTimeout(() => ac.abort(), 2500); + inflight = fetch(hubUrl() + '/v1/network-deals', { signal: ac.signal }) + .then(r => (r.ok ? r.json() : null)) + .then(j => { const b = clean(j); if (b) cache = { at: Date.now(), body: b }; else cache.at = Date.now(); }) + .catch(() => { cache.at = Date.now() - TTL + 30 * 1000; }) // hub down: try again in 30 s, keep the last good copy + .finally(() => { clearTimeout(t); inflight = null; }); + return inflight; +} +function current() { if (Date.now() - cache.at > TTL) refresh(); return cache.body; } +function setLocal(fn) { local = typeof fn === 'function' ? fn : null; } +function withLocal(body, self) { + if (!local) return body; + return { events: body.events.map(e => Object.assign({}, e, { deals: e.deals.map(d => { + if (d.site !== self) return d; + try { const r = local(Object.assign({}, d)); return r === undefined ? d : r; } catch (err) { return d; } + }).filter(Boolean) })) }; +} +// GET /api/network-deals: public, short cache, the same answer on every page. self = this site's network id (NETWORK_SITE_ID). +function handle(req, res, self) { + const me = String(self || process.env.NETWORK_SITE_ID || '').trim().toLowerCase(); + const body = Object.assign({ self: me }, withLocal(current(), me)); + res.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'public, max-age=60', 'X-Content-Type-Options': 'nosniff' }); + res.end(JSON.stringify(body)); +} +module.exports = { current, handle, refresh, setLocal, clean, _set: b => { cache = { at: Date.now(), body: clean(b) || { events: [] } }; } }; diff --git a/public/admin.html b/public/admin.html index 82f1458..076bbbf 100644 --- a/public/admin.html +++ b/public/admin.html @@ -24,7 +24,7 @@
- +