add fetch time for scoresaber me and user command
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 39s

This commit is contained in:
Lee 2024-06-27 13:33:38 +01:00
parent 001ece7899
commit ecd688310f

View File

@ -48,9 +48,9 @@ public class ScoreSaberCommand extends BatCommand {
/**
* Builds the profile embed for the ScoreSaber profile
*
* @param user The user to build the profile embed for
* @param user The user to build the profile embed for
* @param scoreSaberService The ScoreSaber service
* @param interaction The interaction
* @param interaction The interaction
*/
public static void sendProfileEmbed(boolean isSelf, BatUser user, ScoreSaberService scoreSaberService, SlashCommandInteraction interaction) {
UserScoreSaberProfile profile = user.getProfile(UserScoreSaberProfile.class);
@ -67,6 +67,7 @@ public class ScoreSaberCommand extends BatCommand {
}
try {
long before = System.currentTimeMillis();
ScoreSaberAccountToken account = scoreSaberService.getAccount(profile.getSteamId());
if (account == null) {
if (!isSelf) {
@ -81,6 +82,7 @@ public class ScoreSaberCommand extends BatCommand {
return;
}
long fetchTime = System.currentTimeMillis() - before;
interaction.replyEmbeds(new EmbedBuilder()
.setAuthor(account.getName() + "'s Profile", "https://scoresaber.com/u/%s".formatted(account.getId()),
"https://cdn.scoresaber.com/avatars/%s.jpg".formatted(account.getId()))
@ -89,8 +91,9 @@ public class ScoreSaberCommand extends BatCommand {
.addField("Rank", "#" + NumberUtils.formatNumberCommas(account.getRank()), true)
.addField("Country Rank", "#" + NumberUtils.formatNumberCommas(account.getCountryRank()), true)
.addField("PP", NumberUtils.formatNumberCommas(account.getPp()), true)
.addField("Joined", "<t:%s>".formatted(DateUtils.getDateFromString(account.getFirstSeen()).toInstant().toEpochMilli()/1000), true)
.addField("Joined", "<t:%s>".formatted(DateUtils.getDateFromString(account.getFirstSeen()).toInstant().toEpochMilli() / 1000), true)
.setTimestamp(LocalDateTime.now())
.setFooter(fetchTime > 3 ? "Fetched in %sms".formatted(fetchTime) : "Cached", null)
.setColor(Colors.DEFAULT)
.build()).queue();
} catch (RateLimitException ex) {