~chee/partyfingerd

c1f5e23af183250d81d82188d32fc72084b72592 — chee 13 days ago 9a39351
allow posts to be fingered as though they were users
3 files changed, 14 insertions(+), 7 deletions(-)

M fingerd.ts
R grab-latest-post-as-text => grab-post-as-text
M install
M fingerd.ts => fingerd.ts +10 -4
@@ 2,15 2,16 @@
import { copy } from "https://deno.land/std@0.151.0/streams/conversion.ts"
const listener = Deno.listen({ port: 79 })
const encoder = new TextEncoder()
const decoder = new TextDecoder()
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> {
async function getLatestPost(post: string): Promise<Deno.Reader | null> {
	// TODO implement this command in deno
	const process = Deno.run({
		cmd: ["/bin/grab-latest-post-as-text"],
		cmd: ["/bin/grab-post-as-text", post],
		stdout: "piped"
	})
	await process.status()


@@ 21,9 22,14 @@ let close = (conn: Deno.Conn) => conn.close()

for await (const conn of listener) {
	try {
		const stdout = await getLatestPost()
		const buffer = new Uint8Array(256)
		await conn.read(buffer)
		const user = decoder.decode(buffer)
			.replace(/\0.*/g,'')
			.trim()
		const stdout = await getLatestPost(user)
		// 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)

R grab-latest-post-as-text => grab-post-as-text +3 -2
@@ 1,7 1,8 @@
#!/bin/sh
curl 2>/dev/null https://chee.party/ \
curl -L 2>/dev/null https://chee.party/$1 \
	 | html2 2>/dev/null \
	 | awk '/@class=entry-content/{flag=1;next}/!= .entry-content/{flag=0}flag' \
	 | 2html 2>/dev/null \
	 | pandoc --from html --to markdown \
	 | awk '/::: {itemprop="description articleBody"}/{flag=1;next}/:::/{flag=0}flag'
	 | awk '/::: {itemprop="description articleBody"}/{flag=1;next}/:::/{flag=0}flag' \
	 | fold -w 72

M install => install +1 -1
@@ 3,5 3,5 @@ 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
sudo cp grab-latest-post-as-text /bin/
sudo cp grab-post-as-text /bin/
echo ready for fingering