2727import me .duncte123 .skybot .extensions .AudioTrackKt ;
2828import me .duncte123 .skybot .objects .TrackUserData ;
2929import me .duncte123 .skybot .utils .Debouncer ;
30- import net .dv8tion .jda .api .entities .channel .middleman .MessageChannel ;
3130import net .dv8tion .jda .api .exceptions .ErrorHandler ;
3231import org .slf4j .Logger ;
3332import org .slf4j .LoggerFactory ;
@@ -56,17 +55,12 @@ public class TrackScheduler {
5655 /* package */ TrackScheduler (GuildMusicManager guildMusicManager ) {
5756 this .guildMusicManager = guildMusicManager ;
5857 this .messageDebouncer = new Debouncer <>((msg ) -> {
59- final MessageChannel latestChannel = guildMusicManager .getLatestChannel ();
60-
61- if (latestChannel == null ) {
62- return ;
63- }
64-
65- sendMsg (new MessageConfig .Builder ()
66- .setChannel (latestChannel )
67- .setMessage (msg )
68- .setFailureAction (new ErrorHandler ().ignore (UNKNOWN_CHANNEL , MISSING_PERMISSIONS ))
69- .build ());
58+ guildMusicManager .getLatestChannel ()
59+ .ifPresent ((latestChannel ) -> sendMsg (new MessageConfig .Builder ()
60+ .setChannel (latestChannel )
61+ .setMessage (msg )
62+ .setFailureAction (new ErrorHandler ().ignore (UNKNOWN_CHANNEL , MISSING_PERMISSIONS ))
63+ .build ()));
7064 }, DEBOUNCE_INTERVAL );
7165 }
7266
@@ -92,10 +86,10 @@ public void addToQueue(Track track, boolean isPatron) throws LimitReachedExcepti
9286
9387 /**
9488 *
95- * @param tracks
96- * @param isPatron
89+ * @param tracks The tracks to be added to the queue.
90+ * @param isPatron if this user is a supporter of the bot.
9791 * @return The total amount of tracks that were added to the queue.
98- * @throws LimitReachedException
92+ * @throws LimitReachedException When the free limit has been reached.
9993 */
10094 public int queuePlaylistTracks (List <Track > tracks , boolean isPatron ) throws LimitReachedException {
10195 final List <Track > tmpQueue = new ArrayList <>();
@@ -136,11 +130,13 @@ public void skipTracks(int count, boolean forceAnnounce) {
136130
137131 if (nextTrack == null ) {
138132 this .guildMusicManager .getPlayer ().stopPlayback ();
139- sendMsg (
140- new MessageConfig .Builder ()
141- .setChannel (guildMusicManager .getLatestChannel ())
142- .setMessage ("Queue concluded" )
143- );
133+
134+ guildMusicManager .getLatestChannel ()
135+ .ifPresent ((channel ) -> sendMsg (
136+ new MessageConfig .Builder ()
137+ .setChannel (channel )
138+ .setMessage ("Queue concluded" )
139+ ));
144140 } else {
145141 // Make sure to cary over the skip state, we want to announce skipped tracks
146142 getUserData (nextTrack ).setForceAnnounce (forceAnnounce );
@@ -158,21 +154,22 @@ public void onTrackStart(Track track) {
158154 data .setForceAnnounce (false );
159155 }
160156
161- AudioTrackKt .toEmbed (
162- track ,
163- this .guildMusicManager ,
164- getInstance ().getShardManager (),
165- false ,
166- (message ) -> {
167- sendMsg (
168- new MessageConfig .Builder ()
169- .setChannel (guildMusicManager .getLatestChannel ())
170- .setEmbeds (false , message )
171- );
172-
173- return null ;
174- }
175- );
157+ guildMusicManager .getLatestChannel ()
158+ .ifPresent ((latestChannel ) -> AudioTrackKt .toEmbed (
159+ track ,
160+ this .guildMusicManager ,
161+ getInstance ().getShardManager (),
162+ false ,
163+ (message ) -> {
164+ sendMsg (
165+ new MessageConfig .Builder ()
166+ .setChannel (latestChannel )
167+ .setEmbeds (false , message )
168+ );
169+
170+ return null ;
171+ }
172+ ));
176173 }
177174 }
178175
0 commit comments