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", async (commit) => {
26 cursorSave = commit.seq;
27 commit.ops.forEach(async (op) => {
28 if (op.action !== "delete" && AppBskyFeedLike.isRecord(op.record)) {
29 if ((op.record.subject.uri ?? "").includes(DID)) {
30 if ((op.record.subject.uri ?? "").includes("app.bsky.feed.post")) {
31 await label(agent, commit.repo, op.record.subject.uri).catch(
32 (err) => console.error(err),
33 );
34 }
35 }
36 }
37 });
38 });
39
40 firehose.start();
41};
42
43subscribe();