Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't try to re-subscribe for same game, fix score property #38

Merged
merged 2 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion modules/gameday.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ async function statusPoll (bot) {
globalCache.values.nearestGames = nearestGames.filter(g => g.status.codedGameState !== 'D');
globalCache.values.game.isDoubleHeader = nearestGames.length > 1;
const inProgressGame = nearestGames.find(nearestGame => nearestGame.status.statusCode === 'I' || nearestGame.status.statusCode === 'PW');
if (inProgressGame) {
/*
the "game_finished" socket event is received before a game's status changes to "Final", typically. So we shouldn't try to
re-subscribe just because the status is still "In Progress". We should check if it's a different game.
*/
if (inProgressGame && inProgressGame.gamePk !== globalCache.values.game.currentGamePk) {
LOGGER.info('Gameday: polling stopped: a game is live.');
globalCache.resetGameCache();
globalCache.values.game.currentLiveFeed = await mlbAPIUtil.liveFeed(inProgressGame.gamePk);
globalCache.values.game.currentGamePk = inProgressGame.gamePk;
gamedayUtil.getConstrastingEmbedColors();
module.exports.subscribe(bot, inProgressGame, nearestGames);
} else {
Expand Down
2 changes: 2 additions & 0 deletions modules/global-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const values = {
subscribedChannels: [],
game: {
currentLiveFeed: null,
currentGamePk: null,
isDoubleHeader: null,
lastReportedCompleteAtBatIndex: null,
lastReportedPlayDescription: null,
Expand All @@ -19,6 +20,7 @@ const values = {

function resetGameCache () {
values.game.currentLiveFeed = null;
values.game.currentGamePk = null;
values.game.isDoubleHeader = null;
values.game.lastReportedCompleteAtBatIndex = null;
values.game.lastReportedPlayDescription = null;
Expand Down
4 changes: 2 additions & 2 deletions modules/livefeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ module.exports = {
return liveFeed.liveData.linescore;
},
homeTeamScore: () => {
return liveFeed.liveData.linescore.teams.home.runs;
return liveFeed.liveData.plays.currentPlay.result.homeScore;
},
awayTeamScore: () => {
return liveFeed.liveData.linescore.teams.away.runs;
return liveFeed.liveData.plays.currentPlay.result.awayScore;
},
currentBatterBatSide: () => {
return liveFeed.liveData.plays.currentPlay.matchup.batSide.code;
Expand Down
Loading