nerdflirt 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # nerdflirt
2
+
3
+ P2P terminal chat — randomly connect with nerds.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g nerdflirt
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ nerdflirt
15
+ ```
16
+
17
+ You'll get a random handle and automatically connect to other nerds on the network.
18
+
19
+ ### Commands
20
+
21
+ - `/peers` — see who's connected
22
+ - `/quit` — disconnect
23
+
24
+ ## How it works
25
+
26
+ Uses [Hyperswarm](https://github.com/holepunchto/hyperswarm) for decentralized peer discovery and encrypted connections. No servers, no accounts.
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env node
2
+
3
+ import Hyperswarm from 'hyperswarm'
4
+ import crypto from 'node:crypto'
5
+ import readline from 'node:readline'
6
+ import b4a from 'b4a'
7
+ import chalk from 'chalk'
8
+
9
+ const TOPIC = crypto.createHash('sha256').update('nerdflirt-network-v1').digest()
10
+ const NAMES = [
11
+ 'ByteCrusher', 'PixelNinja', 'QuantumFox', 'NeonGhost', 'CipherPunk',
12
+ 'DataWitch', 'BinaryBard', 'SyntaxSiren', 'KernelKid', 'StackSamurai',
13
+ 'BitBandit', 'CodeCoyote', 'HexHawk', 'LogicLlama', 'NullNomad',
14
+ 'PacketPirate', 'RecurseRaven', 'ShellShark', 'TokenTiger', 'VoidViper'
15
+ ]
16
+
17
+ const myName = NAMES[Math.floor(Math.random() * NAMES.length)]
18
+ const peers = new Map()
19
+ const swarm = new Hyperswarm()
20
+
21
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
22
+
23
+ console.log(chalk.magentaBright(`
24
+ ♥ nerdflirt ♥
25
+ You are: ${chalk.bold(myName)}
26
+ Searching for nerds...
27
+ `))
28
+
29
+ swarm.on('connection', (conn, info) => {
30
+ const id = b4a.toString(info.publicKey, 'hex').slice(0, 8)
31
+ peers.set(id, { conn, name: null })
32
+
33
+ // send our name on connect
34
+ conn.write(JSON.stringify({ type: 'name', name: myName }))
35
+
36
+ conn.on('data', (data) => {
37
+ try {
38
+ const msg = JSON.parse(data.toString())
39
+ if (msg.type === 'name') {
40
+ peers.get(id).name = msg.name
41
+ console.log(chalk.green(`\n💚 ${msg.name} connected! Say something flirty.\n`))
42
+ rl.prompt(true)
43
+ } else if (msg.type === 'chat') {
44
+ const peerName = peers.get(id)?.name || id
45
+ console.log(chalk.cyan(`\n${peerName}: ${msg.text}`))
46
+ rl.prompt(true)
47
+ }
48
+ } catch {}
49
+ })
50
+
51
+ conn.on('close', () => {
52
+ const name = peers.get(id)?.name || id
53
+ console.log(chalk.red(`\n💔 ${name} disconnected.\n`))
54
+ peers.delete(id)
55
+ rl.prompt(true)
56
+ })
57
+
58
+ conn.on('error', () => peers.delete(id))
59
+ })
60
+
61
+ const discovery = swarm.join(TOPIC, { client: true, server: true })
62
+ await discovery.flushed()
63
+
64
+ rl.setPrompt(chalk.magenta(`${myName}> `))
65
+ rl.prompt()
66
+
67
+ rl.on('line', (line) => {
68
+ const text = line.trim()
69
+ if (!text) { rl.prompt(); return }
70
+
71
+ if (text === '/quit') {
72
+ console.log(chalk.magentaBright('\n♥ Until next time, nerd. ♥\n'))
73
+ swarm.destroy()
74
+ process.exit(0)
75
+ }
76
+
77
+ if (text === '/peers') {
78
+ const names = [...peers.values()].map(p => p.name || '???')
79
+ console.log(chalk.yellow(`Connected: ${names.length ? names.join(', ') : 'nobody yet'}`))
80
+ rl.prompt()
81
+ return
82
+ }
83
+
84
+ const msg = JSON.stringify({ type: 'chat', text })
85
+ for (const { conn } of peers.values()) {
86
+ conn.write(msg)
87
+ }
88
+ rl.prompt()
89
+ })
90
+
91
+ rl.on('close', () => {
92
+ swarm.destroy()
93
+ process.exit(0)
94
+ })
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "nerdflirt",
3
+ "version": "1.0.0",
4
+ "description": "Terminal flirting",
5
+ "bin": {
6
+ "nerdflirt": "./bin/nerdflirt.js"
7
+ },
8
+ "type": "module",
9
+ "files": ["bin", "README.md"],
10
+ "license": "MIT",
11
+ "dependencies": {
12
+ "hyperswarm": "^4.7.15",
13
+ "b4a": "^1.6.6",
14
+ "chalk": "^5.3.0"
15
+ }
16
+ }