diff --git a/modules/command-util.js b/modules/command-util.js index 07ef2fd..43d5841 100644 --- a/modules/command-util.js +++ b/modules/command-util.js @@ -276,7 +276,7 @@ module.exports = { return {}; }, - buildBatterSavantTable: async (statcast, metricSummaries) => { + buildBatterSavantTable: async (statcast, metricSummaries, spot) => { const value = [ { label: 'Batting Run Value', value: statcast.swing_take_run_value, metric: 'swing_take_run_value', percentile: statcast.percent_rank_swing_take_run_value }, { label: 'Baserunning Run Value', value: statcast.runner_run_value, metric: 'runner_run_value', percentile: statcast.percent_rank_runner_run_value }, @@ -314,6 +314,9 @@ module.exports = { ]; const html = `
` + + `alt text` + '

Value

' + buildSavantSection(value, metricSummaries) + '

Hitting

' + @@ -327,7 +330,7 @@ module.exports = { return (await getScreenshotOfSavantTable(html)); }, - buildPitcherSavantTable: async (statcast, metricSummaries) => { + buildPitcherSavantTable: async (statcast, metricSummaries, spot) => { const value = [ { label: 'Pitching Run Value', value: statcast.swing_take_run_value, metric: 'swing_take_run_value', percentile: statcast.percent_rank_swing_take_run_value }, { label: 'Fastball Run Value', value: Math.round(statcast.pitch_run_value_fastball), metric: 'pitch_run_value_fastball', percentile: statcast.percent_rank_pitch_run_value_fastball }, @@ -350,6 +353,9 @@ module.exports = { ]; const html = `
` + + `alt text` + '

Value

' + buildSavantSection(value, metricSummaries, true) + '

Pitching

' + @@ -505,7 +511,7 @@ module.exports = { return matchingPlayer; }, - getPitcherEmbed: (pitcher, pitcherInfo, isLiveGame, description) => { + getPitcherEmbed: (pitcher, pitcherInfo, isLiveGame, description, savantMode = false) => { const feed = liveFeed.init(globalCache.values.game.currentLiveFeed); if (isLiveGame) { const abbreviations = { @@ -517,24 +523,28 @@ module.exports = { ? abbreviations.home : abbreviations.away; const inning = feed.inning(); - return new EmbedBuilder() + const embed = new EmbedBuilder() .setTitle(halfInning.toUpperCase() + ' ' + inning + ', ' + abbreviations.away + ' vs. ' + abbreviations.home + ': Current Pitcher') .setDescription('## ' + (pitcherInfo.handedness ? pitcherInfo.handedness + 'HP **' : '**') + (pitcher.fullName || 'TBD') + '** (' + abbreviation + ')' + (description || '')) - .setThumbnail('attachment://spot.png') .setImage('attachment://savant.png') .setColor((halfInning === 'top' ? globalCache.values.game.homeTeamColor : globalCache.values.game.awayTeamColor) ); + + if (!savantMode) { + embed.setThumbnail('attachment://spot.png'); + } + + return embed; } else { const embed = new EmbedBuilder() .setTitle((pitcherInfo.handedness ? pitcherInfo.handedness + 'HP ' : '') + pitcher.fullName) - .setThumbnail('attachment://spot.png') .setImage('attachment://savant.png') .setColor(globals.TEAMS.find(team => team.id === pitcher.currentTeam.id).primaryColor); @@ -542,11 +552,15 @@ module.exports = { embed.setDescription(description); } + if (!savantMode) { + embed.setThumbnail('attachment://spot.png'); + } + return embed; } }, - getBatterEmbed: (batter, batterInfo, isLiveGame, description) => { + getBatterEmbed: (batter, batterInfo, isLiveGame, description, savantMode = false) => { const feed = liveFeed.init(globalCache.values.game.currentLiveFeed); if (isLiveGame) { const abbreviations = { @@ -558,22 +572,26 @@ module.exports = { ? abbreviations.home : abbreviations.away; const inning = feed.inning(); - return new EmbedBuilder() + const embed = new EmbedBuilder() .setTitle(halfInning.toUpperCase() + ' ' + inning + ', ' + abbreviations.away + ' vs. ' + abbreviations.home + ': Current Batter') .setDescription('## ' + feed.currentBatterBatSide() + 'HB ' + batter.fullName + ' (' + abbreviation + ')' + (description || '')) - .setThumbnail('attachment://spot.png') .setImage('attachment://savant.png') .setColor((halfInning === 'top' ? globalCache.values.game.awayTeamColor : globalCache.values.game.homeTeamColor) ); + + if (!savantMode) { + embed.setThumbnail('attachment://spot.png'); + } + + return embed; } else { const embed = new EmbedBuilder() .setTitle(batterInfo.stats.batSide.code + 'HB ' + batter.fullName) - .setThumbnail('attachment://spot.png') .setImage('attachment://savant.png') .setColor(globals.TEAMS.find(team => team.id === batter.currentTeam.id).primaryColor); @@ -581,6 +599,10 @@ module.exports = { embed.setDescription(description); } + if (!savantMode) { + embed.setThumbnail('attachment://spot.png'); + } + return embed; } }, diff --git a/modules/interaction-handlers.js b/modules/interaction-handlers.js index dca9fae..903c4b3 100644 --- a/modules/interaction-handlers.js +++ b/modules/interaction-handlers.js @@ -447,14 +447,14 @@ module.exports = { const statcastData = commandUtil.getStatcastData(text); if (statcastData.mostRecentStatcast && statcastData.mostRecentMetricYear && statcastData.metricSummaryJSON) { const batterInfo = await commandUtil.hydrateHitter(batter.id); - const attachment = new AttachmentBuilder(Buffer.from(batterInfo.spot), { name: 'spot.png' }); const savantAttachment = new AttachmentBuilder((await commandUtil.buildBatterSavantTable( statcastData.mostRecentStatcast, - statcastData.metricSummaryJSON[statcastData.mostRecentMetricYear.toString()])), { name: 'savant.png' }); + statcastData.metricSummaryJSON[statcastData.mostRecentMetricYear.toString()], + batterInfo.spot)), { name: 'savant.png' }); await interaction.followUp({ ephemeral: false, - files: [attachment, savantAttachment], - embeds: [commandUtil.getBatterEmbed(batter, batterInfo, !playerName)], + files: [savantAttachment], + embeds: [commandUtil.getBatterEmbed(batter, batterInfo, !playerName, null, true)], components: [], content: '' }); @@ -477,14 +477,14 @@ module.exports = { const statcastData = commandUtil.getStatcastData(text); if (statcastData.mostRecentStatcast && statcastData.mostRecentMetricYear && statcastData.metricSummaryJSON) { const pitcherInfo = await commandUtil.hydrateProbable(pitcher.id); - const attachment = new AttachmentBuilder(Buffer.from(pitcherInfo.spot), { name: 'spot.png' }); const savantAttachment = new AttachmentBuilder((await commandUtil.buildPitcherSavantTable( statcastData.mostRecentStatcast, - statcastData.metricSummaryJSON[statcastData.mostRecentMetricYear.toString()])), { name: 'savant.png' }); + statcastData.metricSummaryJSON[statcastData.mostRecentMetricYear.toString()], + pitcherInfo.spot)), { name: 'savant.png' }); await interaction.followUp({ ephemeral: false, - files: [attachment, savantAttachment], - embeds: [commandUtil.getPitcherEmbed(pitcher, pitcherInfo, !playerName)], + files: [savantAttachment], + embeds: [commandUtil.getPitcherEmbed(pitcher, pitcherInfo, !playerName, null, true)], components: [], content: '' });