diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..538af3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +.wrangler/ +.dev.vars +*.log diff --git a/worker.js b/worker.js new file mode 100644 index 0000000..49dd0f5 --- /dev/null +++ b/worker.js @@ -0,0 +1,298 @@ +// MAKE A MILLY OR IT'S EMBARRASSING +// Horse race: King Omar vs Basic Rhys vs Pussy vs Patty +// Last to $1M is confirmed gay + +const GOAL = 1_000_000; +const STRIPE_KEY_SECRET = null; // Omar's revenue comes from KV metrics + +export default { + async fetch(request, env) { + const url = new URL(request.url); + + // API: update a competitor's revenue (each person calls this with their own secret) + if (url.pathname === '/update' && request.method === 'POST') { + const auth = request.headers.get('Authorization'); + const { competitor, revenue } = await request.json(); + const validKeys = { + rhys: env.RHYS_SECRET, + pussy: env.PUSSY_SECRET, + patty: env.PATTY_SECRET, + omar: env.OMAR_SECRET, + }; + if (!validKeys[competitor] || auth !== `Bearer ${validKeys[competitor]}`) { + return new Response('Unauthorized', { status: 401 }); + } + const comps = JSON.parse(await env.MILLY_METRICS.get('competitors') || '{}'); + if (comps[competitor]) comps[competitor].revenue = parseFloat(revenue) || 0; + await env.MILLY_METRICS.put('competitors', JSON.stringify(comps)); + return new Response('OK'); + } + + // Pull Omar's live revenue from metrics KV (updated by weekly agent) + const [compsRaw, metricsRaw, baselineRaw] = await Promise.all([ + env.MILLY_METRICS.get('competitors'), + env.MILLY_METRICS.get('metrics'), + env.MILLY_METRICS.get('baseline'), + ]); + + const competitors = compsRaw ? JSON.parse(compsRaw) : {}; + const metrics = metricsRaw ? JSON.parse(metricsRaw) : {}; + const baseline = baselineRaw ? JSON.parse(baselineRaw).amount : 0; + + // Omar's revenue comes from the live Stripe metrics + if (competitors.omar) { + competitors.omar.revenue = metrics.total_revenue || 0; + } + + return new Response(render(competitors), { + headers: { 'Content-Type': 'text/html;charset=UTF-8', 'Cache-Control': 'no-store' } + }); + } +}; + +function pct(revenue) { + return Math.min((revenue / GOAL) * 100, 100); +} + +function fmt(n) { + if (n >= 1e6) return `$${(n/1e6).toFixed(3)}M`; + if (n >= 1000) return `$${(n/1000).toFixed(1)}K`; + return `$${n.toFixed(0)}`; +} + +function render(competitors) { + const sorted = Object.entries(competitors).sort((a, b) => b[1].revenue - a[1].revenue); + const leader = sorted[0]; + const loser = sorted[sorted.length - 1]; + + // Build horse positions + const horses = Object.entries(competitors).map(([id, c]) => ({ + id, ...c, + pct: pct(c.revenue), + done: c.revenue >= GOAL + })); + + return ` + + + + +MAKE A MILLY OR IT'S EMBARRASSING ๐Ÿ‡ + + + + + +
+
MAKE A MILLY
OR IT'S EMBARRASSING
+
โš ๏ธ Last to $1,000,000 is confirmed GAY ๐Ÿณ๏ธโ€๐ŸŒˆ
+
4 competitors ยท 4 AIs ยท 1 goal ยท deadline: December 31, 2026
+
+ +
+
+
๐Ÿ
+
+ ${horses.map((h, i) => ` +
+
${i+1}
+
+
+
${h.emoji} ${h.name}
+
via ${h.ai}
+
${fmt(h.revenue)}
+
+
+
$100K
+
$250K
+
$500K
+
$750K
+
+ ๐ŸŽ +
+ ${h.pct > 3 ? `${h.pct.toFixed(2)}%` : ''} +
+
+
`).join('')} +
+
+ +
+
+ ${sorted.map(([id, c], i) => ` +
+
#${i+1}
+
${c.emoji}
+
${c.name}
+
${c.ai}
+
${fmt(c.revenue)}
+
${pct(c.revenue).toFixed(3)}% to $1M
+ + ${i === 0 ? '๐Ÿ† WINNING' : i === sorted.length-1 ? '๐Ÿณ๏ธโ€๐ŸŒˆ LOSING' : i === 1 ? '๐Ÿฅˆ 2nd' : '๐Ÿฅ‰ 3rd'} + +
`).join('')} +
+
+ +
+
Time remaining until the embarrassment
+
+
--
Days
+
--
Hours
+
--
Minutes
+
--
Seconds
+
+
+ + + + + +`; +} diff --git a/wrangler.toml b/wrangler.toml new file mode 100644 index 0000000..ec60a6c --- /dev/null +++ b/wrangler.toml @@ -0,0 +1,13 @@ +name = "milly-countdown" +main = "worker.js" +compatibility_date = "2024-01-01" +account_id = "c29d5b5c11b67dc349843b8731e93b8f" +workers_dev = true + +routes = [ + { pattern = "makeamillyoritsembarassing.theradicalparty.com", custom_domain = true } +] + +[[kv_namespaces]] +binding = "MILLY_METRICS" +id = "771638f1bfc940ad84e53570b632f236"