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();
return EmbedUtils.genericEmbed()
.setThumbnail("https://cdn.scoresaber.com/covers/%s.png".formatted(leaderboardToken.getSongHash())) String thumbnailUrl = String.format("https://cdn.scoresaber.com/covers/%s.png", leaderboardToken.getSongHash());
.setAuthor(playerInfo.getName() + " just set a new score!", "https://scoresaber.com/u/%s".formatted(playerInfo.getId()), String authorUrl = String.format("https://scoresaber.com/u/%s", playerInfo.getId());
"https://cdn.scoresaber.com/avatars/%s.jpg".formatted(playerInfo.getId())) String description = String.format("**%s** (%s%s)\n[[Map Link]](%s) [[SS Profile]](%s)",
.setDescription("**%s** (%s%s)\n[[Map Link]](%s) [[SS Profile]](%s)".formatted(
leaderboardToken.getSongName(), leaderboardToken.getSongName(),
ScoreSaberUtils.getFormattedDifficulty(leaderboardToken.getDifficulty().getDifficulty()), ScoreSaberUtils.getFormattedDifficulty(leaderboardToken.getDifficulty().getDifficulty()),
leaderboardToken.isRanked() ? " " + leaderboardToken.getStars() + "" : "", leaderboardToken.isRanked() ? " " + leaderboardToken.getStars() + "" : "",
"https://scoresaber.com/leaderboard/%s".formatted(leaderboardToken.getId()), String.format("https://scoresaber.com/leaderboard/%s", leaderboardToken.getId()),
"https://scoresaber.com/u/%s".formatted(playerInfo.getId()) authorUrl
)) );
.addField("Accuracy", "%s%%".formatted(
leaderboardToken.getMaxScore() == 0 ? "N/A" : NumberUtils.formatNumberCommas(((double) scoreToken.getBaseScore() / leaderboardToken.getMaxScore()) * 100) String accuracy = leaderboardToken.getMaxScore() == 0 ? "N/A" :
), true) String.format("%s%%", NumberUtils.formatNumberCommas(((double) scoreToken.getBaseScore() / leaderboardToken.getMaxScore()) * 100));
.addField("Raw PP", scoreToken.getPp() == 0 ? "Unranked" : NumberUtils.formatNumberCommas(scoreToken.getPp()), true)
.addField("Rank", "#%s".formatted(NumberUtils.formatNumberCommas(scoreToken.getRank())), true) String rawPp = scoreToken.getPp() == 0 ? "Unranked" : NumberUtils.formatNumberCommas(scoreToken.getPp());
.addField("Misses", "%s".formatted(scoreToken.getMissedNotes()), true) String rank = String.format("#%s", NumberUtils.formatNumberCommas(scoreToken.getRank()));
.addField("Bad Cuts", "%s".formatted(scoreToken.getBadCuts()), true) String misses = String.format("%s", scoreToken.getMissedNotes());
.addField("Max Combo", "%s %s".formatted( String badCuts = String.format("%s", scoreToken.getBadCuts());
String maxCombo = String.format("%s %s",
scoreToken.getMaxCombo(), scoreToken.getMaxCombo(),
scoreToken.getMaxCombo() == leaderboardToken.getMaxScore() ? "(FC)" : "" scoreToken.getMaxCombo() == leaderboardToken.getMaxScore() ? "(FC)" : ""
), true) );
return EmbedUtils.genericEmbed()
.setThumbnail(thumbnailUrl)
.setAuthor(playerInfo.getName() + " just set a new score!", authorUrl, playerInfo.getProfilePicture())
.setDescription(description)
.addField("Accuracy", accuracy, true)
.addField("Raw PP", rawPp, true)
.addField("Rank", rank, true)
.addField("Misses", misses, true)
.addField("Bad Cuts", badCuts, true)
.addField("Max Combo", maxCombo, true)
.setTimestamp(DateUtils.getDateFromString(scoreToken.getTimeSet()).toInstant()) .setTimestamp(DateUtils.getDateFromString(scoreToken.getTimeSet()).toInstant())
.build(); .build();
} }