🈵

Blueskyの登録者全員フォローする [deprecated]

2023/05/08に公開

ここ2ヶ月ほど、新興SNSのBlueskyを利用しています。

Blueskyでは、登録したばかりなのに、突然海外のアカウントからフォローされることがあります。

https://bsky.app/

これは、「全員フォローするアカウント」が存在するためです。
「現在のサーバーで未だフォローしていないアカウントを返すAPI」が用意されているので、これが値を戻さなくなるまでフォローし続けることで、サーバー内の登録者を全員フォローすることができます。

以下にコードを示します。
Denoで書いているのでインポート部分がfrom "npm:@atproto/api"となっていますが、ここを修正すればNodeでも動かせると思います。

all_follow.ts
import AtprotoAPI from "npm:@atproto/api";
const { BskyAgent } = AtprotoAPI;

const service = "https://bsky.social"; // service URL
const agent = new BskyAgent({ service });

const identifier = "???.bsky.social"; // user handle
const password = "..."; // user password
await agent.login({ identifier, password });

async function follow_all_suggested() {
  const response = await agent.app.bsky.actor.getSuggestions();
  const actors = response?.data?.actors || [];
  if (actors.length === 0) {
    return 0;
  }
  for (const { handle, displayName, did } of actors) {
    console.log({ handle, name: displayName });
    await agent.follow(did);
  }
  return actors.length;
}

console.log("start");
let all_count = 0;
let current_count = await follow_all_suggested();
while (current_count > 0) {
  all_count += current_count;
  current_count = await follow_all_suggested();
}
console.log("end");
console.log(`followed ${all_count} users.`);

実行時はID/passwordを設定し、--allow-net権限を付加します。
実行イメージはこんな感じ。

❯ deno run --allow-net ./all_follow.ts
start
{ handle: "xxx", name: "xxx" }
{ handle: "xxx", name: undefined }
...
end
followed xxx users.

「全員フォローするアカウント」は、この処理を定期自動実行しているものと思われます。
また、service URLを書き換えれば、bsky.social以外のサーバーで使用することも可能です。

Discussion