tangled
alpha
login
or
join now
isuggest.selfce.st
/
atproto-scripts
forked from
isabelroses.com/atproto-scripts
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
fix: IR errors
isabelroses.com
6 months ago
6fad1001
db3b0665
+18
-9
2 changed files
expand all
collapse all
unified
split
src
toplikes.ts
whodoilike.ts
+1
-1
src/toplikes.ts
···
29
29
}
30
30
31
31
if (response.data.cursor) {
32
32
-
await getLikedPosts(response.data.cursor, posts)
32
32
+
return getLikedPosts(response.data.cursor, posts)
33
33
}
34
34
35
35
return posts;
+17
-8
src/whodoilike.ts
···
1
1
import { Client, CredentialManager } from '@atcute/client';
2
2
-
import { AppBskyFeedPost } from '@atcute/bluesky';
2
2
+
import { AppBskyFeedDefs } from '@atcute/bluesky';
3
3
import fs from 'fs';
4
4
import 'dotenv/config';
5
5
6
6
-
async function getLikedPosts(cursor: string | undefined = undefined, posts: AppBskyFeedPost.Main[] = []): Promise<AppBskyFeedPost.Main[]> {
6
6
+
async function getLikedPosts(cursor: string | undefined = undefined, posts: AppBskyFeedDefs.FeedViewPost[] = []): Promise<AppBskyFeedDefs.FeedViewPost[]> {
7
7
const response = await rpc.get('app.bsky.feed.getActorLikes', {
8
8
params: {
9
9
actor: process.env.DID,
···
23
23
posts.push(feedItem);
24
24
}
25
25
26
26
-
if (response.data.cursor) {
27
27
-
return getLikedPosts(response.data.cursor, posts)
26
26
+
console.log(`added ${posts.length} posts`)
27
27
+
// console.log(response.data.cursor);
28
28
+
29
29
+
// maybe its a skill issue but this IRs, adding the length check helps stop that
30
30
+
if (!response.data.cursor || response.data.feed.length === 0) {
31
31
+
return posts;
28
32
}
29
33
30
30
-
return posts;
34
34
+
return getLikedPosts(response.data.cursor, posts)
31
35
}
32
36
33
37
async function main() {
···
38
42
39
43
const didToLikes = new Map();
40
44
for (const post of posts) {
41
41
-
const { handle, did } = post.post;
45
45
+
const { handle, did } = post.post.author;
42
46
43
47
if (didToLikes.has(did)) {
44
44
-
let didsLikes = didToLikes.get(did);
48
48
+
let didsLikes = didToLikes.get(did).likes;
45
49
didToLikes.set(did, { handle, likes: didsLikes + 1 });
46
50
} else {
47
51
didToLikes.set(did, { handle, likes: 1 })
···
50
54
51
55
var descDidToLikes = new Map([...didToLikes.entries()].sort((a, b) => b[1].likes - a[1].likes));
52
56
57
57
+
let output = "Rank | Handle | Times Liked\n----|------|----------";
58
58
+
let i = 1;
53
59
for (const [did, likers] of descDidToLikes) {
54
54
-
fs.appendFileSync('dist/whodoilike.md', `\n${did} | ${likers.handle} | ${likers.likes}`);
60
60
+
output += `\n${i} | ${likers.handle} (${did}) | ${likers.likes}`;
61
61
+
i++;
55
62
}
63
63
+
64
64
+
fs.writeFileSync("dist/whodoilike.md", output);
56
65
}
57
66
58
67
// hoist me pls