this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 104 lines 2.9 kB view raw
1import { Bot } from '@skyware/bot'; 2 3import { BSKY_IDENTIFIER, BSKY_PASSWORD } from './config.js'; 4import { LABELS } from './constants.js'; 5import sharp from 'sharp'; 6 7const bot = new Bot(); 8 9try { 10 await bot.login({ 11 identifier: BSKY_IDENTIFIER, 12 password: BSKY_PASSWORD, 13 }); 14} catch (error) { 15 console.error('Error logging in: ', error); 16 process.exit(1); 17} 18 19process.stdout.write('WARNING: This will delete all posts in your profile. Are you sure you want to continue? (y/n) '); 20 21const answer = await new Promise((resolve) => { 22 process.stdin.once('data', (data) => { 23 resolve(data.toString().trim().toLowerCase()); 24 }); 25}); 26 27if (answer === 'y') { 28 const postsToDelete = await bot.profile.getPosts(); 29 for (const post of postsToDelete.posts) { 30 await post.delete(); 31 } 32 console.log('All posts have been deleted.'); 33} else { 34 console.log('Operation cancelled.'); 35 process.exit(0); 36} 37 38const post = await bot.post({ 39 text: 'Like the replies to this post to receive labels.', 40 threadgate: { allowLists: [] }, 41}); 42 43interface Card { 44 error: string; 45 likely_type: string; 46 url: string; 47 title: string; 48 description: string; 49 image: string; 50} 51 52const labelNamesAndUrls = LABELS.map((label) => ({ name: label.locales[0].name, url: label.typeinmindUrl })); 53const labelRkeys: Record<string, string> = {}; 54for (const label of labelNamesAndUrls) { 55 // const card: Card = await (async (url: string) => { 56 // const res = await fetch(`https://cardyb.bsky.app/v1/extract?url=${encodeURIComponent(url)}`); 57 // return await res.json() as Card; 58 // })(label.url); 59 // const image = await (async (url: string) => { 60 // const res = await fetch(url); 61 // return await res.arrayBuffer(); 62 // })(card.image); 63 // const imageBuffer = await sharp(image).jpeg({ quality: 90 }).toBuffer(); 64 // const imageBlob = new Blob([imageBuffer], { type: 'image/jpeg' }); 65 const labelPost = await post.reply({ 66 text: label.name, 67 facets: [ 68 { 69 index: { 70 byteStart: 0, 71 byteEnd: label.name.length 72 }, 73 features: [ 74 { 75 $type: 'app.bsky.richtext.facet#link', 76 uri: label.url, 77 }, 78 ], 79 }, 80 ], 81 // external: { 82 // uri: card.url, 83 // title: card.title, 84 // description: card.description, 85 // thumb: { 86 // data: imageBlob, 87 // } 88 // }, 89 }); 90 labelRkeys[label.name] = labelPost.uri.split('/').pop()!; 91} 92 93console.log('Label rkeys:'); 94for (const [name, rkey] of Object.entries(labelRkeys)) { 95 console.log(` name: '${name}',`); 96 console.log(` rkey: '${rkey}',`); 97} 98 99const deletePost = await bot.post({ text: 'Like this post to delete all labels.' }); 100const deletePostRkey = deletePost.uri.split('/').pop()!; 101console.log('Delete post rkey:'); 102console.log(`export const DELETE = '${deletePostRkey}';`); 103 104process.exit(0);