bsky follow audit script

log instead of throw

besaid.zone 803bbcf6 f5b5e0ff

verified
Changed files
+10 -7
+10 -7
index.ts
··· 43 } 44 45 const headers = { 46 - 'User-Agent': 'unfollower-script/did:plc:qttsv4e7pu2jl3ilanfgc3zn' 47 } 48 49 const MONTHS_IN_DAYS = 183 // 6 months, seems reasonable ··· 61 try { 62 const response = await fetch(`https://slingshot.microcosm.blue/xrpc/com.bad-example.identity.resolveMiniDoc?identifier=${indentifier}`, {headers}) 63 if (!response.ok) { 64 - throw new Error(`Failed to fetch minidoc for ${indentifier}. Status - ${response.status}`) 65 } 66 const data = await response.json() as MiniDoc 67 return data ··· 77 try { 78 const response = await fetch(`${doc.pds}/xrpc/com.atproto.repo.listRecords?repo=${doc.did}&collection=app.bsky.feed.post&limit=1`, {headers}) 79 if (!response.ok) { 80 - throw new Error(`There was an error fetching posts for ${doc.handle}. Status - ${response.status}`) 81 } 82 const data = await response.json() as {records: Post[]} 83 return data; ··· 94 try { 95 const response = await fetch(`https://public.api.bsky.app/xrpc/app.bsky.graph.getFollows?actor=${did}&cursor=${cursor}&limit=100`) 96 if (!response.ok) { 97 - throw new Error(`There was a problem getting follows for ${did}. Status - ${response.status}`) 98 } 99 100 const data = await response.json() as { ··· 123 for (const [index, follower] of follows.entries()) { 124 const doc = await resolveIdentity(follower.did) 125 const post = await getRecentPost(doc) 126 - const recentPostCreationDate = post?.records?.[0]!.value?.createdAt 127 128 129 // it's possible that someone has never made a post i guess, we should add them to the list ··· 131 // neg 1 can represent never made post 132 unfollowMap.set(follower.handle, -1) 133 } 134 - if (post?.records[0] && post?.records[0]?.value && !isNaN(Date.parse(recentPostCreationDate))) { 135 // invalid date for some reason idk 136 const daysSinceLastPost = getDateDifferenceInDays(new Date(recentPostCreationDate), new Date()) 137 if (daysSinceLastPost >= MONTHS_IN_DAYS) { ··· 142 console.info(`Auditing user [${index + 1} / ${follows.length}]`) 143 } 144 145 - await new Promise((resolve) => setTimeout(resolve, 1000)) 146 } 147 cursor = followsCursor 148 } while (cursor)
··· 43 } 44 45 const headers = { 46 + 'User-Agent': 'swab/https://tangled.org/dane.is.extraordinarily.cool/swab' 47 } 48 49 const MONTHS_IN_DAYS = 183 // 6 months, seems reasonable ··· 61 try { 62 const response = await fetch(`https://slingshot.microcosm.blue/xrpc/com.bad-example.identity.resolveMiniDoc?identifier=${indentifier}`, {headers}) 63 if (!response.ok) { 64 + // throw new Error(`Failed to fetch minidoc for ${indentifier}. Status - ${response.status}`) 65 + console.error(`Failed to fetch minidoc for ${indentifier}. Status - ${response.status}`) 66 } 67 const data = await response.json() as MiniDoc 68 return data ··· 78 try { 79 const response = await fetch(`${doc.pds}/xrpc/com.atproto.repo.listRecords?repo=${doc.did}&collection=app.bsky.feed.post&limit=1`, {headers}) 80 if (!response.ok) { 81 + // throw new Error(`There was an error fetching posts for ${doc.handle}. Status - ${response.status}`) 82 + console.error(`There was an error fetching posts for ${doc.handle}. Status - ${response.status}`) 83 } 84 const data = await response.json() as {records: Post[]} 85 return data; ··· 96 try { 97 const response = await fetch(`https://public.api.bsky.app/xrpc/app.bsky.graph.getFollows?actor=${did}&cursor=${cursor}&limit=100`) 98 if (!response.ok) { 99 + // throw new Error(`There was a problem getting follows for ${did}. Status - ${response.status}`) 100 + console.error(`There was a problem getting follows for ${did}. Status - ${response.status}`) 101 } 102 103 const data = await response.json() as { ··· 126 for (const [index, follower] of follows.entries()) { 127 const doc = await resolveIdentity(follower.did) 128 const post = await getRecentPost(doc) 129 130 131 // it's possible that someone has never made a post i guess, we should add them to the list ··· 133 // neg 1 can represent never made post 134 unfollowMap.set(follower.handle, -1) 135 } 136 + if (post?.records[0] && post?.records[0]?.value) { 137 + const recentPostCreationDate = post?.records?.[0].value?.createdAt 138 // invalid date for some reason idk 139 const daysSinceLastPost = getDateDifferenceInDays(new Date(recentPostCreationDate), new Date()) 140 if (daysSinceLastPost >= MONTHS_IN_DAYS) { ··· 145 console.info(`Auditing user [${index + 1} / ${follows.length}]`) 146 } 147 148 + // await new Promise((resolve) => setTimeout(resolve, 1000)) 149 } 150 cursor = followsCursor 151 } while (cursor)