-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfix-mistake.js
49 lines (39 loc) · 1.34 KB
/
fix-mistake.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import bsky from '@atproto/api';
import * as dotenv from 'dotenv';
dotenv.config();
const { BskyAgent } = bsky;
const agent = new BskyAgent({
service: 'https://bsky.social',
});
await agent.login({
identifier: process.env.BLUESKY_USERNAME,
password: process.env.BLUESKY_PASSWORD,
});
async function deletePostsWithText(targetText) {
try {
console.log(`Fetching posts for user: ${process.env.BLUESKY_USERNAME}`);
// Fetch posts from your feed
const { data } = await agent.getAuthorFeed({ actor: process.env.BLUESKY_USERNAME });
const posts = data.feed;
if (!posts || posts.length === 0) {
console.log('No posts found.');
return;
}
// Iterate over posts and delete those matching the target text
for (const post of posts) {
const postText = post.post.record.text;
if (postText.trim().toLowerCase() === targetText.toLowerCase()) {
const postUri = post.post.uri;
console.log(`Deleting post: "${postText}" with URI: ${postUri}`);
const response = await agent.deletePost(postUri);
console.log(response);
console.log('Post deleted successfully.');
}
}
console.log('Completed processing posts.');
} catch (error) {
console.error('Error while deleting posts:', error);
}
}
// Delete all posts containing "hi"
await deletePostsWithText('hi');