Pronouns labels on Bluesky

maybe better error handling

Changed files
+37 -8
src
+17 -7
src/label.ts
···
-
import { BskyAgent } from "@atproto/api";
+
import { AppBskyActorDefs, BskyAgent } from "@atproto/api";
import { DID, PRONOUNS, URIs } from "./constants.js";
-
export const label = async (agent: BskyAgent, subject: string, uri: string) => {
+
export const label = async (
+
agent: BskyAgent,
+
subject: string | AppBskyActorDefs.ProfileView,
+
uri: string,
+
) => {
+
const did = AppBskyActorDefs.isProfileView(subject) ? subject.did : subject;
const repo = await agent
.withProxy("atproto_labeler", DID)
-
.api.tools.ozone.moderation.getRepo({ did: subject });
+
.api.tools.ozone.moderation.getRepo({ did: did })
+
.catch((err) => console.log(err));
+
+
if (!repo) return;
const post = URIs[uri];
···
},
subject: {
$type: "com.atproto.admin.defs#repoRef",
-
did: subject,
+
did: did,
},
createdBy: agent.session!.did,
createdAt: new Date().toISOString(),
subjectBlobCids: [],
-
});
+
})
+
.catch((err) => console.log(err));
return;
}
···
},
subject: {
$type: "com.atproto.admin.defs#repoRef",
-
did: subject,
+
did: did,
},
createdBy: agent.session!.did,
createdAt: new Date().toISOString(),
subjectBlobCids: [],
})
-
.then(() => console.log(`Labeled ${subject} with ${post}`));
+
.catch((err) => console.log(err))
+
.then(() => console.log(`Labeled ${did} with ${post}`));
}
};
+20 -1
src/main.ts
···
import { getAgent } from "./agent.js";
import { label } from "./label.js";
import { DID } from "./constants.js";
+
import "dotenv/config";
const subscribe = async () => {
const agent = await getAgent();
// add firehose cursor save
-
const firehose = new Firehose({ cursor: "759165458" });
+
const firehose = new Firehose();
+
+
firehose.on("error", ({ cursor }) => {
+
agent.api.chat.bsky.convo.sendMessage(
+
{
+
convoId: process.env.CONVO_ID ?? "",
+
message: {
+
text: `Firehose errored on cursor: ${cursor}`,
+
},
+
},
+
{
+
encoding: "application/json",
+
headers: {
+
"atproto-proxy": "did:web:api.bsky.chat#bsky_chat",
+
},
+
},
+
);
+
});
+
firehose.on("commit", (commit) => {
for (const op of commit.ops) {
if (op.action === "delete") continue;