From 7480de502034c600888c67773d0b92dd15d11ff4 Mon Sep 17 00:00:00 2001 From: Alec Date: Sun, 9 Mar 2025 13:54:21 -0400 Subject: [PATCH] display starter stats by game type --- modules/command-util.js | 17 ++++++++++++++--- modules/interaction-handlers.js | 11 +++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/modules/command-util.js b/modules/command-util.js index 5d4c018..4925d86 100644 --- a/modules/command-util.js +++ b/modules/command-util.js @@ -640,11 +640,11 @@ module.exports = { }); }, - buildPitchingStatsMarkdown: (pitchingStats, pitchMix, lastThree, seasonAdvanced, sabermetrics, includeExtra = false) => { + buildPitchingStatsMarkdown: (pitchingStats, pitchMix, lastThree, seasonAdvanced, sabermetrics, gameType, includeExtra = false) => { let reply = ''; if (lastThree) { - reply += '\n**Recent Games:** \n'; + reply += `\n**Recent Games${resolveGameType(gameType)}:** \n`; reply += `G: ${lastThree.gamesPlayed}, `; reply += `ERA: ${lastThree.era}, `; reply += `Hits: ${lastThree.hits}, `; @@ -652,7 +652,7 @@ module.exports = { reply += `BB: ${lastThree.baseOnBalls}, `; reply += `HR: ${lastThree.homeRuns}\n`; } - reply += '**All Games:** \n'; + reply += `**All Games${resolveGameType(gameType)}:** \n`; if (!pitchingStats) { reply += 'G: 0, '; reply += 'W-L: -, '; @@ -1262,3 +1262,14 @@ function getDivisionAbbreviation (division) { return 'C'; } } + +function resolveGameType (gameType) { + switch (gameType) { + case 'R': + return ''; + case 'P': + return ' (Postseason)'; + case 'S': + return ' (Spring Training)'; + } +} diff --git a/modules/interaction-handlers.js b/modules/interaction-handlers.js index b30fb65..41d2a24 100644 --- a/modules/interaction-handlers.js +++ b/modules/interaction-handlers.js @@ -32,8 +32,8 @@ module.exports = { } const matchup = await mlbAPIUtil.matchup(game.gamePk); const probables = matchup.probables; - const hydratedHomeProbable = await commandUtil.hydrateProbable(probables.homeProbable); - const hydratedAwayProbable = await commandUtil.hydrateProbable(probables.awayProbable); + const hydratedHomeProbable = await commandUtil.hydrateProbable(probables.homeProbable, matchup.probables.gameType); + const hydratedAwayProbable = await commandUtil.hydrateProbable(probables.awayProbable, matchup.probables.gameType); joinImages([hydratedHomeProbable.spot, hydratedAwayProbable.spot], { direction: 'horizontal', offset: 10, margin: 0, color: 'transparent' }) .then(async (img) => { @@ -50,7 +50,8 @@ module.exports = { hydratedHomeProbable.pitchMix, hydratedHomeProbable.pitchingStats.lastXGames, hydratedHomeProbable.pitchingStats.seasonAdvanced, - hydratedHomeProbable.pitchingStats.sabermetrics + hydratedHomeProbable.pitchingStats.sabermetrics, + matchup.probables.gameType ), inline: true }) @@ -63,7 +64,8 @@ module.exports = { hydratedAwayProbable.pitchMix, hydratedAwayProbable.pitchingStats.lastXGames, hydratedAwayProbable.pitchingStats.seasonAdvanced, - hydratedAwayProbable.pitchingStats.sabermetrics + hydratedAwayProbable.pitchingStats.sabermetrics, + matchup.probables.gameType ), inline: true }); @@ -492,6 +494,7 @@ module.exports = { pitcherInfo.pitchingStats.lastXGames, pitcherInfo.pitchingStats.seasonAdvanced, pitcherInfo.pitchingStats.sabermetrics, + (statType || 'R'), true ), (statType || 'R'),