Fix
This commit is contained in:
parent
9869f60213
commit
0649ade820
2 changed files with 14 additions and 13 deletions
2
app.js
2
app.js
|
@ -16,7 +16,7 @@ let main = () => {
|
|||
}
|
||||
|
||||
if (storage.data.token && storage.data.token_secret) {
|
||||
console.log("[INFO] Starting bot")
|
||||
console.log('[INFO] Starting bot')
|
||||
bot.start()
|
||||
} else {
|
||||
oauth.start()
|
||||
|
|
27
bot.js
27
bot.js
|
@ -57,6 +57,7 @@ let bot = {
|
|||
// Video 15MB
|
||||
// medias is an array of filenames
|
||||
twitterPostWithMedias: function (post, medias) {
|
||||
let that = this
|
||||
let pieces = this.splitForImage(post)
|
||||
|
||||
let uploads = []
|
||||
|
@ -65,7 +66,7 @@ let bot = {
|
|||
let b64content = readBase64(media)
|
||||
uploads.push(
|
||||
new Promise((resolve, reject) => {
|
||||
this.twitter.post('media/upload', { media_data: b64content }, (err, data, response) => {
|
||||
that.twitter.post('media/upload', { media_data: b64content }, (err, data, response) => {
|
||||
if (err) reject(err)
|
||||
else resolve(data)
|
||||
})
|
||||
|
@ -75,19 +76,18 @@ let bot = {
|
|||
|
||||
return Promise.all(uploads).then(datas => {
|
||||
let mediaIds = datas.map(data => data.media_id_string)
|
||||
let altText = 'test'
|
||||
mediaIds.forEach(mediaId => {
|
||||
this.twitter.post('media/metadata/create', { media_id: mediaId, alt_text: { text: altText } }, (err, data, response) => {
|
||||
if (!err) {
|
||||
this.twitter.post('statuses/update', { status: pieces[0], media_ids: mediaIds }, (err, data, response) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
that.twitter.post('statuses/update', { status: pieces[0], media_ids: mediaIds }, (err, data, response) => {
|
||||
if (!err) {
|
||||
resolve(data)
|
||||
} else reject(err)
|
||||
})
|
||||
})
|
||||
}).then((data) => {
|
||||
if (pieces.length > 1) return that.twitterPost(pieces[1], data.id_str)
|
||||
else return Promise.resolve()
|
||||
}).then(() => {
|
||||
console.log(`[INFO] Tweeted ${post} with ${medias}`)
|
||||
if (pieces.length > 1) this.twitterPost(pieces[1], data.id_str)
|
||||
} else throw err
|
||||
})
|
||||
} else throw err
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
|
@ -111,7 +111,7 @@ let bot = {
|
|||
promise = promise.then(data => this.promisePost(pieces[i], data.id_str))
|
||||
}
|
||||
|
||||
promise.then(() => console.log(`[INFO] Tweeted ${post}`))
|
||||
return promise.then(() => console.log(`[INFO] Tweeted ${post}`))
|
||||
.catch(err => console.error(err))
|
||||
},
|
||||
|
||||
|
@ -138,6 +138,7 @@ let bot = {
|
|||
.replace(/<br\/>/g, '\n')
|
||||
.replace(/<\/p>/g, '\n')
|
||||
.replace(/'/g, '\'')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/<[^>]*>?/gm, '')
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue