From 1ecf8160f2a3184f96c6a46fbe5c1319503a8d0c Mon Sep 17 00:00:00 2001 From: windyakin Date: Wed, 31 May 2023 21:04:23 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=8F=E3=83=B3?= =?UTF-8?q?=E3=83=89=E3=83=AA=E3=83=B3=E3=82=B0=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=97=E3=81=A6=E5=8F=8D=E5=BF=9C=E3=81=95=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 76b463c..9e1a2c0 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ const app = new App({ signingSecret: process.env.SLACK_SIGNING_SECRET, }); -app.message(/https:\/\/twitter.com/, async ({ message, context }) => { +app.message(/https:\/\/twitter.com/, async ({ message, context, say }) => { const matchPettern = new RegExp('https://twitter.com/[a-zA-Z0-9_]+/status/[0-9]+', 'gi'); const tweetUrls = message.text.match(matchPettern).filter( (match, currentIndex, matches) => matches.indexOf(match) === currentIndex @@ -18,20 +18,31 @@ app.message(/https:\/\/twitter.com/, async ({ message, context }) => { }); if (searchResponse.messages.matches.filter((item) => item.ts !== message.ts).length !== 0) { - await app.client.reactions.add({ - token: context.botToken, - channel: message.channel, - name: 'x', - timestamp: message.ts, - }); + try { + await app.client.reactions.add({ + token: context.botToken, + channel: message.channel, + name: 'x', + timestamp: message.ts, + }); + } catch (err) { + console.error(err); + } } else { if (process.env.GANBARUBY_ENABLE) { - await axios.post(`${process.env.GANBARUBY_URL}/save`, { tweetUrl: match }, { - auth: { - username: process.env.GANBARUBY_BASIC_USER, - password: process.env.GANBARUBY_BASIC_PASS, - } - }) + try { + await axios.post(`${process.env.GANBARUBY_URL}/save`, { tweetUrl: match }, { + auth: { + username: process.env.GANBARUBY_BASIC_USER, + password: process.env.GANBARUBY_BASIC_PASS, + } + }); + } catch (err) { + await say({ + text: '|c||^.-^|| 画像の保存に失敗しましたわ〜!', + thread_ts: message.ts + }); + } } } }));