Pronouns labels on Bluesky
1import { did } 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 (agent: BskyAgent, subject: string, uri: string) => { 19 const repo = await agent 20 .withProxy("atproto_labeler", did) 21 .api.tools.ozone.moderation.getRepo({ did: subject }); 22 23 const post = await getPostContent(agent, uri); 24 25 if (repo.data.labels && post.includes("Like this post to delete")) { 26 await agent 27 .withProxy("atproto_labeler", did) 28 .api.tools.ozone.moderation.emitEvent({ 29 event: { 30 $type: "tools.ozone.moderation.defs#modEventLabel", 31 createLabelVals: [], 32 negateLabelVals: repo.data.labels.map((label) => label.val), 33 }, 34 subject: { 35 $type: "com.atproto.admin.defs#repoRef", 36 did: subject, 37 }, 38 createdBy: agent.session!.did, 39 createdAt: new Date().toISOString(), 40 subjectBlobCids: [], 41 }); 42 return; 43 } 44 45 if (repo.data.labels && repo.data.labels.length >= 4) return; 46 47 if (PRONOUNS[post]) { 48 await agent 49 .withProxy("atproto_labeler", did) 50 .api.tools.ozone.moderation.emitEvent({ 51 event: { 52 $type: "tools.ozone.moderation.defs#modEventLabel", 53 createLabelVals: [PRONOUNS[post]], 54 negateLabelVals: [], 55 }, 56 subject: { 57 $type: "com.atproto.admin.defs#repoRef", 58 did: subject, 59 }, 60 createdBy: agent.session!.did, 61 createdAt: new Date().toISOString(), 62 subjectBlobCids: [], 63 }); 64 } 65};