Skip to content

Commit

Permalink
Add clinch indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenyeargin committed Apr 6, 2024
1 parent 0903ebf commit ac762d5
Show file tree
Hide file tree
Showing 3 changed files with 2,997 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/hockey.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ module.exports = (robot) => {
});
};

const isEliminated = (team, standings) => {
const lastWildcard = standings
.find((t) => t.conferenceAbbrev === team.conferenceAbbrev && t.wildcardSequence === 2) || {};
const maxPoints = ((82 - team.gamesPlayed) * 2) + team.points;
if (lastWildcard.points > maxPoints) {
return true;
}
return false;
};

const registerDefaultListener = (team) => {
const statsRegEx = '_team_regex_$';
robot.respond(new RegExp(statsRegEx.replace('_team_regex_', team.regex), 'i'), (msg) => getNhlStatsData(team, msg, () => getMoneyPuckData(team, msg)));
Expand Down Expand Up @@ -339,8 +349,10 @@ module.exports = (robot) => {
standings = json.standings.filter((t) => t.divisionName === filter || t.conferenceName === filter);
}
standings.forEach((t) => {
let clinchIndicator = t.clinchIndicator ? ` (${t.clinchIndicator})` : '';
clinchIndicator = isEliminated(t, standings) ? ' (e)' : clinchIndicator;
const row = [
t.teamName.default,
`${t.teamName.default}${clinchIndicator}`,
t.gamesPlayed,
t.wins,
t.losses,
Expand Down

0 comments on commit ac762d5

Please sign in to comment.