-
-
Save md1guy/e4de3778d18be34d296c8f63cb6ccf37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node-v18.17.1 | |
// npm install '@atproto/api' | |
const Proto = require('@atproto/api') | |
const { BskyAgent } = Proto | |
const agent = new BskyAgent({ service: 'https://bsky.social/' }) | |
const auth = () => agent.login( | |
{ | |
identifier: process.env.BSKY_HANDLE, | |
password: process.env.BSKY_PASSWORD | |
} | |
); | |
const paginateAll = async ( | |
fn, | |
limit = 100, | |
) => { | |
const results = []; | |
let cursor; | |
do { | |
const res = await fn(cursor); | |
results.push(res); | |
cursor = res.cursor; | |
} while (cursor && results.length < limit) | |
return results; | |
} | |
const getAllFollowers = async (actor) => { | |
const paginator = async (cursor) => { | |
const res = await agent.api.app.bsky.graph.getFollowers( | |
{ | |
actor: actor, | |
cursor, | |
limit: 100, | |
}, | |
); | |
return res.data; | |
} | |
return (await paginateAll(paginator)) | |
.flatMap(res => res.followers); | |
} | |
const blockProfile = async (did, handle) => { | |
const blockRecord = { | |
$type: 'app.bsky.graph.block', | |
createdAt: new Date().toISOString(), | |
subject: did | |
} | |
const res = await agent.com.atproto.repo.createRecord( | |
{ | |
collection: 'app.bsky.graph.block', | |
record: blockRecord, | |
repo: agent.session?.did | |
} | |
); | |
if (res?.success) | |
console.log(`sucessfully blocked ${handle}`); | |
else | |
console.log(`failed blocking ${handle}`); | |
} | |
const blockAllFollowers = async handle => { | |
await auth(); | |
const blockFollowersDid = (await agent.resolveHandle({ handle: handle }))?.data.did; | |
const followers = await getAllFollowers(blockFollowersDid); | |
for (const profile of followers) { | |
await blockProfile(profile.did, profile.handle); | |
} | |
} | |
blockAllFollowers('publeecist.bsky.social'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment