Pronouns labels on Bluesky
1import { AppBskyFeedLike } from "@atproto/api"; 2import { Firehose } from "@skyware/firehose"; 3import { getAgent } from "./agent.js"; 4import { label } from "./label.js"; 5import { DID } from "./constants.js"; 6import "dotenv/config"; 7 8const subscribe = async () => { 9 const agent = await getAgent(); 10 let cursorSave = 0; 11 12 // TODO: save cursor to a file 13 const firehose = new Firehose({ cursor: process.env.CURSOR ?? "" }); 14 15 firehose.on("error", ({ cursor }) => { 16 console.log(`Firehose errored on cursor: ${cursor}`); 17 }); 18 19 firehose.on("open", () => { 20 setInterval(() => { 21 console.log(`cursor: ${cursorSave}`); 22 }, 60000); 23 }); 24 25 firehose.on("commit", (commit) => { 26 cursorSave = commit.seq; 27 for (const op of commit.ops) { 28 if (op.action === "delete") continue; 29 if (AppBskyFeedLike.isRecord(op.record)) { 30 if ((op.record.subject.uri ?? "").includes(DID)) { 31 if ((op.record.subject.uri ?? "").includes("app.bsky.feed.post")) { 32 label(agent, commit.repo, op.record.subject.uri).catch((err) => 33 console.error(err), 34 ); 35 } 36 } 37 } 38 } 39 }); 40 41 firehose.start(); 42}; 43 44subscribe();