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 // add firehose cursor save
13 //const firehose = new Firehose({ cursor: "760303563" });
14 const firehose = new Firehose();
15
16 firehose.on("error", ({ cursor }) => {
17 console.log(`Firehose errored on cursor: ${cursor}`);
18 });
19
20 firehose.on("open", () => {
21 setInterval(() => {
22 console.log(`cursor: ${cursorSave}`);
23 }, 60000);
24 });
25
26 firehose.on("commit", (commit) => {
27 cursorSave = commit.seq;
28 for (const op of commit.ops) {
29 if (op.action === "delete") continue;
30 if (AppBskyFeedLike.isRecord(op.record)) {
31 if ((op.record.subject.uri ?? "").includes(DID)) {
32 if ((op.record.subject.uri ?? "").includes("app.bsky.feed.post")) {
33 label(agent, commit.repo, op.record.subject.uri).catch((err) =>
34 console.error(err),
35 );
36 }
37 }
38 }
39 }
40 });
41
42 firehose.start();
43};
44
45subscribe();