diff --git a/src/main/java/cc/fascinated/bat/features/spotify/SpotifyFeature.java b/src/main/java/cc/fascinated/bat/features/spotify/SpotifyFeature.java index bf04dc8..44db632 100644 --- a/src/main/java/cc/fascinated/bat/features/spotify/SpotifyFeature.java +++ b/src/main/java/cc/fascinated/bat/features/spotify/SpotifyFeature.java @@ -110,19 +110,24 @@ public class SpotifyFeature extends Feature { if (!profile.hasLinkedAccount() || !spotifyService.hasTrackPlaying(user)) { return checkSpotify(spotifyService, user); } - CurrentlyPlaying currentlyPlaying = spotifyService.getCurrentlyPlayingTrack(user); Track track = (Track) currentlyPlaying.getItem(); String trackName = track.getName(); + for (Action action : currentlyPlaying.getActions().getDisallows().getDisallowedActions()) { + if (action.equals(Action.SKIPPING_NEXT)) { + return EmbedUtils.errorEmbed() + .setDescription("%s Unable to skip the track.".formatted(Emojis.CROSS_MARK_EMOJI)); + } + } - spotifyService.skipTrack(user); + spotifyService.skipTrack(user); // Skip the track + // Get the new track CurrentlyPlaying newCurrentlyPlaying = SpotifyUtils.getNewTrack(spotifyService, user, trackName); if (newCurrentlyPlaying == null) { return EmbedUtils.errorEmbed() .setDescription("%s There are no more tracks in the queue.".formatted(Emojis.CROSS_MARK_EMOJI)); } Track newTrack = (Track) newCurrentlyPlaying.getItem(); - return EmbedUtils.successEmbed() .setDescription(""" :track_next: Skipped the track: **[%s | %s](%s)** diff --git a/src/main/java/cc/fascinated/bat/service/SpotifyService.java b/src/main/java/cc/fascinated/bat/service/SpotifyService.java index 21a957c..e631b65 100644 --- a/src/main/java/cc/fascinated/bat/service/SpotifyService.java +++ b/src/main/java/cc/fascinated/bat/service/SpotifyService.java @@ -89,12 +89,10 @@ public class SpotifyService { * Starts playback for the user. * * @param user the user to start playback for - * @return if the playback was started */ @SneakyThrows - public boolean skipTrack(BatUser user) { + public void skipTrack(BatUser user) { getSpotifyApi(user).skipUsersPlaybackToNextTrack().build().execute(); - return true; } /** @@ -105,10 +103,12 @@ public class SpotifyService { */ @SneakyThrows public CurrentlyPlaying getCurrentlyPlayingTrack(BatUser user) { - if (currentlyPlayingCache.containsKey(user)) { - return currentlyPlayingCache.get(user); + CurrentlyPlaying currentlyPlaying = currentlyPlayingCache.get(user); + // If the track is still playing return the cache otherwise fetch the track + if (currentlyPlaying != null && currentlyPlaying.getTimestamp() + currentlyPlaying.getProgress_ms() < System.currentTimeMillis()) { + return currentlyPlaying; } - CurrentlyPlaying currentlyPlaying = getSpotifyApi(user).getUsersCurrentlyPlayingTrack().build().execute(); + currentlyPlaying = getSpotifyApi(user).getUsersCurrentlyPlayingTrack().build().execute(); currentlyPlayingCache.put(user, currentlyPlaying); return currentlyPlaying; } @@ -127,7 +127,6 @@ public class SpotifyService { * Pauses playback for the user. * * @param user the user to start playback for - * @return if the playback was paused */ @SneakyThrows public void pausePlayback(BatUser user) { @@ -138,7 +137,6 @@ public class SpotifyService { * Pauses playback for the user. * * @param user the user to start playback for - * @return if the playback was paused */ @SneakyThrows public void resumePlayback(BatUser user) { @@ -183,7 +181,7 @@ public class SpotifyService { /** * Ensures the user has a valid Spotify access token. *

- * If the token is expired, it will be refreshed. + * If the token is expired, it will be refreshed. *

* * @param user the user to get the token for