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) => { 14 console.log({ 15 error: err, 16 }); 17 }); 18 19 if (!repo) return; 20 21 const post = URIs[uri]; 22 23 if (repo.data.labels && (post ?? "").includes("Like this post to delete")) { 24 await agent 25 .withProxy("atproto_labeler", DID) 26 .api.tools.ozone.moderation.emitEvent({ 27 event: { 28 $type: "tools.ozone.moderation.defs#modEventLabel", 29 createLabelVals: [], 30 negateLabelVals: repo.data.labels.map((label) => label.val), 31 }, 32 subject: { 33 $type: "com.atproto.admin.defs#repoRef", 34 did: did, 35 }, 36 createdBy: agent.session!.did, 37 createdAt: new Date().toISOString(), 38 subjectBlobCids: [], 39 }) 40 .catch((err) => { 41 console.log({ 42 error: err, 43 }); 44 }) 45 .then(() => console.log(`Deleted labels for ${did}`)); 46 return; 47 } 48 49 if (repo.data.labels && repo.data.labels.length >= 4) return; 50 51 if (PRONOUNS[post]) { 52 await agent 53 .withProxy("atproto_labeler", DID) 54 .api.tools.ozone.moderation.emitEvent({ 55 event: { 56 $type: "tools.ozone.moderation.defs#modEventLabel", 57 createLabelVals: [PRONOUNS[post]], 58 negateLabelVals: [], 59 }, 60 subject: { 61 $type: "com.atproto.admin.defs#repoRef", 62 did: did, 63 }, 64 createdBy: agent.session!.did, 65 createdAt: new Date().toISOString(), 66 subjectBlobCids: [], 67 }) 68 .catch((err) => { 69 console.log({ 70 error: err, 71 }); 72 }) 73 .then(() => console.log(`Labeled ${did} with ${post}`)); 74 } 75};