Skip to content

Commit

Permalink
bump to 2024 season
Browse files Browse the repository at this point in the history
  • Loading branch information
Chew committed Feb 4, 2024
1 parent 102ed7e commit 49a30da
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/main/java/pw/chew/mlb/MLBBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class MLBBot {
public static final List<JSONObject> TEAMS = new ArrayList<>();
public static final EventWaiter waiter = new EventWaiter();

public static final int SEASON = 2024;

public static void main(String[] args) throws IOException {
// Load properties into the PropertiesManager
Properties prop = new Properties();
Expand Down Expand Up @@ -78,7 +80,7 @@ public static void main(String[] args) throws IOException {
RestClient.setClient(jda.getHttpClient());

// Load teams
JSONObject teams = new JSONObject(RestClient.get("https://statsapi.mlb.com/api/v1/teams?sportIds=1&season=2023"));
JSONObject teams = new JSONObject(RestClient.get("https://statsapi.mlb.com/api/v1/teams?sportIds=1&season=" + SEASON));

for (int i = 0; i < teams.getJSONArray("teams").length(); i++) {
TEAMS.add(teams.getJSONArray("teams").getJSONObject(i));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/pw/chew/mlb/commands/PlanGameCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.List;
import java.util.Map;

import static pw.chew.mlb.MLBBot.SEASON;

public class PlanGameCommand extends SlashCommand {
public PlanGameCommand() {
this.name = "plangame";
Expand Down Expand Up @@ -203,7 +205,7 @@ public void onAutoComplete(CommandAutoCompleteInteractionEvent event) {
return;
}

JSONArray games = new JSONObject(RestClient.get("https://statsapi.mlb.com/api/v1/schedule?lang=en&sportId=%S&season=2023&teamId=%S&fields=dates,date,games,gamePk,teams,away,team,teamName,id&hydrate=team".formatted(sport, teamId)))
JSONArray games = new JSONObject(RestClient.get("https://statsapi.mlb.com/api/v1/schedule?lang=en&sportId=%S&season=%s&teamId=%S&fields=dates,date,games,gamePk,teams,away,team,teamName,id&hydrate=team".formatted(sport, SEASON, teamId)))
.getJSONArray("dates");

List<Command.Choice> choices = new ArrayList<>();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/pw/chew/mlb/commands/SetInfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Map;

import static pw.chew.mlb.MLBBot.SEASON;
import static pw.chew.mlb.MLBBot.TEAMS;

public class SetInfoCommand extends SlashCommand {
Expand Down Expand Up @@ -87,7 +88,7 @@ protected void execute(SlashCommandEvent event) {
divisionAbbreviation += word.substring(0, 1);
}

JSONObject standings = new JSONObject(RestClient.get("https://statsapi.mlb.com/api/v1/standings?leagueId=103,104&season=2023&standingsTypes=regularSeason"));
JSONObject standings = new JSONObject(RestClient.get("https://statsapi.mlb.com/api/v1/standings?leagueId=103,104&standingsTypes=regularSeason&season=" + SEASON));

// Gotta find the team now...
JSONArray records = standings.getJSONArray("records");
Expand Down Expand Up @@ -122,7 +123,7 @@ protected void execute(SlashCommandEvent event) {
case "nextgame" -> {
int teamId = teamInfo.getInt("id");

JSONObject teamSchedule = new JSONObject(RestClient.get(String.format("https://statsapi.mlb.com/api/v1/teams/%s?season=2023&hydrate=nextSchedule", teamId)));
JSONObject teamSchedule = new JSONObject(RestClient.get(String.format("https://statsapi.mlb.com/api/v1/teams/%s?season=%s&hydrate=nextSchedule", teamId, SEASON)));

JSONObject nextGame = null;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/pw/chew/mlb/objects/MLBAPIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.Map;

import static pw.chew.mlb.MLBBot.SEASON;
import static pw.chew.mlb.MLBBot.TEAMS;

public class MLBAPIUtil {
Expand Down Expand Up @@ -42,7 +43,7 @@ public static Teams getTeams(String sportId) {
if (teamsCache.getIfPresent(sportId) != null) {
return teamsCache.getIfPresent(sportId);
}
Teams teams = new Teams(new JSONObject(RestClient.get("https://statsapi.mlb.com/api/v1/teams?sportIds=%s&season=2023".formatted(sportId))).getJSONArray("teams"));
Teams teams = new Teams(new JSONObject(RestClient.get("https://statsapi.mlb.com/api/v1/teams?sportIds=%s&season=%s".formatted(sportId, SEASON))).getJSONArray("teams"));
teamsCache.put(sportId, teams);
return teams;
}
Expand Down

0 comments on commit 49a30da

Please sign in to comment.