Skip to content

Commit

Permalink
Merge pull request #65 from cnunezre/bug/64-profileCC-breaks-when-the…
Browse files Browse the repository at this point in the history
…re-is-no-rating-for-a-user-in-a-specific-chess-category-like-bullet

Adding support for profiles that don't have data for all ratings in chess.com
  • Loading branch information
jalpp authored Jun 20, 2024
2 parents e7b9595 + beb75ed commit 4cf2bb9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/main/java/Chesscom/CCProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Abstraction.Player.UserObject;
import io.github.sornerol.chess.pubapi.domain.player.stats.PlayerStats;
import io.github.sornerol.chess.pubapi.domain.player.stats.PuzzleRushStats;
import io.github.sornerol.chess.pubapi.domain.player.stats.RatingPoolStats;
import io.github.sornerol.chess.pubapi.exception.ChessComPubApiException;
import net.dv8tion.jda.api.EmbedBuilder;

Expand All @@ -24,13 +26,13 @@ public EmbedBuilder getCCProfile() {
PlayerStats player = this.getChessComStats();

proSay += "**Bullet**: " +
player.getChessBullet().getLast().getRating() +
getRatingOrDefault(player.getChessBullet()) +
"\n **Rapid:** " +
player.getChessRapid().getLast().getRating() +
getRatingOrDefault(player.getChessRapid()) +
"\n **Blitz:** " +
player.getChessBlitz().getLast().getRating() +
getRatingOrDefault(player.getChessBlitz()) +
"\n **PuzzleRush:** " +
player.getPuzzleRush().getBest().getScore();
getStatsOrDefault(player.getPuzzleRush());
embedBuilder.setThumbnail(this.getPlayerClient().getPlayerByUsername(getUserID()).getAvatarUrl()).setTitle(this.getUserID() + "'s Chess.com Profile").setDescription(proSay).setColor(Color.green);

} catch (IOException e) {
Expand All @@ -40,8 +42,13 @@ public EmbedBuilder getCCProfile() {
}

return embedBuilder;

}

private String getRatingOrDefault(RatingPoolStats rating) {
return rating != null ? rating.getLast().getRating().toString() : "?";
}

private String getStatsOrDefault(PuzzleRushStats stats) {
return stats != null ? stats.getBest().getScore().toString() : "?";
}
}

0 comments on commit 4cf2bb9

Please sign in to comment.