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