Pronouns labels on Bluesky

save cursor to file

Changed files
+21 -17
src
+6
src/constants.ts
···
"ae/aer": "ae",
"prince/princes/princeself": "prince",
"ze/hir": "ze",
};
export const URIs: Record<string, string> = {
···
"prince/princes/princeself",
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwvcc736wg2n":
"ze/hir",
};
export const DID = process.env.DID ?? "";
···
"ae/aer": "ae",
"prince/princes/princeself": "prince",
"ze/hir": "ze",
+
"dey/deren": "dey",
+
none: "none",
};
export const URIs: Record<string, string> = {
···
"prince/princes/princeself",
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwvcc736wg2n":
"ze/hir",
+
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwwwvsvcnz2h":
+
"dey/deren",
+
"at://did:plc:wkoofae5uytcm7bjncmev6n6/app.bsky.feed.post/3kwxljuxooh2r":
+
"none",
};
export const DID = process.env.DID ?? "";
+3 -9
src/label.ts
···
.withProxy("atproto_labeler", DID)
.api.tools.ozone.moderation.getRepo({ did: did })
.catch((err) => {
-
console.log({
-
error: err,
-
});
});
if (!repo) return;
···
subjectBlobCids: [],
})
.catch((err) => {
-
console.log({
-
error: err,
-
});
})
.then(() => console.log(`Deleted labels for ${did}`));
return;
···
subjectBlobCids: [],
})
.catch((err) => {
-
console.log({
-
error: err,
-
});
})
.then(() => console.log(`Labeled ${did} with ${post}`));
}
···
.withProxy("atproto_labeler", DID)
.api.tools.ozone.moderation.getRepo({ did: did })
.catch((err) => {
+
console.log(err);
});
if (!repo) return;
···
subjectBlobCids: [],
})
.catch((err) => {
+
console.log(err);
})
.then(() => console.log(`Deleted labels for ${did}`));
return;
···
subjectBlobCids: [],
})
.catch((err) => {
+
console.log(err);
})
.then(() => console.log(`Labeled ${did} with ${post}`));
}
+12 -8
src/main.ts
···
import { getAgent } from "./agent.js";
import { label } from "./label.js";
import { DID } from "./constants.js";
-
import "dotenv/config";
const subscribe = async () => {
const agent = await getAgent();
-
let cursorSave = 0;
-
// TODO: save cursor to a file
-
const firehose = new Firehose({ cursor: process.env.CURSOR ?? "" });
-
firehose.on("error", ({ cursor }) => {
-
console.log(`Firehose errored on cursor: ${cursor}`);
});
firehose.on("open", () => {
setInterval(() => {
-
console.log(`cursor: ${cursorSave}`);
}, 60000);
});
firehose.on("commit", async (commit) => {
-
cursorSave = commit.seq;
commit.ops.forEach(async (op) => {
if (op.action !== "delete" && AppBskyFeedLike.isRecord(op.record)) {
if ((op.record.subject.uri ?? "").includes(DID)) {
···
import { getAgent } from "./agent.js";
import { label } from "./label.js";
import { DID } from "./constants.js";
+
import fs from "node:fs";
const subscribe = async () => {
const agent = await getAgent();
+
let cursorFirehose = 0;
+
let cursorFile = fs.readFileSync("cursor.txt", "utf8");
+
const firehose = new Firehose({ cursor: cursorFile ?? "" });
+
if (cursorFile) console.log(`Initiate firehose at cursor ${cursorFile}`);
+
+
firehose.on("error", ({ cursor, error }) => {
+
console.log(`Firehose errored on cursor: ${cursor}`, error);
});
firehose.on("open", () => {
setInterval(() => {
+
fs.writeFile("cursor.txt", cursorFirehose.toString(), (err) => {
+
if (err) console.error(err);
+
});
}, 60000);
});
firehose.on("commit", async (commit) => {
+
cursorFirehose = commit.seq;
commit.ops.forEach(async (op) => {
if (op.action !== "delete" && AppBskyFeedLike.isRecord(op.record)) {
if ((op.record.subject.uri ?? "").includes(DID)) {