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