-
Notifications
You must be signed in to change notification settings - Fork 2
/
delivery.js
36 lines (32 loc) · 1.04 KB
/
delivery.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
/*
Module: delivery
Delivers xkcd comic feed to subscribers.
Replies to comic toot with comments mentioning subscribers.
*/
const fs = require('fs-extra')
const config = fs.readJSONSync('./config.json')
const constructComments = accts => {
let comments = [config.comment_for_subscribers_prompt]
accts.forEach(acct => {
if ((comments[comments.length - 1] + ' @' + acct).length <= 500) {
// fits in
comments[comments.length - 1] += ' @' + acct
} else {
// start filling in a new comment
comments[comments.length] =
config.comment_for_subscribers_prompt + ' @' + acct
}
})
return comments
}
const publishComments = (bot, original_toot_id) => {
const subscribers = fs.readJSONSync(config.subscribers_file)
constructComments(subscribers).forEach(cmt => {
bot.post('statuses', {
in_reply_to_id: original_toot_id,
visibility: 'direct',
status: cmt
})
})
}
module.exports = publishComments