resFuture.complete(newCommandResult(CommandResultType.FAILURE,"There is already a pending playlist or livestream."));
return;
}
mm.vote(user.getUser(),"tracks",req);//self vote; should never return -1 (success) coz req > 1
channel.sendMessage("Due to the total duration of your requested tracks, it has been added to pending. It will be automatically removed if it has not been approved by the users in the channel for longer than 1 minute.\n"+"Others in the channel should use `!desp music approve` to vote.").queue();
mm.pending=l;
mm.pendingCleanup=ex.schedule(()->{
mm.clearVotes("tracks");
mm.pending=null;
mm.pendingCleanup=null;
channel.sendMessage(user.getUser().getName()+"'s"+(l.size()>1?" playlist ":" livestream ")+"request has timed out.").queue();
channel.sendMessage("Adding `"+l.get(0).getInfo().title+"` ("+(l.get(0).getDuration()==Long.MAX_VALUE?"N/A":l.get(0).getUserData(TrackData.class).getFormattedDuration())+") to the queue. [`"+startIndex+"`]").queue();
}else{
channel.sendMessage("Adding playlist `"+n+"` to the queue, queue now has a total of `"+(startIndex+l.size()-1)+"` tracks.").queue();
},(ex)->resFuture.complete(ex.getStackTrace()[0].getMethodName().equals("readPlaylistName")?newCommandResult(CommandResultType.FAILURE,"Cannot read the playlist specified. Is it private?"):newCommandResult(CommandResultType.ERROR,ExceptionUtils.getStackTrace(ex))));
exceptionally.accept(e);//so i dont lose my sanity over silenced errors
}
}
@Override
publicvoidplaylistLoaded(AudioPlaylistplaylist){
try{
if(playlist.getTracks().size()==0){//somehow its possible; do the same as noResult()
if(url.startsWith("ytsearch:"))load(user,url.replaceFirst("yt","sc"),resultHandler,exceptionally);//searches in soundcloud, since apparently yt pretty frequently returns no result
elseresultHandler.accept(null,newArrayList<>());
return;
}
StringplName=playlist.getName();
List<AudioTrack>tracks=playlist.getTracks();
StringplId="";
if(playlist.isSearchResult()){
tracks=tracks.subList(0,1);//only get first result if search
plName=null;//no actual playlist name
}else{
if(url.contains("://soundcloud.com")||url.contains("://www.youtube.com"))//add pl id if is playlist
exceptionally.accept(e);//so i dont lose my sanity over silenced errors
}
}
@Override
publicvoidnoMatches(){
if(url.startsWith("ytsearch:"))load(user,url.replaceFirst("yt","sc"),resultHandler,exceptionally);//searches in soundcloud, since apparently yt pretty frequently returns no result
List<AudioTrack>tracks=mm.scheduler.findTracks(1,Integer.MAX_VALUE).stream().filter(a->a!=null).collect(Collectors.toList());//get all tracks in queue
tracks.add(0,playing);
intmaxPage=(int)Math.ceil(tracks.size()/10f);
if(page>maxPage)thrownewIllegalArgumentException("There is no such page.");
smsg.append("The current queue (page "+page+"/"+maxPage+"): \n");
if(mm.scheduler.loop!=null){
smsg.append("There is a total of `"+tracks.size()+"` tracks "+(mm.scheduler.loop.equals("loop")?"looping":"in autoplay")+".\n\n");
}else{
longmillis=0;
for(AudioTracktrack:tracks)
millis+=track.getDuration();
smsg.append("There is a total of `"+tracks.size()+"` tracks queued"+((millis==Long.MAX_VALUE||millis<0)?".\n\n":", with a total duration of `"+MiscUtils.convertMillis(millis-playing.getPosition())+"`.\n\n"));
}else{//remove autoplay queued track when disabling autoplay?
if(mm.scheduler.loop.equals("autoplay")&&mm.scheduler.getQueueSize()==1&&mm.scheduler.findTracks(1,1).get(0).getUserData(TrackData.class).uDis.equals("Autoplay")){//including autoplay, theres only 2 tracks; only remove tracks that is autoplayed
mm.scheduler.removeTrack(1);
}
mm.scheduler.loop=null;
returnfalse;
}
}
publicvoidstopAndClearQueue(Guildguild){
GuildMusicManagermm=getGuildMusicManager(guild);
mm.pending=null;
mm.pendingCleanup=null;
mm.clearQueueCleanup=null;
mm.scheduler.loop=null;
mm.scheduler.clearSchedulerQueue();
mm.clearAllVotes();
mm.player.stopTrack();
mm.player.setPaused(false);
guild.getAudioManager().closeAudioConnection();
}
//should ALWAYS be called before discarding this instance
DiscordBot.lastMusicCmd.get(s).sendMessage("The music bot is going into maintenance and it will now disconnect. Sorry for the inconvenience.").queue();
}
});
musicManagers=null;//so further operations wont be possible even if i forgot to set this instance to null