add rate limit check for scoresaber api
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 36s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 36s
This commit is contained in:
parent
b50e30ffc5
commit
4a7e7de6a2
@ -5,6 +5,7 @@ import cc.fascinated.bat.common.Colors;
|
||||
import cc.fascinated.bat.common.DateUtils;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.NumberUtils;
|
||||
import cc.fascinated.bat.exception.RateLimitException;
|
||||
import cc.fascinated.bat.features.scoresaber.profile.UserScoreSaberProfile;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
@ -65,32 +66,37 @@ public class ScoreSaberCommand extends BatCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
// todo: handle rate limits
|
||||
ScoreSaberAccountToken account = scoreSaberService.getAccount(profile.getSteamId());
|
||||
if (account == null) {
|
||||
if (!isSelf) {
|
||||
try {
|
||||
ScoreSaberAccountToken account = scoreSaberService.getAccount(profile.getSteamId());
|
||||
if (account == null) {
|
||||
if (!isSelf) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("%s has an invalid ScoreSaber account linked, please ask them to re-link their account"
|
||||
.formatted(user.getDiscordUser().getAsMention()))
|
||||
.build()).queue();
|
||||
}
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("%s has an invalid ScoreSaber account linked, please ask them to re-link their account"
|
||||
.formatted(user.getDiscordUser().getAsMention()))
|
||||
.setDescription("You have an invalid ScoreSaber account linked, please re-link your account")
|
||||
.build()).queue();
|
||||
return;
|
||||
}
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("You have an invalid ScoreSaber account linked, please re-link your account")
|
||||
.build()).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
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()))
|
||||
.addField("Name", account.getName(), true)
|
||||
.addField("Country", account.getCountry(), true)
|
||||
.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)
|
||||
.setTimestamp(LocalDateTime.now())
|
||||
.setColor(Colors.DEFAULT)
|
||||
.build()).queue();
|
||||
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()))
|
||||
.addField("Name", account.getName(), true)
|
||||
.addField("Country", account.getCountry(), true)
|
||||
.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)
|
||||
.setTimestamp(LocalDateTime.now())
|
||||
.setColor(Colors.DEFAULT)
|
||||
.build()).queue();
|
||||
} catch (RateLimitException ex) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("The ScoreSaber API is currently rate our limiting requests, please try again later")
|
||||
.build()).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user