forked from malfynnction/AltText-Tweeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send-tweet.js
38 lines (33 loc) · 991 Bytes
/
send-tweet.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
const TwitterP = require('twitter')
const keys = require('./keys')
const Twitter = new TwitterP(keys)
const tweetThis = (content, toriginal_id, mentioning_user) => {
if (content.length <= 280) {
const reply = { status: content, in_reply_to_status_id: toriginal_id }
Twitter.post('statuses/update', reply, function (err, tweet) {
if (err) {
console.log(err)
}
})
} else {
const cont_arr = content.split(' ')
let part = ''
while (cont_arr.length > 0 && part.length + cont_arr[0].length <= 279) {
part += cont_arr[0] + ' '
cont_arr.splice(0, 1)
}
const reply = { status: part, in_reply_to_status_id: toriginal_id }
Twitter.post('statuses/update', reply, function (err, tweet) {
if (err) {
console.log(err)
} else {
tweetThis(
`@${mentioning_user} ${cont_arr.join(' ')}`,
tweet.id_str,
mentioning_user
)
}
})
}
}
module.exports = tweetThis