This commit is contained in:
Lee 2024-06-26 11:11:13 +01:00
parent aec2fe1c2b
commit e7159ad514

@ -23,7 +23,6 @@ import org.springframework.stereotype.Component;
*/ */
@Component @Component
public class ScoreSaberFeature extends Feature { public class ScoreSaberFeature extends Feature {
@Autowired @Autowired
public ScoreSaberFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) { public ScoreSaberFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("ScoreSaber"); super("ScoreSaber");
@ -43,28 +42,39 @@ public class ScoreSaberFeature extends Feature {
ScoreSaberScoreToken scoreToken = score.getScore(); ScoreSaberScoreToken scoreToken = score.getScore();
ScoreSaberLeaderboardToken leaderboardToken = score.getLeaderboard(); ScoreSaberLeaderboardToken leaderboardToken = score.getLeaderboard();
ScoreSaberScoreToken.LeaderboardPlayerInfo playerInfo = scoreToken.getLeaderboardPlayerInfo(); ScoreSaberScoreToken.LeaderboardPlayerInfo playerInfo = scoreToken.getLeaderboardPlayerInfo();
String thumbnailUrl = String.format("https://cdn.scoresaber.com/covers/%s.png", leaderboardToken.getSongHash());
String authorUrl = String.format("https://scoresaber.com/u/%s", playerInfo.getId());
String description = String.format("**%s** (%s%s)\n[[Map Link]](%s) [[SS Profile]](%s)",
leaderboardToken.getSongName(),
ScoreSaberUtils.getFormattedDifficulty(leaderboardToken.getDifficulty().getDifficulty()),
leaderboardToken.isRanked() ? " " + leaderboardToken.getStars() + "" : "",
String.format("https://scoresaber.com/leaderboard/%s", leaderboardToken.getId()),
authorUrl
);
String accuracy = leaderboardToken.getMaxScore() == 0 ? "N/A" :
String.format("%s%%", NumberUtils.formatNumberCommas(((double) scoreToken.getBaseScore() / leaderboardToken.getMaxScore()) * 100));
String rawPp = scoreToken.getPp() == 0 ? "Unranked" : NumberUtils.formatNumberCommas(scoreToken.getPp());
String rank = String.format("#%s", NumberUtils.formatNumberCommas(scoreToken.getRank()));
String misses = String.format("%s", scoreToken.getMissedNotes());
String badCuts = String.format("%s", scoreToken.getBadCuts());
String maxCombo = String.format("%s %s",
scoreToken.getMaxCombo(),
scoreToken.getMaxCombo() == leaderboardToken.getMaxScore() ? "(FC)" : ""
);
return EmbedUtils.genericEmbed() return EmbedUtils.genericEmbed()
.setThumbnail("https://cdn.scoresaber.com/covers/%s.png".formatted(leaderboardToken.getSongHash())) .setThumbnail(thumbnailUrl)
.setAuthor(playerInfo.getName() + " just set a new score!", "https://scoresaber.com/u/%s".formatted(playerInfo.getId()), .setAuthor(playerInfo.getName() + " just set a new score!", authorUrl, playerInfo.getProfilePicture())
"https://cdn.scoresaber.com/avatars/%s.jpg".formatted(playerInfo.getId())) .setDescription(description)
.setDescription("**%s** (%s%s)\n[[Map Link]](%s) [[SS Profile]](%s)".formatted( .addField("Accuracy", accuracy, true)
leaderboardToken.getSongName(), .addField("Raw PP", rawPp, true)
ScoreSaberUtils.getFormattedDifficulty(leaderboardToken.getDifficulty().getDifficulty()), .addField("Rank", rank, true)
leaderboardToken.isRanked() ? " " + leaderboardToken.getStars() + "" : "", .addField("Misses", misses, true)
"https://scoresaber.com/leaderboard/%s".formatted(leaderboardToken.getId()), .addField("Bad Cuts", badCuts, true)
"https://scoresaber.com/u/%s".formatted(playerInfo.getId()) .addField("Max Combo", maxCombo, true)
))
.addField("Accuracy", "%s%%".formatted(
leaderboardToken.getMaxScore() == 0 ? "N/A" : NumberUtils.formatNumberCommas(((double) scoreToken.getBaseScore() / leaderboardToken.getMaxScore()) * 100)
), true)
.addField("Raw PP", scoreToken.getPp() == 0 ? "Unranked" : NumberUtils.formatNumberCommas(scoreToken.getPp()), true)
.addField("Rank", "#%s".formatted(NumberUtils.formatNumberCommas(scoreToken.getRank())), true)
.addField("Misses", "%s".formatted(scoreToken.getMissedNotes()), true)
.addField("Bad Cuts", "%s".formatted(scoreToken.getBadCuts()), true)
.addField("Max Combo", "%s %s".formatted(
scoreToken.getMaxCombo(),
scoreToken.getMaxCombo() == leaderboardToken.getMaxScore() ? "(FC)" : ""
), true)
.setTimestamp(DateUtils.getDateFromString(scoreToken.getTimeSet()).toInstant()) .setTimestamp(DateUtils.getDateFromString(scoreToken.getTimeSet()).toInstant())
.build(); .build();
} }