Important fixes

This commit is contained in:
ekardnam 2019-07-26 09:36:25 +02:00
parent da0703b34c
commit 073e2bd51a

37
bot.js
View file

@ -91,23 +91,28 @@ let bot = {
})
},
promisePost: function(post, reply = null) {
let that = this
return new Promise(function(resolve, reject) {
that.twitter.post('statuses/update', { status: post, in_reply_to_status_id: reply }, (err, data, response) => {
if (err) reject(err)
else resolve(data)
})
})
},
// post to twitter
// if post is longer than TWITTER_MAX_CHARS divides in multiple tweets
twitterPost: function (post, reply = null) {
let replyTo = reply
let success = true
this.splitTweet(post).forEach((piece) => {
this.twitter.post('statuses/update', { status: piece, in_reply_to_status_id: replyTo }, (err, data, response) => {
if (err) {
success = false
console.error(err)
} else {
replyTo = data.id_str
}
})
})
let pieces = this.splitTweet(post)
if (success) console.log(`[INFO] Tweeted ${post}`)
let promise = this.promisePost(pieces[0], reply)
for (let i = 1; i < pieces.length; i++) {
promise = promise.then(data => this.promisePost(pieces[i], data.id_str))
}
promise.then(() => console.log(`[INFO] Tweeted ${post}`))
.catch(err => console.error(err))
},
// downloads a file from the given url and saves it to temp dir
@ -129,7 +134,11 @@ let bot = {
// makes a post formatted for twitter
// mastodon returns posts in HTML
twitterFormat: function(post) {
return post.replace(/<[^>]*>?/gm, '')
return post
.replace(/<br\/>/g, '\n')
.replace(/<\/p>/g, '\n')
.replace(/&apos;/g, '\'')
.replace(/<[^>]*>?/gm, '')
},
// poll on mastodon status updates