Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for profiles that don't have data for all ratings in chess.com #65

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() : "?";
}
}
Loading