-49
utils/doesUserFollow.ts
-49
utils/doesUserFollow.ts
···
1
1
import { bsky } from "./bsky.ts";
2
-
import { session } from "./session.ts";
3
-
4
-
export const doesUserFollow = async (did: string) => {
5
-
const hardCodedDID = session.agentBskyDID;
6
-
7
-
const maxFollowersToCheck = 5000;
8
-
9
-
const { data } = await bsky.getProfile({
10
-
actor: hardCodedDID,
11
-
});
12
-
13
-
const { followersCount } = data;
14
-
15
-
if (followersCount && followersCount > maxFollowersToCheck) {
16
-
return "";
17
-
}
18
-
19
-
let cursor: string | undefined = undefined;
20
-
let followersChecked = 0;
21
-
22
-
while (followersChecked < maxFollowersToCheck) {
23
-
const { data: followersData } = await bsky.getFollowers({
24
-
actor: hardCodedDID,
25
-
limit: 100,
26
-
cursor: cursor,
27
-
});
28
-
29
-
// Check if the input DID is in this batch of followers
30
-
for (const follower of followersData.followers) {
31
-
if (follower.did === did) {
32
-
return `user "@${follower.handle}" FOLLOWS YOU`;
33
-
}
34
-
}
35
-
36
-
followersChecked += followersData.followers.length;
37
-
38
-
// If there's no cursor, we've reached the end of the followers list
39
-
if (!followersData.cursor) {
40
-
break;
41
-
}
42
-
43
-
cursor = followersData.cursor;
44
-
}
45
-
46
-
// If we get here, we didn't find the DID in the followers we checked
47
-
const userProfile = await bsky.getProfile({ actor: did });
48
-
return `user "@${userProfile.data.handle}" DOES NOT FOLLOW YOU`;
49
-
};
50
-
51
2
/**
52
3
* Checks if user follows target on Bluesky.
53
4
*