import { IDENTIFIER, MONTHS_IN_DAYS } from "./constants"; import { getDateDifferenceInDays, getFollowRecords, getRecentPost, resolveIdentity, } from "./utils"; let cursor: string | undefined; const unfollows = []; const doc = await resolveIdentity(IDENTIFIER); do { const { follows, cursor: followCursor } = await getFollowRecords(doc, cursor); for (const [index, record] of follows.entries()) { const doc = await resolveIdentity(record?.value?.subject); const post = await getRecentPost(doc); // it's possible that someone has never made a post i guess, we should add them to the list if (!post?.records) { // neg 1 can represent never made post unfollows.push({ did: record?.value?.subject, lastPost: -1, uri: "" }); continue; } if (post?.records?.[0]?.value) { const recentPostCreationDate = post?.records?.[0].value?.createdAt; const daysSinceLastPost = getDateDifferenceInDays( new Date(recentPostCreationDate), new Date(), ); if (daysSinceLastPost >= MONTHS_IN_DAYS) { unfollows.push({ did: record?.value?.subject, lastPost: daysSinceLastPost, uri: record?.uri, }); } } console.clear(); console.info(`Auditing user [${index + 1} / ${follows.length}]`); } cursor = followCursor; } while (cursor); await Bun.write("follows.json", JSON.stringify(unfollows)); console.info(`wrote ${unfollows.length} accounts to follows.json`);