-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
33 lines (28 loc) · 936 Bytes
/
index.ts
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
import bsky from '@atproto/api';
const { BskyAgent } = bsky;
import * as dotenv from 'dotenv';
import process from 'node:process';
import fs from 'node:fs';
dotenv.config();
const agent = new BskyAgent({
service: 'https://bsky.social',
});
await agent.login({
identifier: process.env.BSKY_USERNAME!,
password: process.env.BSKY_PASSWORD!,
});
const lines = fs.readFileSync('songofsongs.txt', 'utf8').split('\n');
const alreadyPosted = fs.readFileSync('posted.txt', 'utf8').split('\n');
let possibleOutput = lines.filter((line) => !alreadyPosted.includes(line));
if (possibleOutput.length === 0) {
fs.rmSync('posted.txt');
possibleOutput = lines;
fs.appendFileSync('posted.txt', '\n');
}
const post = possibleOutput[Math.floor(Math.random() * possibleOutput.length)];
await agent.post({
$type: 'app.bsky.feed.post',
text: post,
createdAt: new Date().toISOString(),
});
fs.appendFileSync('posted.txt', post + '\n');