From c78033f4094fa0cf7b721451038502eeec8ad4a8 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 4 Jul 2024 15:44:05 +0100 Subject: [PATCH] fix cached footer --- .../command/scoresaber/ScoreSaberCommand.java | 3 ++- .../cc/fascinated/bat/service/ScoreSaberService.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/cc/fascinated/bat/features/scoresaber/command/scoresaber/ScoreSaberCommand.java b/src/main/java/cc/fascinated/bat/features/scoresaber/command/scoresaber/ScoreSaberCommand.java index 97fcfb2..0dfe47e 100644 --- a/src/main/java/cc/fascinated/bat/features/scoresaber/command/scoresaber/ScoreSaberCommand.java +++ b/src/main/java/cc/fascinated/bat/features/scoresaber/command/scoresaber/ScoreSaberCommand.java @@ -67,6 +67,7 @@ public class ScoreSaberCommand extends BatCommand { try { long before = System.currentTimeMillis(); + boolean cached = scoreSaberService.isCached(profile.getAccountId()); ScoreSaberAccountToken account = scoreSaberService.getAccount(profile.getAccountId()); if (account == null) { if (!isSelf) { @@ -96,7 +97,7 @@ public class ScoreSaberCommand extends BatCommand { .addField("PP", NumberFormatter.formatCommas(account.getPp()), true) .addField("Joined", "".formatted(DateUtils.getDateFromString(account.getFirstSeen()).toInstant().getEpochSecond()), true) .setTimestamp(LocalDateTime.now()) - .setFooter(fetchTime > 3 ? "Fetched in %sms".formatted(fetchTime) : "Cached", "https://flagcdn.com/h120/%s.png".formatted(account.getCountry().toLowerCase())) + .setFooter(!cached ? "Fetched in %sms".formatted(fetchTime) : "Cached", "https://flagcdn.com/h120/%s.png".formatted(account.getCountry().toLowerCase())) .setColor(Colors.DEFAULT) .build()).queue(); } catch (RateLimitException ex) { diff --git a/src/main/java/cc/fascinated/bat/service/ScoreSaberService.java b/src/main/java/cc/fascinated/bat/service/ScoreSaberService.java index 1dd8d4f..c9b2b92 100644 --- a/src/main/java/cc/fascinated/bat/service/ScoreSaberService.java +++ b/src/main/java/cc/fascinated/bat/service/ScoreSaberService.java @@ -46,6 +46,16 @@ public class ScoreSaberService extends TextWebSocketHandler { connectWebSocket(); } + /** + * Checks if the account is cached. + * + * @param id The id of the account. + * @return If the account is cached. + */ + public boolean isCached(String id) { + return cachedAccounts.containsKey(id); + } + /** * Gets the account from the ScoreSaber API. *