Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113import { AtpAgent } from "@atproto/api";import * as dotenv from "dotenv";
dotenv.config();
const IDENTIFIER = process.env.IDENTIFIER || "";const PASSWORD = process.env.PASSWORD || "";const PDS_URL = process.env.PDS_URL || "https://bsky.social";
const main = async () => { const agent = new AtpAgent({ service: PDS_URL });
await agent.login({ identifier: IDENTIFIER, password: PASSWORD });
const handle = agent.session?.handle;
if (handle) { const profile = await agent.app.bsky.actor.getProfile({ actor: handle });
if (profile) { let bio: string = profile.data.description;
if (bio) { const bookhiveResponse = await agent.com.atproto.repo.listRecords({ repo: handle, collection: "buzz.bookhive.book" });
if (bookhiveResponse.success) { const currentlyReading = bookhiveResponse.data.records .filter( (record: { value: { status: string } }) => record.value.status === "buzz.bookhive.defs#reading" ) .sort((a, b) => b.value.startedAt.localeCompare(a.value.startedAt) ); const formattedCurrentlyReading = currentlyReading.map( (cr: { value: { title: any; authors: any } }) => `${cr.value.title} by ${cr.value.authors}` );
const regex = /(\nCurrently Reading\n๐)([\s\S]*?)(\n๐\n)/;
let newBio = "";
if (regex.test(bio)) { const [_, prefix, __, suffix] = bio.match(regex)!;
let newMiddle: string[] = [];
for (const cr of formattedCurrentlyReading) { if ( bio.replace( regex, [ prefix, newMiddle.join(""), `\n${cr}`, suffix ].join("") ).length <= 256 ) { newMiddle.push(`\n${cr}`); } }
newBio = bio.replace( regex, [prefix, newMiddle.join(""), suffix].join("") ); } else { let newMiddle: string[] = [];
for (const cr of formattedCurrentlyReading) { if ( [ bio, `\n\nCurrently Reading\n๐`, newMiddle.join(""), `\n${cr}`, `\n๐` ].join("").length <= 256 ) { newMiddle.push(`\n${cr}`); } }
newBio = [ bio, `\n\nCurrently Reading\n๐`, newMiddle.join(""), `\n๐` ].join(""); }
if (newBio.length <= 256 && newBio !== bio) { await agent.upsertProfile((p: any) => { return { ...p, description: newBio }; }); } } } } }};
main();