~chee/partyfingerd

076d770371af5d35fe9900d8cb63d7d3ba689b14 — chee a month ago
initial
4 files changed, 66 insertions(+), 0 deletions(-)

A README.md
A fingerd.ts
A install
A partyfingerd.service
A  => README.md +9 -0
@@ 1,9 @@
# partyfingerd

finger service for chee.party.

prints my latest blog post when you finger:

```
finger @chee.party
```

A  => fingerd.ts +38 -0
@@ 1,38 @@
#!/usr/bin/env -S deno run --allow-net --allow-run
import { copy } from "https://deno.land/std@0.151.0/streams/conversion.ts"
const listener = Deno.listen({ port: 79 })
const encoder = new TextEncoder()
const heart = Uint8Array.from([0x3c, 0x33])
const dashes = "\n" + "*".repeat(72) + "\n\n"
const welcome = encoder.encode(dashes)
const goodbye = encoder.encode(dashes + "see more at https://chee.party/")

async function getLatestPost(): Promise<Deno.Reader | null> {
	// TODO implement this command in deno
	const process = Deno.run({
		cmd: ["/bin/grab-latest-post-as-text"],
		stdout: "piped"
	})
	await process.status()
	return process.stdout
}

let close = (conn: Deno.Conn) => conn.close()

for await (const conn of listener) {
	try {
		const stdout = await getLatestPost()
		// i don't know a better way of throwing everything away
		await conn.read(new Uint8Array(32))
		await conn.write(welcome)
		if (stdout) {
			await copy(stdout, conn)
		} else {
			await conn.write(heart)
		}
		await conn.write(goodbye)
	} finally {
		conn.close()
	}

}

A  => install +6 -0
@@ 1,6 @@
#!/bin/sh
deno compile --allow-net --allow-run fingerd.ts
sudo mv fingerd /bin/partyfingerd
sudo cp partyfingerd.service /etc/systemd/system/
sudo systemctl enable --now partyfingerd
echo ready for fingering

A  => partyfingerd.service +13 -0
@@ 1,13 @@
[Unit]
Description=Finger Party Daemon
After=network.target

[Service]
Type=simple
# lol
User=root
ExecStart=/bin/partyfingerd
Restart=always

[Install]
WantedBy=multi-user.target