-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
78 lines (59 loc) · 1.99 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { agent } from './bsky.js';
import { Song, loadSongs } from './songs.js';
const doQuote = (songs: Song[], reply?: any) => {
const songIndex = Math.floor(Math.random() * songs.length);
const song = songs[songIndex];
if (song.lyrics.length != 0) {
const lineIndex = Math.floor(Math.random() * song.lyrics.length);
const line = song.lyrics[lineIndex];
const post = `${line}\n\n${song.title} - ${song.album}`;
console.log(`${new Date().toLocaleString()}: ${post}\n`);
agent
.post({
$type: 'app.bsky.feed.post',
text: post,
createdAt: new Date().toISOString(),
reply,
})
.catch((err) => console.error(err));
song.lyrics.splice(lineIndex, 1);
console.log(`- ${song.lyrics.length} lyric lines remaining in this song`);
}
if (song.lyrics.length === 0) {
songs.splice(songIndex, 1);
console.log(`- removing song with empty lyrics, ${songs.length} songs remaining`);
}
return songs.length;
};
console.log(`${new Date().toLocaleString()}: ****** Floyd Quoter Started *****\n`);
let songs = loadSongs();
doQuote(songs);
setInterval(() => {
const sonCount = doQuote(songs);
if (sonCount === 0) {
console.log(`- reloading songs`);
songs = loadSongs();
}
}, 60 * 60 * 1000 * 2);
// ****** Reply to notifications part
setInterval(async () => {
const { data } = await agent.listNotifications();
data.notifications
.filter((n) => n.reason == 'mention' && !n.isRead)
.forEach(async (n) => {
console.log('**** Replying!!!');
const parent = { uri: n.uri, cid: n.cid };
// @ts-ignore
const root = n.record.reply?.root
? // @ts-ignore
{ uri: n.record.reply?.root.uri, cid: n.record.reply?.root.cid }
: parent;
const reply = { root, parent };
const sonCount = doQuote(songs, reply);
if (sonCount === 0) {
console.log(`- reloading songs`);
songs = loadSongs();
}
});
await agent.updateSeenNotifications();
}, 5000);