Skip to content

Commit

Permalink
Merge pull request #153 from napple-team/windyakin_20230531_a2fba39d2d
Browse files Browse the repository at this point in the history
エラーハンドリングを追加して反応させる
  • Loading branch information
windyakin authored May 31, 2023
2 parents b3bc429 + 1ecf816 commit 3af43fe
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
});
}
}
}
}));
Expand Down

0 comments on commit 3af43fe

Please sign in to comment.