Advertisement
Guest User

Untitled

a guest
Nov 20th, 2024
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypoScript 1.49 KB | Software | 0 0
  1. import { AtpAgent } from '@atproto/api';
  2. import * as dotenv from 'dotenv';
  3.  
  4. const agent = new AtpAgent({ service: 'https://bsky.social' });
  5.  
  6. dotenv.config();
  7.  
  8. function sleep(ms: number) {
  9.   return new Promise((resolve) => setTimeout(resolve, ms));
  10. }
  11.  
  12. async function blockFollowersOfAccount(targetHandle: string) {
  13.   try {
  14.  
  15.     await agent.login({
  16.       identifier: process.env.BSKY_BOT_HANDLE!,
  17.       password: process.env.BSKY_BOT_PASSWORD!
  18.     });
  19.  
  20.     let cursor: string | undefined = undefined;
  21.  
  22.     do {
  23.       const response = await agent.getFollowers({
  24.         actor: targetHandle,
  25.         limit: 100,
  26.         cursor,
  27.       });
  28.  
  29.       const followers = response.data.followers;
  30.  
  31.       for (const follower of followers) {
  32.  
  33.         try {
  34.  
  35.           await agent.app.bsky.graph.block.create(
  36.             { repo: agent.session!.did },
  37.             {
  38.               subject: follower.did,
  39.               createdAt: new Date().toISOString(),
  40.             }
  41.           );
  42.  
  43.           console.log(`Blocked follower: ${follower.handle}`);
  44.         } catch (error) {
  45.           console.error(`Failed to block follower: ${follower.handle}`, error);
  46.         }
  47.  
  48.  
  49.         await sleep(10000);
  50.  
  51.       }
  52.  
  53.       cursor = response.data.cursor;
  54.     } while (cursor);
  55.  
  56.     console.log(`All followers of ${targetHandle} have been blocked.`);
  57.   } catch (error) {
  58.     console.error('An error occurred:', error);
  59.   }
  60. }
  61.  
  62. blockFollowersOfAccount('asshole-whose-followers-to-block.bsky.social');
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement