Pronouns labels on Bluesky

no brain left

Changed files
+38 -30
src
+1 -7
src/agent.ts
···
service: process.env.BSKY_SERVICE ?? "https://bsky.social",
});
-
await agent.login({
-
identifier: process.env.BSKY_IDENTIFIER!,
-
password: process.env.BSKY_PASSWORD!,
-
});
return agent;
};
-
export const did = await getAgent().then((agent) => agent.session!.did);
-
BskyAgent.configure({
-
appLabelers: [did],
});
···
service: process.env.BSKY_SERVICE ?? "https://bsky.social",
});
return agent;
};
BskyAgent.configure({
+
appLabelers: [process.env.DID ?? ""],
});
+25
src/constants.ts
···
export const PRONOUNS: Record<string, string> = {
"she/her": "she",
"he/him": "he",
···
avoid: "avoid",
"look at bio": "bio",
};
···
+
import "dotenv/config";
+
export const PRONOUNS: Record<string, string> = {
"she/her": "she",
"he/him": "he",
···
avoid: "avoid",
"look at bio": "bio",
};
+
+
export const URIs: Record<string, string> = {
+
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwsqucto3j2a":
+
"Like this post to delete your labels",
+
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwss4ldkwd2j":
+
"they/them",
+
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwss4fmiow2n":
+
"it/its",
+
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwss4bzqlw2k":
+
"he/him",
+
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwss45mxrh2j":
+
"she/her",
+
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwst2tn2342f":
+
"look at bio",
+
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwsslg3gqk2t":
+
"avoid",
+
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwssldhzme27":
+
"ask",
+
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwss4vc4cw2x":
+
"any/all",
+
};
+
+
export const DID = process.env.DID ?? "";
+8 -21
src/label.ts
···
-
import { did } from "./agent.js";
-
import { AppBskyFeedPost, BskyAgent } from "@atproto/api";
-
import { PRONOUNS } from "./constants.js";
-
-
const getPostContent = async (agent: BskyAgent, uri: string) => {
-
return await agent
-
.getPosts({ uris: [uri] })
-
.catch((err) => {
-
console.error(err.message);
-
})
-
.then((posts) => {
-
if (posts && AppBskyFeedPost.isRecord(posts.data.posts[0].record))
-
return posts.data.posts[0].record.text;
-
else return "";
-
});
-
};
export const label = async (agent: BskyAgent, subject: string, uri: string) => {
const repo = await agent
-
.withProxy("atproto_labeler", did)
.api.tools.ozone.moderation.getRepo({ did: subject });
-
const post = await getPostContent(agent, uri);
if (repo.data.labels && post.includes("Like this post to delete")) {
await agent
-
.withProxy("atproto_labeler", did)
.api.tools.ozone.moderation.emitEvent({
event: {
$type: "tools.ozone.moderation.defs#modEventLabel",
···
if (PRONOUNS[post]) {
await agent
-
.withProxy("atproto_labeler", did)
.api.tools.ozone.moderation.emitEvent({
event: {
$type: "tools.ozone.moderation.defs#modEventLabel",
···
createdBy: agent.session!.did,
createdAt: new Date().toISOString(),
subjectBlobCids: [],
-
});
}
};
···
+
import { BskyAgent } from "@atproto/api";
+
import { DID, PRONOUNS, URIs } from "./constants.js";
export const label = async (agent: BskyAgent, subject: string, uri: string) => {
const repo = await agent
+
.withProxy("atproto_labeler", DID)
.api.tools.ozone.moderation.getRepo({ did: subject });
+
const post = URIs[uri];
if (repo.data.labels && post.includes("Like this post to delete")) {
await agent
+
.withProxy("atproto_labeler", DID)
.api.tools.ozone.moderation.emitEvent({
event: {
$type: "tools.ozone.moderation.defs#modEventLabel",
···
if (PRONOUNS[post]) {
await agent
+
.withProxy("atproto_labeler", DID)
.api.tools.ozone.moderation.emitEvent({
event: {
$type: "tools.ozone.moderation.defs#modEventLabel",
···
createdBy: agent.session!.did,
createdAt: new Date().toISOString(),
subjectBlobCids: [],
+
})
+
.then(() => console.log(`Labeled ${subject} with ${post}`));
}
};
+4 -2
src/main.ts
···
import { AppBskyFeedLike } from "@atproto/api";
import { Firehose } from "@skyware/firehose";
-
import { did, getAgent } from "./agent.js";
import { label } from "./label.js";
const subscribe = async () => {
const agent = await getAgent();
const firehose = new Firehose();
firehose.on("commit", (commit) => {
for (const op of commit.ops) {
if (op.action === "delete") continue;
if (AppBskyFeedLike.isRecord(op.record)) {
-
if (op.record.subject.uri.includes(did)) {
if (op.record.subject.uri.includes("app.bsky.feed.post")) {
label(agent, commit.repo, op.record.subject.uri).catch((err) =>
console.error(err),
···
import { AppBskyFeedLike } from "@atproto/api";
import { Firehose } from "@skyware/firehose";
+
import { getAgent } from "./agent.js";
import { label } from "./label.js";
+
import { DID } from "./constants.js";
const subscribe = async () => {
const agent = await getAgent();
+
//const firehose = new Firehose("wss://bsky.network", { cursor: "759324067" });
const firehose = new Firehose();
firehose.on("commit", (commit) => {
for (const op of commit.ops) {
if (op.action === "delete") continue;
if (AppBskyFeedLike.isRecord(op.record)) {
+
if (op.record.subject.uri.includes(DID)) {
if (op.record.subject.uri.includes("app.bsky.feed.post")) {
label(agent, commit.repo, op.record.subject.uri).catch((err) =>
console.error(err),