Pronouns labels on Bluesky
1import { BskyAgent } from "@atproto/api";
2import { DID, PRONOUNS, URIs } from "./constants.js";
3
4export const label = async (agent: BskyAgent, subject: string, uri: string) => {
5 const repo = await agent
6 .withProxy("atproto_labeler", DID)
7 .api.tools.ozone.moderation.getRepo({ did: subject });
8
9 const post = URIs[uri];
10
11 if (repo.data.labels && post.includes("Like this post to delete")) {
12 await agent
13 .withProxy("atproto_labeler", DID)
14 .api.tools.ozone.moderation.emitEvent({
15 event: {
16 $type: "tools.ozone.moderation.defs#modEventLabel",
17 createLabelVals: [],
18 negateLabelVals: repo.data.labels.map((label) => label.val),
19 },
20 subject: {
21 $type: "com.atproto.admin.defs#repoRef",
22 did: subject,
23 },
24 createdBy: agent.session!.did,
25 createdAt: new Date().toISOString(),
26 subjectBlobCids: [],
27 });
28 return;
29 }
30
31 if (repo.data.labels && repo.data.labels.length >= 4) return;
32
33 if (PRONOUNS[post]) {
34 await agent
35 .withProxy("atproto_labeler", DID)
36 .api.tools.ozone.moderation.emitEvent({
37 event: {
38 $type: "tools.ozone.moderation.defs#modEventLabel",
39 createLabelVals: [PRONOUNS[post]],
40 negateLabelVals: [],
41 },
42 subject: {
43 $type: "com.atproto.admin.defs#repoRef",
44 did: subject,
45 },
46 createdBy: agent.session!.did,
47 createdAt: new Date().toISOString(),
48 subjectBlobCids: [],
49 })
50 .then(() => console.log(`Labeled ${subject} with ${post}`));
51 }
52};