Skip to content

Commit 2b69d2c

Browse files
committed
show next 3 batters in inning changes
Closes #28 Thanks to @AlecM33 for letting me know onDeck/inHole are things I can use!
1 parent f6b504c commit 2b69d2c

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

src/main/java/pw/chew/mlb/listeners/GameFeedHandler.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public static ActiveGame currentServerGame(@NotNull Guild server) {
192192
* @param gamePk The gamePk of the game to run.
193193
*/
194194
private static void runGame(String gamePk) {
195-
logger.debug("Starting game with gamePk: " + gamePk);
195+
logger.debug("Starting game with gamePk: {}", gamePk);
196196

197197
if (gamePk.isEmpty()) {
198198
return;
@@ -269,7 +269,7 @@ private static void runGame(String gamePk) {
269269

270270
// Check for new changes in the description
271271
if (recentState.atBatIndex() >= 0 && !recentState.currentPlayDescription().equals(currentState.currentPlayDescription())) {
272-
logger.debug("New play description for gamePk " + gamePk + ": " + recentState.currentPlayDescription());
272+
logger.debug("New play description for gamePk {}: {}", gamePk, recentState.currentPlayDescription());
273273

274274
boolean scoringPlay = recentState.home().runs() != currentState.home().runs() || recentState.away().runs() != currentState.away().runs();
275275
boolean hasOut = recentState.outs() != currentState.outs() && recentState.outs() > 0;
@@ -367,9 +367,21 @@ private static void runGame(String gamePk) {
367367
if (!currentState.inningState().equals(recentState.inningState())) {
368368
// Ignore if the state is "Middle" or "End"
369369
if (!recentState.inningState().equals("Middle") && !recentState.inningState().equals("End")) {
370+
String upToBat = """
371+
Next up: %s
372+
On deck: %s
373+
In the hole: %s
374+
"""
375+
.formatted(
376+
currentState.offenseBatter(), currentState.onDeck(), currentState.inTheHole()
377+
);
378+
370379
EmbedBuilder inningEmbed = new EmbedBuilder()
371380
.setTitle("Inning State Updated")
372-
.setDescription(recentState.inningState() + " of the " + recentState.inningOrdinal());
381+
.setDescription(
382+
recentState.inningState() + " of the " + recentState.inningOrdinal()
383+
+ "\n\n" + upToBat
384+
);
373385

374386
sendMessages(inningEmbed.build(), gamePk);
375387
}

src/main/java/pw/chew/mlb/objects/GameState.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public record GameState(JSONObject gameData, String gamePk) {
3030
*/
3131
@NotNull
3232
public static GameState fromPk(String gamePk) {
33-
String res = RestClient.get("https://statsapi.mlb.com/api/v1.1/game/:id/feed/live?language=en&fields=gameData,venue,fieldInfo,capacity,weather,condition,temp,wind,gameInfo,attendance,game,pk,datetime,dateTime,status,detailedState,abstractGameState,liveData,plays,allPlays,result,rbi,description,awayScore,homeScore,event,about,inning,isTopInning,isComplete,count,balls,strikes,outs,playEvents,details,isInPlay,isScoringPlay,eventType,hitData,launchSpeed,launchAngle,totalDistance,trajectory,hardness,isPitch,atBatIndex,playId,currentPlay,scoringPlays,matchup,batter,fullName,pitcher,postOnFirst,postOnSecond,postOnThird,linescore,currentInning,currentInningOrdinal,inningState,teams,home,name,clubName,abbreviation,runs,away,innings,num,hits,errors,leftOnBase,decisions,winner,id,loser,save,boxscore,players,stats,pitching,note"
33+
String res = RestClient.get("https://statsapi.mlb.com/api/v1.1/game/:id/feed/live?language=en&fields=gameData,venue,fieldInfo,capacity,weather,condition,temp,wind,gameInfo,attendance,game,pk,datetime,dateTime,status,detailedState,abstractGameState,liveData,plays,allPlays,result,rbi,description,awayScore,homeScore,event,about,inning,isTopInning,isComplete,count,balls,strikes,outs,playEvents,details,isInPlay,isScoringPlay,eventType,hitData,launchSpeed,launchAngle,totalDistance,trajectory,hardness,isPitch,atBatIndex,playId,currentPlay,scoringPlays,matchup,batter,fullName,pitcher,postOnFirst,postOnSecond,postOnThird,linescore,offense,onDeck,inHole,currentInning,currentInningOrdinal,inningState,teams,home,name,clubName,abbreviation,runs,away,innings,num,hits,errors,leftOnBase,decisions,winner,id,loser,save,boxscore,players,stats,pitching,note"
3434
.replace(":id", gamePk)).asString();
3535

3636
try {
@@ -241,6 +241,33 @@ public String currentBatter() {
241241
return currentPlay().getJSONObject("matchup").getJSONObject("batter").getString("fullName");
242242
}
243243

244+
/**
245+
* The next batter for the offense. Not necessarily the same as {@link #currentBatter()}.
246+
*
247+
* @return the next batter for the offense.
248+
*/
249+
public String offenseBatter() {
250+
return lineScore().getJSONObject("offense").getJSONObject("batter").getString("fullName");
251+
}
252+
253+
/**
254+
* The batter on deck (after the next batter) for the offense.
255+
*
256+
* @return the batter on deck for the offense.
257+
*/
258+
public String onDeck() {
259+
return lineScore().getJSONObject("offense").getJSONObject("onDeck").getString("fullName");
260+
}
261+
262+
/**
263+
* The batter in the hole (after the on deck batter) for the offense.
264+
*
265+
* @return the batter in the hole for the offense.
266+
*/
267+
public String inTheHole() {
268+
return lineScore().getJSONObject("offense").getJSONObject("inHole").getString("fullName");
269+
}
270+
244271
/**
245272
* Gets who is currently on a base. E.g., "1st: Mike Trout".
246273
* Can also be "No one is on base." if no one is on base.

0 commit comments

Comments
 (0)