From 558d26dcba3f5676d3bdf347523f8b3027fe9c81 Mon Sep 17 00:00:00 2001 From: Stephen Yeargin Date: Mon, 6 May 2024 20:33:12 -0500 Subject: [PATCH 1/2] Congratulate when user(s) run the board --- src/untappd-friends.js | 23 +++++++++++++++++++++++ test/untappd-friends-slack_test.js | 3 +++ test/untappd-friends_test.js | 1 + 3 files changed, 27 insertions(+) diff --git a/src/untappd-friends.js b/src/untappd-friends.js index fc0d96f..a17e69d 100755 --- a/src/untappd-friends.js +++ b/src/untappd-friends.js @@ -292,6 +292,29 @@ module.exports = (robot) => { contents.push(chunk); }); + // Congratulate the users that "run the board" + if (countToReturn > 1) { + const uniqueUsers = []; + const uniqueLocations = []; + obj.response.checkins.items.forEach((checkin) => { + if (!uniqueUsers.includes(formatDisplayName(checkin.user))) { + uniqueUsers.push(formatDisplayName(checkin.user)); + } + if (!uniqueLocations.includes(checkin.venue.venue_name)) { + uniqueLocations.push(checkin.venue.venue_name); + } + }); + if (uniqueLocations.length === 1 && uniqueLocations[0]) { + contents.push({ + fallback: `🏆 Congratulations to ${uniqueUsers.join(' + ')} for running the board at ${uniqueLocations[0]}! 🍻`, + }); + } else if (uniqueUsers.length === 1) { + contents.push({ + fallback: `🏆 Congratulations to ${uniqueUsers[0]} for running the board! 🍻`, + }); + } + } + // Slack formatting if (/slack/i.test(robot.adapterName)) { robot.messageRoom(msg.message.room, { attachments: contents, unfurl_links: false }); diff --git a/test/untappd-friends-slack_test.js b/test/untappd-friends-slack_test.js index 1b73069..763ced7 100644 --- a/test/untappd-friends-slack_test.js +++ b/test/untappd-friends-slack_test.js @@ -87,6 +87,9 @@ describe('hubot-untappd-friends for slack', () => { title_link: 'https://untappd.com/user/heathseals/checkin/578869664', ts: 1522406504, }, + { + fallback: '🏆 Congratulations to heath (heathseals) for running the board! 🍻', + }, ], unfurl_links: false, }, diff --git a/test/untappd-friends_test.js b/test/untappd-friends_test.js index 7412e13..1a2331d 100644 --- a/test/untappd-friends_test.js +++ b/test/untappd-friends_test.js @@ -64,6 +64,7 @@ describe('hubot-untappd-friends', () => { ['alice', '@hubot untappd'], ['hubot', 'heath (heathseals) was drinking Blonde Ale (Blonde Ale - 5%) by Gara Guzu Brewery at 49 Çukurcuma - an hour ago'], ['hubot', 'heath (heathseals) was drinking Efes Pilsen (Pilsner - Other - 5%) by Anadolu Efes at DERALIYE OTTOMAN CUISINE - 8 hours ago'], + ['hubot', '🏆 Congratulations to heath (heathseals) for running the board! 🍻'], ]); done(); } catch (err) { From 5ba3a610e13fb172813dfd117b9f2ea4515482f6 Mon Sep 17 00:00:00 2001 From: Stephen Yeargin Date: Mon, 6 May 2024 20:46:34 -0500 Subject: [PATCH 2/2] Fix Slack formatting --- src/untappd-friends.js | 2 ++ test/untappd-friends-slack_test.js | 1 + 2 files changed, 3 insertions(+) diff --git a/src/untappd-friends.js b/src/untappd-friends.js index a17e69d..3c06b29 100755 --- a/src/untappd-friends.js +++ b/src/untappd-friends.js @@ -306,10 +306,12 @@ module.exports = (robot) => { }); if (uniqueLocations.length === 1 && uniqueLocations[0]) { contents.push({ + text: `🏆 Congratulations to ${uniqueUsers.join(' + ')} for running the board at ${uniqueLocations[0]}! 🍻`, fallback: `🏆 Congratulations to ${uniqueUsers.join(' + ')} for running the board at ${uniqueLocations[0]}! 🍻`, }); } else if (uniqueUsers.length === 1) { contents.push({ + text: `🏆 Congratulations to ${uniqueUsers[0]} for running the board! 🍻`, fallback: `🏆 Congratulations to ${uniqueUsers[0]} for running the board! 🍻`, }); } diff --git a/test/untappd-friends-slack_test.js b/test/untappd-friends-slack_test.js index 763ced7..bc21f5d 100644 --- a/test/untappd-friends-slack_test.js +++ b/test/untappd-friends-slack_test.js @@ -88,6 +88,7 @@ describe('hubot-untappd-friends for slack', () => { ts: 1522406504, }, { + text: '🏆 Congratulations to heath (heathseals) for running the board! 🍻', fallback: '🏆 Congratulations to heath (heathseals) for running the board! 🍻', }, ],