From f4439338f91845cb05580de4b6cb04474c2dc709 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 25 Jun 2024 18:53:09 +0100 Subject: [PATCH] cleanup score embed and add thumbnail of the song art --- .../NumberOneScoreFeedListener.java | 37 +--------------- .../scoresaber/ScoreSaberFeature.java | 44 +++++++++++++++++++ .../scoresaber/UserScoreFeedListener.java | 37 +--------------- 3 files changed, 46 insertions(+), 72 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/features/scoresaber/NumberOneScoreFeedListener.java b/src/main/java/cc/fascinated/bat/features/scoresaber/NumberOneScoreFeedListener.java index a150cc2..0d70dd4 100644 --- a/src/main/java/cc/fascinated/bat/features/scoresaber/NumberOneScoreFeedListener.java +++ b/src/main/java/cc/fascinated/bat/features/scoresaber/NumberOneScoreFeedListener.java @@ -64,42 +64,7 @@ public class NumberOneScoreFeedListener implements EventListener { guildService.saveGuild(batGuild); continue; } - channel.sendMessageEmbeds(this.buildScoreEmbed(score)).queue(); + channel.sendMessageEmbeds(ScoreSaberFeature.buildScoreEmbed(score)).queue(); } } - - /** - * Builds an embed for a score. - * - * @param score The score. - * @return The embed. - */ - public MessageEmbed buildScoreEmbed(ScoreSaberPlayerScoreToken score) { - ScoreSaberScoreToken scoreToken = score.getScore(); - ScoreSaberLeaderboardToken leaderboardToken = score.getLeaderboard(); - ScoreSaberScoreToken.LeaderboardPlayerInfo playerInfo = scoreToken.getLeaderboardPlayerInfo(); - return EmbedUtils.genericEmbed() - .setAuthor(playerInfo.getName() + " just set a new #1!", "https://scoresaber.com/u/%s".formatted(playerInfo.getId()), - "https://cdn.scoresaber.com/avatars/%s.jpg".formatted(playerInfo.getId())) - .setDescription("**%s** (%s%s)\n[[Map Link]](%s) [[SS Profile]](%s)".formatted( - leaderboardToken.getSongName(), - ScoreSaberUtils.getFormattedDifficulty(leaderboardToken.getDifficulty().getDifficulty()), - leaderboardToken.isRanked() ? " " + leaderboardToken.getStars() + "⭐" : "", - "https://scoresaber.com/leaderboard/%s".formatted(leaderboardToken.getId()), - "https://scoresaber.com/u/%s".formatted(playerInfo.getId()) - )) - .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()) - .build(); - } } diff --git a/src/main/java/cc/fascinated/bat/features/scoresaber/ScoreSaberFeature.java b/src/main/java/cc/fascinated/bat/features/scoresaber/ScoreSaberFeature.java index d005c55..fc38479 100644 --- a/src/main/java/cc/fascinated/bat/features/scoresaber/ScoreSaberFeature.java +++ b/src/main/java/cc/fascinated/bat/features/scoresaber/ScoreSaberFeature.java @@ -1,11 +1,19 @@ package cc.fascinated.bat.features.scoresaber; +import cc.fascinated.bat.common.DateUtils; +import cc.fascinated.bat.common.EmbedUtils; +import cc.fascinated.bat.common.NumberUtils; +import cc.fascinated.bat.common.ScoreSaberUtils; import cc.fascinated.bat.features.Feature; import cc.fascinated.bat.features.scoresaber.command.numberone.NumberOneFeedCommand; import cc.fascinated.bat.features.scoresaber.command.scoresaber.ScoreSaberCommand; import cc.fascinated.bat.features.scoresaber.command.userfeed.UserFeedCommand; +import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberLeaderboardToken; +import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberPlayerScoreToken; +import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberScoreToken; import cc.fascinated.bat.service.CommandService; import lombok.NonNull; +import net.dv8tion.jda.api.entities.MessageEmbed; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; @@ -24,4 +32,40 @@ public class ScoreSaberFeature extends Feature { commandService.registerCommand(context.getBean(UserFeedCommand.class)); commandService.registerCommand(context.getBean(NumberOneFeedCommand.class)); } + + /** + * Builds an embed for a score. + * + * @param score The score. + * @return The embed. + */ + public static MessageEmbed buildScoreEmbed(ScoreSaberPlayerScoreToken score) { + ScoreSaberScoreToken scoreToken = score.getScore(); + ScoreSaberLeaderboardToken leaderboardToken = score.getLeaderboard(); + ScoreSaberScoreToken.LeaderboardPlayerInfo playerInfo = scoreToken.getLeaderboardPlayerInfo(); + return EmbedUtils.genericEmbed() + .setThumbnail("https://cdn.scoresaber.com/covers/%s.png".formatted(leaderboardToken.getSongHash())) + .setAuthor(playerInfo.getName() + " just set a new score!", "https://scoresaber.com/u/%s".formatted(playerInfo.getId()), + "https://cdn.scoresaber.com/avatars/%s.jpg".formatted(playerInfo.getId())) + .setDescription("**%s** (%s%s)\n[[Map Link]](%s) [[SS Profile]](%s)".formatted( + leaderboardToken.getSongName(), + ScoreSaberUtils.getFormattedDifficulty(leaderboardToken.getDifficulty().getDifficulty()), + leaderboardToken.isRanked() ? " " + leaderboardToken.getStars() + "⭐" : "", + "https://scoresaber.com/leaderboard/%s".formatted(leaderboardToken.getId()), + "https://scoresaber.com/u/%s".formatted(playerInfo.getId()) + )) + .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()) + .build(); + } } diff --git a/src/main/java/cc/fascinated/bat/features/scoresaber/UserScoreFeedListener.java b/src/main/java/cc/fascinated/bat/features/scoresaber/UserScoreFeedListener.java index 738ded1..2b51518 100644 --- a/src/main/java/cc/fascinated/bat/features/scoresaber/UserScoreFeedListener.java +++ b/src/main/java/cc/fascinated/bat/features/scoresaber/UserScoreFeedListener.java @@ -52,42 +52,7 @@ public class UserScoreFeedListener implements EventListener { guildService.saveGuild(batGuild); continue; } - channel.sendMessageEmbeds(this.buildScoreEmbed(score)).queue(); + channel.sendMessageEmbeds(ScoreSaberFeature.buildScoreEmbed(score)).queue(); } } - - /** - * Builds an embed for a score. - * - * @param score The score. - * @return The embed. - */ - public MessageEmbed buildScoreEmbed(ScoreSaberPlayerScoreToken score) { - ScoreSaberScoreToken scoreToken = score.getScore(); - ScoreSaberLeaderboardToken leaderboardToken = score.getLeaderboard(); - ScoreSaberScoreToken.LeaderboardPlayerInfo playerInfo = scoreToken.getLeaderboardPlayerInfo(); - return EmbedUtils.genericEmbed() - .setAuthor(playerInfo.getName() + " just set a new score!", "https://scoresaber.com/u/%s".formatted(playerInfo.getId()), - "https://cdn.scoresaber.com/avatars/%s.jpg".formatted(playerInfo.getId())) - .setDescription("**%s** (%s%s)\n[[Map Link]](%s) [[SS Profile]](%s)".formatted( - leaderboardToken.getSongName(), - ScoreSaberUtils.getFormattedDifficulty(leaderboardToken.getDifficulty().getDifficulty()), - leaderboardToken.isRanked() ? " " + leaderboardToken.getStars() + "⭐" : "", - "https://scoresaber.com/leaderboard/%s".formatted(leaderboardToken.getId()), - "https://scoresaber.com/u/%s".formatted(playerInfo.getId()) - )) - .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()) - .build(); - } }