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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -27,7 +27,7 @@ public class SpotifyController {
* @return the response entity
*/
@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));
}
}

View File

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

View File

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

View File

@ -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

View File

@ -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 """
<a href="%s">Click here to authorize your Spotify account</a>
""".formatted(authorizationUrl);
}
AuthorizationCodeCredentials credentials = spotifyApi.authorizationCode(code).build().execute();
String key = StringUtils.randomString(16);
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);
}
/**