From 49e734671391ac8ef43e8cb3c19aa599e9cf3af5 Mon Sep 17 00:00:00 2001 From: Andrea Date: Sun, 5 Jun 2022 10:42:05 +0200 Subject: [PATCH] [calendar] fix bot --- server/calendarBot.js | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/server/calendarBot.js b/server/calendarBot.js index f23c67f0..37f86a83 100644 --- a/server/calendarBot.js +++ b/server/calendarBot.js @@ -84,26 +84,25 @@ const timer = ms => new Promise( res => setTimeout(res, ms)); const { day, message, image } = await (await fetch(locales[locale].url + '/api/calendar/today')).json(); console.log('<<<', message, '>>>'); if (!message) { continue; } + + fs.writeFileSync(imageTmpPath, Buffer.from(await (await fetch(image)).arrayBuffer()), {encoding: 'binary'}); + let imageStream = null; + try { + imageStream = fs.createReadStream(imageTmpPath); + } catch {} + + for (let publisher of process.argv[3].split(',')) { + console.log('Publishing: ' + publisher); + const postId = await publishers[publisher]( + message, + imageStream, + lastPostId[publisher] + ); + console.log(postId); + lastPostId[publisher] = postId; + } } catch (e) { console.error(e); - continue; - } - - fs.writeFileSync(imageTmpPath, Buffer.from(await (await fetch(image)).arrayBuffer()), {encoding: 'binary'}); - let imageStream = null; - try { - imageStream = fs.createReadStream(imageTmpPath); - } catch {} - - for (let publisher of process.argv[3].split(',')) { - console.log('Publishing: ' + publisher); - const postId = await publishers[publisher]( - message, - imageStream, - lastPostId[publisher] - ); - console.log(postId); - lastPostId[publisher] = postId; } } })();