disable spotify linking (until they accept out application)
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 36s

This commit is contained in:
Lee 2024-06-29 13:08:13 +01:00
parent 320eab34a3
commit d2d898a5b8
15 changed files with 55 additions and 32 deletions

@ -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.BatCommand;
import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.command.CommandInfo;

@ -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.Consts;
import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.BatCommand;

@ -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.Consts;
import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.BatCommand;

@ -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.BatCommand;
import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.command.CommandInfo;

@ -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.BatCommand;
import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.command.CommandInfo;

@ -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.BatSubCommand;
import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.command.CommandInfo;

@ -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.BatSubCommand;
import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.command.CommandInfo;

@ -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.BatCommand;
import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.command.CommandInfo;

@ -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.BatSubCommand;
import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.command.CommandInfo;

@ -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.BatSubCommand;
import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.command.CommandInfo;

@ -27,7 +27,7 @@ public class SpotifyController {
* @return the response entity * @return the response entity
*/ */
@GetMapping(value = "/callback") @GetMapping(value = "/callback")
public ResponseEntity<String> authorizationCallback(@RequestParam String code) { public ResponseEntity<String> authorizationCallback(@RequestParam(required = false) String code) {
return ResponseEntity.ok(spotifyService.authorize(code)); return ResponseEntity.ok(spotifyService.authorize(code));
} }
} }

@ -5,7 +5,6 @@ import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(HttpStatus.TOO_MANY_REQUESTS) @ResponseStatus(HttpStatus.TOO_MANY_REQUESTS)
public class RateLimitException extends RuntimeException { public class RateLimitException extends RuntimeException {
public RateLimitException(String message) { public RateLimitException(String message) {
super(message); super(message);
} }

@ -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);
}
}

@ -38,22 +38,25 @@ public class LinkSubCommand extends BatSubCommand implements EventListener {
@Override @Override
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) { 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() interaction.replyEmbeds(EmbedUtils.genericEmbed()
.setDescription("You can link your Spotify account by clicking [here](%s)".formatted(spotifyService.getAuthorizationUrl())) .setDescription("We are currently awaiting Spotify's approval for our application. Please check back later.")
.build()) .build()).queue();
.addComponents(ActionRow.of(Button.primary("spotify_link", "Link Spotify"))) // SpotifyProfile profile = user.getProfile(SpotifyProfile.class);
.setEphemeral(true) // if (profile.hasLinkedAccount()) {
.queue(); // 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 @Override

@ -117,10 +117,13 @@ public class SpotifyService {
* @param user the user to start playback for * @param user the user to start playback for
* @return if the playback was paused * @return if the playback was paused
*/ */
@SneakyThrows
public boolean resumePlayback(BatUser user) { public boolean resumePlayback(BatUser user) {
try {
getSpotifyApi(user).startResumeUsersPlayback().build().execute(); getSpotifyApi(user).startResumeUsersPlayback().build().execute();
return true; return true;
} catch (Exception e) {
throw new RuntimeException("Failed to resume playback", e);
}
} }
/** /**
@ -133,12 +136,17 @@ public class SpotifyService {
@SneakyThrows @SneakyThrows
public String authorize(String code) { public String authorize(String code) {
if (code == null) { if (code == null) {
return "Missing code param"; return """
<a href="%s">Click here to authorize your Spotify account</a>
""".formatted(authorizationUrl);
} }
AuthorizationCodeCredentials credentials = spotifyApi.authorizationCode(code).build().execute(); AuthorizationCodeCredentials credentials = spotifyApi.authorizationCode(code).build().execute();
String key = StringUtils.randomString(16); String key = StringUtils.randomString(16);
accessToken.put(key, credentials); accessToken.put(key, credentials);
return "Authorization Key: " + key; return """
<p>Successfully authorized your Spotify account!</p>
<p>Your key is: <strong>%s</strong></p>
""".formatted(key);
} }
/** /**