this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

switch from emitEvent to createLabel

+30 -52
+27 -35
src/label.ts
··· 1 - import { AppBskyActorDefs, Agent } from "@atproto/api"; 2 - import { DID, PRONOUNS, URIs } from "./constants.js"; 1 + import { AppBskyActorDefs } from "@atproto/api"; 2 + import { DID, PRONOUNS, SIGNING_KEY, URIs } from "./constants.js"; 3 + import { LabelerServer } from "@skyware/labeler"; 4 + import { getAgent } from "./agent.js"; 5 + 6 + const server = new LabelerServer({ did: DID, signingKey: SIGNING_KEY }); 7 + const agent = await getAgent(); 8 + 9 + server.start(4001, (error, address) => { 10 + if (error) { 11 + console.error(error); 12 + } else { 13 + console.log(`Labeler server listening on ${address}`); 14 + } 15 + }); 3 16 4 17 export const label = async ( 5 - agent: Agent, 6 18 subject: string | AppBskyActorDefs.ProfileView, 7 19 uri: string, 8 20 ) => { 9 21 const did = AppBskyActorDefs.isProfileView(subject) ? subject.did : subject; 10 22 const labels = await agent.com.atproto.label 11 - .queryLabels({ sources: [DID], uriPatterns: [did] }) 23 + .queryLabels({ sources: [server.did], uriPatterns: [did] }) 12 24 .catch((err) => { 13 25 console.log(err); 14 26 }); ··· 17 29 const post = URIs[uri]; 18 30 19 31 if (post?.includes("Like this post to delete")) { 20 - await agent 21 - .withProxy("atproto_labeler", DID) 22 - .tools.ozone.moderation.emitEvent({ 23 - event: { 24 - $type: "tools.ozone.moderation.defs#modEventLabel", 25 - createLabelVals: [], 26 - negateLabelVals: labels.data.labels.map((label) => label.val), 27 - }, 28 - subject: { 29 - $type: "com.atproto.admin.defs#repoRef", 30 - did: did, 31 - }, 32 - createdBy: agent.did!, 33 - createdAt: new Date().toISOString(), 34 - subjectBlobCids: [], 35 - }) 32 + await server 33 + .createLabels( 34 + { uri: did }, 35 + { negate: labels.data.labels.map((label) => label.val) }, 36 + ) 36 37 .catch((err) => { 37 38 console.log(err); 38 39 }) 39 40 .then(() => console.log(`Deleted labels for ${did}`)); 40 41 } else if (labels.data.labels.length < 4 && PRONOUNS[post]) { 41 - await agent 42 - .withProxy("atproto_labeler", DID) 43 - .tools.ozone.moderation.emitEvent({ 44 - event: { 45 - $type: "tools.ozone.moderation.defs#modEventLabel", 46 - createLabelVals: [PRONOUNS[post]], 47 - negateLabelVals: [], 48 - }, 49 - subject: { 50 - $type: "com.atproto.admin.defs#repoRef", 51 - did: did, 52 - }, 53 - createdBy: agent.did!, 54 - createdAt: new Date().toISOString(), 55 - subjectBlobCids: [], 42 + await server 43 + .createLabel({ 44 + src: server.did, 45 + uri: did, 46 + val: PRONOUNS[post], 47 + cts: new Date().toISOString(), 56 48 }) 57 49 .catch((err) => { 58 50 console.log(err);
+3 -17
src/main.ts
··· 1 1 import { AppBskyFeedLike } from "@atproto/api"; 2 2 import { Firehose } from "@skyware/firehose"; 3 - import { getAgent } from "./agent.js"; 4 3 import { label } from "./label.js"; 5 - import { DID, SIGNING_KEY } from "./constants.js"; 4 + import { DID } from "./constants.js"; 6 5 import fs from "node:fs"; 7 - import { LabelerServer } from "@skyware/labeler"; 8 - 9 - const server = new LabelerServer({ did: DID, signingKey: SIGNING_KEY }); 10 - 11 - server.start(4001, (error, address) => { 12 - if (error) { 13 - console.error(error); 14 - } else { 15 - console.log(`Labeler server listening on ${address}`); 16 - } 17 - }); 18 6 19 7 const subscribe = async () => { 20 - const agent = await getAgent(); 21 - 22 8 let cursorFirehose = 0; 23 9 const cursorFile = fs.readFileSync("cursor.txt", "utf8"); 24 10 ··· 45 31 if (op.action !== "delete" && AppBskyFeedLike.isRecord(op.record)) { 46 32 if ((op.record.subject.uri ?? "").includes(DID)) { 47 33 if ((op.record.subject.uri ?? "").includes("app.bsky.feed.post")) { 48 - await label(agent, commit.repo, op.record.subject.uri).catch( 49 - (err) => console.error(err), 34 + await label(commit.repo, op.record.subject.uri).catch((err) => 35 + console.error(err), 50 36 ); 51 37 } 52 38 }