From acc70e6a83af5bc3cf43c77ea5216c2ce0530a74 Mon Sep 17 00:00:00 2001 From: dbroqua Date: Fri, 1 May 2020 09:10:13 +0200 Subject: [PATCH] Fixed bug on removed cover --- libs.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libs.js b/libs.js index 02ff969..b25e13c 100644 --- a/libs.js +++ b/libs.js @@ -249,19 +249,28 @@ const formatMessage = (values) => { * @param {String} cover */ const publishMessage = (song, cover) => { + const status = formatMessage(song) + const catch = (err, res) => { + if ( err ) { + console.log(config.colors.FgRed, 'ERR on publishMessage:', err, config.colors.Reset) + } + } if (cover) { getMedia(cover, (err, dest) => { if (err) { - M.post('statuses', { status: formatMessage(song) }) + M.post('statuses', { status }, catch) } else { M.post('media', { file: fs.createReadStream(dest) }).then(resp => { const id = resp.data.id - M.post('statuses', { status: formatMessage(song), media_ids: [id] }) + M.post('statuses', { status, media_ids: [id] }, catch) + }) + .catch( () => { + M.post('statuses', { status }, catch) }) } }) } else { - M.post('statuses', { status: formatMessage(song) }) + M.post('statuses', { status }, catch) } }