Skip to content

Commit

Permalink
Merge pull request #74 from stephenyeargin/run-the-board
Browse files Browse the repository at this point in the history
Congratulate when user(s) run the board
  • Loading branch information
stephenyeargin authored May 7, 2024
2 parents 51c6d67 + 5ba3a61 commit 9f4e67a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/untappd-friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,31 @@ 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({
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! 🍻`,
});
}
}

// Slack formatting
if (/slack/i.test(robot.adapterName)) {
robot.messageRoom(msg.message.room, { attachments: contents, unfurl_links: false });
Expand Down
4 changes: 4 additions & 0 deletions test/untappd-friends-slack_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ describe('hubot-untappd-friends for slack', () => {
title_link: 'https://untappd.com/user/heathseals/checkin/578869664',
ts: 1522406504,
},
{
text: '🏆 Congratulations to heath (heathseals) for running the board! 🍻',
fallback: '🏆 Congratulations to heath (heathseals) for running the board! 🍻',
},
],
unfurl_links: false,
},
Expand Down
1 change: 1 addition & 0 deletions test/untappd-friends_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9f4e67a

Please sign in to comment.