From d2d898a5b84701c878d73a9356381e4f83bd3c37 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 29 Jun 2024 13:08:13 +0100 Subject: [PATCH] disable spotify linking (until they accept out application) --- .../impl/{ => general}/BotStatsCommand.java | 2 +- .../impl/{ => general}/HelpCommand.java | 2 +- .../impl/{ => general}/InviteCommand.java | 2 +- .../impl/{ => general}/PingCommand.java | 2 +- .../{ => general}/avatar/AvatarCommand.java | 2 +- .../{ => general}/avatar/GuildSubCommand.java | 2 +- .../{ => general}/avatar/UserSubCommand.java | 2 +- .../{ => general}/banner/BannerCommand.java | 2 +- .../{ => general}/banner/GuildSubCommand.java | 2 +- .../{ => general}/banner/UserSubCommand.java | 2 +- .../bat/controller/SpotifyController.java | 2 +- .../bat/exception/RateLimitException.java | 1 - .../spotify/SpotifyForbiddenException.java | 13 ++++++++ .../spotify/command/LinkSubCommand.java | 33 ++++++++++--------- .../bat/service/SpotifyService.java | 18 +++++++--- 15 files changed, 55 insertions(+), 32 deletions(-) rename src/main/java/cc/fascinated/bat/command/impl/{ => general}/BotStatsCommand.java (98%) rename src/main/java/cc/fascinated/bat/command/impl/{ => general}/HelpCommand.java (99%) rename src/main/java/cc/fascinated/bat/command/impl/{ => general}/InviteCommand.java (96%) rename src/main/java/cc/fascinated/bat/command/impl/{ => general}/PingCommand.java (96%) rename src/main/java/cc/fascinated/bat/command/impl/{ => general}/avatar/AvatarCommand.java (92%) rename src/main/java/cc/fascinated/bat/command/impl/{ => general}/avatar/GuildSubCommand.java (96%) rename src/main/java/cc/fascinated/bat/command/impl/{ => general}/avatar/UserSubCommand.java (97%) rename src/main/java/cc/fascinated/bat/command/impl/{ => general}/banner/BannerCommand.java (92%) rename src/main/java/cc/fascinated/bat/command/impl/{ => general}/banner/GuildSubCommand.java (96%) rename src/main/java/cc/fascinated/bat/command/impl/{ => general}/banner/UserSubCommand.java (97%) create mode 100644 src/main/java/cc/fascinated/bat/exception/spotify/SpotifyForbiddenException.java diff --git a/src/main/java/cc/fascinated/bat/command/impl/BotStatsCommand.java b/src/main/java/cc/fascinated/bat/command/impl/general/BotStatsCommand.java similarity index 98% rename from src/main/java/cc/fascinated/bat/command/impl/BotStatsCommand.java rename to src/main/java/cc/fascinated/bat/command/impl/general/BotStatsCommand.java index 360e970..ef5652b 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/BotStatsCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/general/BotStatsCommand.java @@ -1,4 +1,4 @@ -package cc.fascinated.bat.command.impl; +package cc.fascinated.bat.command.impl.general; import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; diff --git a/src/main/java/cc/fascinated/bat/command/impl/HelpCommand.java b/src/main/java/cc/fascinated/bat/command/impl/general/HelpCommand.java similarity index 99% rename from src/main/java/cc/fascinated/bat/command/impl/HelpCommand.java rename to src/main/java/cc/fascinated/bat/command/impl/general/HelpCommand.java index 28d68bc..7408eaa 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/HelpCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/general/HelpCommand.java @@ -1,4 +1,4 @@ -package cc.fascinated.bat.command.impl; +package cc.fascinated.bat.command.impl.general; import cc.fascinated.bat.Consts; import cc.fascinated.bat.command.BatCommand; diff --git a/src/main/java/cc/fascinated/bat/command/impl/InviteCommand.java b/src/main/java/cc/fascinated/bat/command/impl/general/InviteCommand.java similarity index 96% rename from src/main/java/cc/fascinated/bat/command/impl/InviteCommand.java rename to src/main/java/cc/fascinated/bat/command/impl/general/InviteCommand.java index d9c42aa..7ce205f 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/InviteCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/general/InviteCommand.java @@ -1,4 +1,4 @@ -package cc.fascinated.bat.command.impl; +package cc.fascinated.bat.command.impl.general; import cc.fascinated.bat.Consts; import cc.fascinated.bat.command.BatCommand; diff --git a/src/main/java/cc/fascinated/bat/command/impl/PingCommand.java b/src/main/java/cc/fascinated/bat/command/impl/general/PingCommand.java similarity index 96% rename from src/main/java/cc/fascinated/bat/command/impl/PingCommand.java rename to src/main/java/cc/fascinated/bat/command/impl/general/PingCommand.java index b513a4d..f2272d7 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/PingCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/general/PingCommand.java @@ -1,4 +1,4 @@ -package cc.fascinated.bat.command.impl; +package cc.fascinated.bat.command.impl.general; import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; diff --git a/src/main/java/cc/fascinated/bat/command/impl/avatar/AvatarCommand.java b/src/main/java/cc/fascinated/bat/command/impl/general/avatar/AvatarCommand.java similarity index 92% rename from src/main/java/cc/fascinated/bat/command/impl/avatar/AvatarCommand.java rename to src/main/java/cc/fascinated/bat/command/impl/general/avatar/AvatarCommand.java index 2349311..b606a91 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/avatar/AvatarCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/general/avatar/AvatarCommand.java @@ -1,4 +1,4 @@ -package cc.fascinated.bat.command.impl.avatar; +package cc.fascinated.bat.command.impl.general.avatar; import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; diff --git a/src/main/java/cc/fascinated/bat/command/impl/avatar/GuildSubCommand.java b/src/main/java/cc/fascinated/bat/command/impl/general/avatar/GuildSubCommand.java similarity index 96% rename from src/main/java/cc/fascinated/bat/command/impl/avatar/GuildSubCommand.java rename to src/main/java/cc/fascinated/bat/command/impl/general/avatar/GuildSubCommand.java index dced8db..82590d8 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/avatar/GuildSubCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/general/avatar/GuildSubCommand.java @@ -1,4 +1,4 @@ -package cc.fascinated.bat.command.impl.avatar; +package cc.fascinated.bat.command.impl.general.avatar; import cc.fascinated.bat.command.BatSubCommand; import cc.fascinated.bat.command.CommandInfo; diff --git a/src/main/java/cc/fascinated/bat/command/impl/avatar/UserSubCommand.java b/src/main/java/cc/fascinated/bat/command/impl/general/avatar/UserSubCommand.java similarity index 97% rename from src/main/java/cc/fascinated/bat/command/impl/avatar/UserSubCommand.java rename to src/main/java/cc/fascinated/bat/command/impl/general/avatar/UserSubCommand.java index 2248297..19e3fda 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/avatar/UserSubCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/general/avatar/UserSubCommand.java @@ -1,4 +1,4 @@ -package cc.fascinated.bat.command.impl.avatar; +package cc.fascinated.bat.command.impl.general.avatar; import cc.fascinated.bat.command.BatSubCommand; import cc.fascinated.bat.command.CommandInfo; diff --git a/src/main/java/cc/fascinated/bat/command/impl/banner/BannerCommand.java b/src/main/java/cc/fascinated/bat/command/impl/general/banner/BannerCommand.java similarity index 92% rename from src/main/java/cc/fascinated/bat/command/impl/banner/BannerCommand.java rename to src/main/java/cc/fascinated/bat/command/impl/general/banner/BannerCommand.java index 83b59ae..19e85ab 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/banner/BannerCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/general/banner/BannerCommand.java @@ -1,4 +1,4 @@ -package cc.fascinated.bat.command.impl.banner; +package cc.fascinated.bat.command.impl.general.banner; import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; diff --git a/src/main/java/cc/fascinated/bat/command/impl/banner/GuildSubCommand.java b/src/main/java/cc/fascinated/bat/command/impl/general/banner/GuildSubCommand.java similarity index 96% rename from src/main/java/cc/fascinated/bat/command/impl/banner/GuildSubCommand.java rename to src/main/java/cc/fascinated/bat/command/impl/general/banner/GuildSubCommand.java index 0cb5c51..5cf462d 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/banner/GuildSubCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/general/banner/GuildSubCommand.java @@ -1,4 +1,4 @@ -package cc.fascinated.bat.command.impl.banner; +package cc.fascinated.bat.command.impl.general.banner; import cc.fascinated.bat.command.BatSubCommand; import cc.fascinated.bat.command.CommandInfo; diff --git a/src/main/java/cc/fascinated/bat/command/impl/banner/UserSubCommand.java b/src/main/java/cc/fascinated/bat/command/impl/general/banner/UserSubCommand.java similarity index 97% rename from src/main/java/cc/fascinated/bat/command/impl/banner/UserSubCommand.java rename to src/main/java/cc/fascinated/bat/command/impl/general/banner/UserSubCommand.java index cf5362e..b11f1e3 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/banner/UserSubCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/general/banner/UserSubCommand.java @@ -1,4 +1,4 @@ -package cc.fascinated.bat.command.impl.banner; +package cc.fascinated.bat.command.impl.general.banner; import cc.fascinated.bat.command.BatSubCommand; import cc.fascinated.bat.command.CommandInfo; diff --git a/src/main/java/cc/fascinated/bat/controller/SpotifyController.java b/src/main/java/cc/fascinated/bat/controller/SpotifyController.java index 4f23bf7..0901f3d 100644 --- a/src/main/java/cc/fascinated/bat/controller/SpotifyController.java +++ b/src/main/java/cc/fascinated/bat/controller/SpotifyController.java @@ -27,7 +27,7 @@ public class SpotifyController { * @return the response entity */ @GetMapping(value = "/callback") - public ResponseEntity authorizationCallback(@RequestParam String code) { + public ResponseEntity authorizationCallback(@RequestParam(required = false) String code) { return ResponseEntity.ok(spotifyService.authorize(code)); } } diff --git a/src/main/java/cc/fascinated/bat/exception/RateLimitException.java b/src/main/java/cc/fascinated/bat/exception/RateLimitException.java index 4724b07..558a100 100644 --- a/src/main/java/cc/fascinated/bat/exception/RateLimitException.java +++ b/src/main/java/cc/fascinated/bat/exception/RateLimitException.java @@ -5,7 +5,6 @@ import org.springframework.web.bind.annotation.ResponseStatus; @ResponseStatus(HttpStatus.TOO_MANY_REQUESTS) public class RateLimitException extends RuntimeException { - public RateLimitException(String message) { super(message); } diff --git a/src/main/java/cc/fascinated/bat/exception/spotify/SpotifyForbiddenException.java b/src/main/java/cc/fascinated/bat/exception/spotify/SpotifyForbiddenException.java new file mode 100644 index 0000000..897ba17 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/exception/spotify/SpotifyForbiddenException.java @@ -0,0 +1,13 @@ +package cc.fascinated.bat.exception.spotify; + +import lombok.experimental.StandardException; + +/** + * @author Fascinated (fascinated7) + */ +@StandardException +public class SpotifyForbiddenException extends RuntimeException { + public SpotifyForbiddenException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/cc/fascinated/bat/features/spotify/command/LinkSubCommand.java b/src/main/java/cc/fascinated/bat/features/spotify/command/LinkSubCommand.java index 2f0b644..e92027f 100644 --- a/src/main/java/cc/fascinated/bat/features/spotify/command/LinkSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/spotify/command/LinkSubCommand.java @@ -38,22 +38,25 @@ public class LinkSubCommand extends BatSubCommand implements EventListener { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) { - SpotifyProfile profile = user.getProfile(SpotifyProfile.class); - if (profile.hasLinkedAccount()) { - interaction.replyEmbeds(EmbedUtils.errorEmbed() - .setDescription("You have already linked your Spotify account!") - .build()) - .setEphemeral(true) - .queue(); - return; - } - interaction.replyEmbeds(EmbedUtils.genericEmbed() - .setDescription("You can link your Spotify account by clicking [here](%s)".formatted(spotifyService.getAuthorizationUrl())) - .build()) - .addComponents(ActionRow.of(Button.primary("spotify_link", "Link Spotify"))) - .setEphemeral(true) - .queue(); + .setDescription("We are currently awaiting Spotify's approval for our application. Please check back later.") + .build()).queue(); +// SpotifyProfile profile = user.getProfile(SpotifyProfile.class); +// if (profile.hasLinkedAccount()) { +// interaction.replyEmbeds(EmbedUtils.errorEmbed() +// .setDescription("You have already linked your Spotify account!") +// .build()) +// .setEphemeral(true) +// .queue(); +// return; +// } +// +// interaction.replyEmbeds(EmbedUtils.genericEmbed() +// .setDescription("You can link your Spotify account by clicking [here](%s)".formatted(spotifyService.getAuthorizationUrl())) +// .build()) +// .addComponents(ActionRow.of(Button.primary("spotify_link", "Link Spotify"))) +// .setEphemeral(true) +// .queue(); } @Override diff --git a/src/main/java/cc/fascinated/bat/service/SpotifyService.java b/src/main/java/cc/fascinated/bat/service/SpotifyService.java index b821210..42f28a5 100644 --- a/src/main/java/cc/fascinated/bat/service/SpotifyService.java +++ b/src/main/java/cc/fascinated/bat/service/SpotifyService.java @@ -117,10 +117,13 @@ public class SpotifyService { * @param user the user to start playback for * @return if the playback was paused */ - @SneakyThrows public boolean resumePlayback(BatUser user) { - getSpotifyApi(user).startResumeUsersPlayback().build().execute(); - return true; + try { + getSpotifyApi(user).startResumeUsersPlayback().build().execute(); + return true; + } catch (Exception e) { + throw new RuntimeException("Failed to resume playback", e); + } } /** @@ -133,12 +136,17 @@ public class SpotifyService { @SneakyThrows public String authorize(String code) { if (code == null) { - return "Missing code param"; + return """ + Click here to authorize your Spotify account + """.formatted(authorizationUrl); } AuthorizationCodeCredentials credentials = spotifyApi.authorizationCode(code).build().execute(); String key = StringUtils.randomString(16); accessToken.put(key, credentials); - return "Authorization Key: " + key; + return """ +

Successfully authorized your Spotify account!

+

Your key is: %s

+ """.formatted(key); } /**