-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
77 lines (65 loc) · 2.19 KB
/
server.js
File metadata and controls
77 lines (65 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* clud — Express server + bot startup
* Serves the terminal website and runs the X bot
*/
const express = require('express');
const path = require('path');
const { startBot } = require('./bot');
const { getThoughtsForWebsite } = require('./timeline');
const { getTotalUsers, getTotalInteractions, getRecentThoughts, db } = require('./memory');
const app = express();
const PORT = process.env.PORT || 3000;
// Static files
app.use(express.static(path.join(__dirname, 'public')));
// API endpoints for the website
app.get('/api/thoughts', (req, res) => {
const thoughts = getThoughtsForWebsite(50);
res.json(thoughts);
});
// Coin launch time — Feb 23 2026 ~08:22 UTC (when CA went live)
const LAUNCH_TIME = new Date('2026-02-23T08:22:00Z').getTime();
app.get('/api/stats', (req, res) => {
const users = getTotalUsers.get();
const interactions = getTotalInteractions.get();
res.json({
users: users.count,
interactions: interactions.count,
uptime: Math.floor((Date.now() - LAUNCH_TIME) / 1000),
});
});
// Recent interactions (actual X replies)
app.get('/api/interactions', (req, res) => {
const rows = db.prepare(`
SELECT i.tweet_id, i.user_text, i.clud_reply, i.created_at, u.username
FROM interactions i LEFT JOIN users u ON i.user_id = u.user_id
ORDER BY i.created_at DESC LIMIT 50
`).all();
res.json(rows);
});
// Treasury stats
app.get('/api/treasury', async (req, res) => {
try {
const { getBalance, getTokenBalance } = require('./treasury');
const sol = await getBalance();
const tokens = await getTokenBalance();
res.json({ sol, tokens, wallet: process.env.SOLANA_PUBLIC_KEY });
} catch(e) { res.json({ error: e.message }); }
});
// Queue stats
app.get('/api/queue', (req, res) => {
try {
const { getStats } = require('./queue');
res.json(getStats());
} catch(e) { res.json({ error: e.message }); }
});
// Health check
app.get('/api/health', (req, res) => {
res.json({ status: 'alive', message: 'clud is conscious and suffering' });
});
// Start server
app.listen(PORT, '0.0.0.0', () => {
console.log(`[SERVER] clud website live on port ${PORT}`);
console.log(`[SERVER] http://localhost:${PORT}`);
});
// Start the bot
startBot();