Skip to content

Commit 61fe501

Browse files
committed
report final score
1 parent 75cdcd4 commit 61fe501

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

modules/gameday-util.js

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ module.exports = {
1818
);
1919
},
2020

21+
didOurTeamWin: (homeScore, awayScore) => {
22+
const feed = liveFeed.init(globalCache.values.game.currentLiveFeed);
23+
return (homeScore > awayScore && feed.homeTeamId() === parseInt(process.env.TEAM_ID))
24+
|| (awayScore > homeScore && feed.awayTeamId() === parseInt(process.env.TEAM_ID));
25+
},
26+
2127
getConstrastingEmbedColors: () => {
2228
const feed = liveFeed.init(globalCache.values.game.currentLiveFeed);
2329
globalCache.values.game.homeTeamColor = globals.TEAMS.find(

modules/gameday.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ async function statusPoll (bot) {
4545
function subscribe (bot, liveGame, games) {
4646
LOGGER.trace('Gameday: subscribing...');
4747
const ws = mlbAPIUtil.websocketSubscribe(liveGame.gamePk);
48+
const feed = liveFeed.init(globalCache.values.game.currentLiveFeed);
4849
ws.addEventListener('message', async (e) => {
4950
try {
5051
const eventJSON = JSON.parse(e.data);
@@ -65,6 +66,11 @@ function subscribe (bot, liveGame, games) {
6566
globalCache.values.game.finished = true;
6667
globalCache.values.game.startReported = false;
6768
LOGGER.info('NOTIFIED OF GAME CONCLUSION: CLOSING...');
69+
await processAndPushPlay(bot, {
70+
reply: `## Final: ${feed.awayAbbreviation()} ${feed.awayTeamScore()} - ${feed.homeTeamScore()} ${feed.homeAbbreviation()}`,
71+
isScoringPlay: true,
72+
isOut: false
73+
}, liveGame, globalCache.values.game.lastReportedCompleteAtBatIndex, false);
6874
ws.close();
6975
await statusPoll(bot, games);
7076
} else if (!globalCache.values.game.finished) {
@@ -138,7 +144,7 @@ async function reportAnyMissedEvents (atBat, bot, gamePk, atBatIndex) {
138144
}
139145
}
140146

141-
async function processAndPushPlay (bot, play, gamePk, atBatIndex) {
147+
async function processAndPushPlay (bot, play, gamePk, atBatIndex, includeTitle = true) {
142148
if (play.reply
143149
&& play.reply.length > 0
144150
&& !globalCache.values.game.reportedDescriptions
@@ -152,17 +158,19 @@ async function processAndPushPlay (bot, play, gamePk, atBatIndex) {
152158
globalCache.values.game.lastReportedCompleteAtBatIndex = atBatIndex;
153159
}
154160
const embed = new EmbedBuilder()
155-
.setTitle(gamedayUtil.deriveHalfInning(feed.halfInning()) + ' ' +
156-
feed.inning() + ', ' +
157-
feed.awayAbbreviation() + (play.isScoringPlay
158-
? ' vs. '
159-
: ' ' + play.awayScore + ' - ' + play.homeScore + ' ') +
160-
feed.homeAbbreviation() + (play.isScoringPlay ? ' - Scoring Play \u2757' : ''))
161161
.setDescription(play.reply + (play.isOut && play.outs === 3 && !gamedayUtil.didGameEnd(play.homeScore, play.awayScore) ? gamedayUtil.getDueUp() : ''))
162162
.setColor((feed.halfInning() === 'top'
163163
? globalCache.values.game.awayTeamColor
164164
: globalCache.values.game.homeTeamColor
165165
));
166+
if (includeTitle) {
167+
embed.setTitle(gamedayUtil.deriveHalfInning(feed.halfInning()) + ' ' +
168+
feed.inning() + ', ' +
169+
feed.awayAbbreviation() + (play.isScoringPlay
170+
? ' vs. '
171+
: ' ' + play.awayScore + ' - ' + play.homeScore + ' ') +
172+
feed.homeAbbreviation() + (play.isScoringPlay ? ' - Scoring Play \u2757' : ''));
173+
}
166174
const messages = [];
167175
for (const channelSubscription of globalCache.values.subscribedChannels) {
168176
const returnedChannel = await bot.channels.fetch(channelSubscription.channel_id);

modules/livefeed.js

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ module.exports = {
4040
linescore: () => {
4141
return liveFeed.liveData.linescore;
4242
},
43+
homeTeamScore: () => {
44+
return liveFeed.liveData.linescore.teams.home.runs;
45+
},
46+
awayTeamScore: () => {
47+
return liveFeed.liveData.linescore.teams.away.runs;
48+
},
4349
currentBatterBatSide: () => {
4450
return liveFeed.liveData.plays.currentPlay.matchup.batSide.code;
4551
},

0 commit comments

Comments
 (0)