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
11 // add firehose cursor save
12 const firehose = new Firehose();
13
14 firehose.on("error", ({ cursor }) => {
15 agent.api.chat.bsky.convo.sendMessage(
16 {
17 convoId: process.env.CONVO_ID ?? "",
18 message: {
19 text: `Firehose errored on cursor: ${cursor}`,
20 },
21 },
22 {
23 encoding: "application/json",
24 headers: {
25 "atproto-proxy": "did:web:api.bsky.chat#bsky_chat",
26 },
27 },
28 );
29 });
30
31 firehose.on("commit", (commit) => {
32 for (const op of commit.ops) {
33 if (op.action === "delete") continue;
34 if (AppBskyFeedLike.isRecord(op.record)) {
35 if ((op.record.subject.uri ?? "").includes(DID)) {
36 if ((op.record.subject.uri ?? "").includes("app.bsky.feed.post")) {
37 label(agent, commit.repo, op.record.subject.uri).catch((err) =>
38 console.error(err),
39 );
40 }
41 }
42 }
43 }
44 });
45
46 firehose.start();
47};
48
49subscribe();