add rate limit check for scoresaber api

This commit is contained in:
Lee 2024-06-27 13:13:37 +01:00
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.DateUtils;
import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.NumberUtils; import cc.fascinated.bat.common.NumberUtils;
import cc.fascinated.bat.exception.RateLimitException;
import cc.fascinated.bat.features.scoresaber.profile.UserScoreSaberProfile; import cc.fascinated.bat.features.scoresaber.profile.UserScoreSaberProfile;
import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser; import cc.fascinated.bat.model.BatUser;
@ -65,7 +66,7 @@ public class ScoreSaberCommand extends BatCommand {
return; return;
} }
// todo: handle rate limits try {
ScoreSaberAccountToken account = scoreSaberService.getAccount(profile.getSteamId()); ScoreSaberAccountToken account = scoreSaberService.getAccount(profile.getSteamId());
if (account == null) { if (account == null) {
if (!isSelf) { if (!isSelf) {
@ -92,5 +93,10 @@ public class ScoreSaberCommand extends BatCommand {
.setTimestamp(LocalDateTime.now()) .setTimestamp(LocalDateTime.now())
.setColor(Colors.DEFAULT) .setColor(Colors.DEFAULT)
.build()).queue(); .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();
}
} }
} }