forked from jagrosh/MusicBot
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
playlist load faster and queue command shows np
- Loading branch information
Showing
11 changed files
with
217 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 94 additions & 84 deletions
178
src/main/java/com/jagrosh/jmusicbot/commands/QueueCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,94 @@ | ||
/* | ||
* Copyright 2016 John Grosh <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.jagrosh.jmusicbot.commands; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
import com.jagrosh.jdautilities.commandclient.CommandEvent; | ||
import com.jagrosh.jdautilities.menu.pagination.PaginatorBuilder; | ||
import com.jagrosh.jmusicbot.Bot; | ||
import com.jagrosh.jmusicbot.audio.AudioHandler; | ||
import com.jagrosh.jmusicbot.audio.QueuedTrack; | ||
import com.jagrosh.jmusicbot.utils.FormatUtil; | ||
import net.dv8tion.jda.core.Permission; | ||
import net.dv8tion.jda.core.exceptions.PermissionException; | ||
|
||
/** | ||
* | ||
* @author John Grosh <[email protected]> | ||
*/ | ||
public class QueueCmd extends MusicCommand { | ||
|
||
private final PaginatorBuilder builder; | ||
public QueueCmd(Bot bot) | ||
{ | ||
super(bot); | ||
this.name = "queue"; | ||
this.help = "shows the current queue"; | ||
this.arguments = "[pagenum]"; | ||
this.aliases = new String[]{"list"}; | ||
this.bePlaying = true; | ||
this.botPermissions = new Permission[]{Permission.MESSAGE_ADD_REACTION,Permission.MESSAGE_EMBED_LINKS}; | ||
builder = new PaginatorBuilder() | ||
.setColumns(1) | ||
.setFinalAction(m -> {try{m.clearReactions().queue();}catch(PermissionException e){}}) | ||
.setItemsPerPage(10) | ||
.waitOnSinglePage(false) | ||
.useNumberedItems(true) | ||
.showPageNumbers(true) | ||
.setEventWaiter(bot.getWaiter()) | ||
.setTimeout(1, TimeUnit.MINUTES) | ||
; | ||
} | ||
|
||
@Override | ||
public void doCommand(CommandEvent event) { | ||
int pagenum = 1; | ||
try{ | ||
pagenum = Integer.parseInt(event.getArgs()); | ||
}catch(NumberFormatException e){} | ||
List<QueuedTrack> list = ((AudioHandler)event.getGuild().getAudioManager().getSendingHandler()).getQueue().getList(); | ||
if(list.isEmpty()) | ||
{ | ||
event.reply(event.getClient().getWarning()+" There is no music in the queue!"); | ||
return; | ||
} | ||
String[] songs = new String[list.size()]; | ||
long total = 0; | ||
for(int i=0; i<list.size(); i++) | ||
{ | ||
total += list.get(i).getTrack().getDuration(); | ||
songs[i] = list.get(i).toString(); | ||
} | ||
builder.setText(event.getClient().getSuccess()+" Current Queue | "+songs.length+" entries | `"+FormatUtil.formatTime(total)+"` ") | ||
.setItems(songs) | ||
.setUsers(event.getAuthor()) | ||
.setColor(event.getSelfMember().getColor()) | ||
; | ||
builder.build().paginate(event.getChannel(), pagenum); | ||
} | ||
|
||
} | ||
/* | ||
* Copyright 2016 John Grosh <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.jagrosh.jmusicbot.commands; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
import com.jagrosh.jdautilities.commandclient.CommandEvent; | ||
import com.jagrosh.jdautilities.menu.pagination.PaginatorBuilder; | ||
import com.jagrosh.jmusicbot.Bot; | ||
import com.jagrosh.jmusicbot.audio.AudioHandler; | ||
import com.jagrosh.jmusicbot.audio.QueuedTrack; | ||
import com.jagrosh.jmusicbot.utils.FormatUtil; | ||
import net.dv8tion.jda.core.Permission; | ||
import net.dv8tion.jda.core.exceptions.PermissionException; | ||
|
||
/** | ||
* | ||
* @author John Grosh <[email protected]> | ||
*/ | ||
public class QueueCmd extends MusicCommand { | ||
|
||
private final PaginatorBuilder builder; | ||
public QueueCmd(Bot bot) | ||
{ | ||
super(bot); | ||
this.name = "queue"; | ||
this.help = "shows the current queue"; | ||
this.arguments = "[pagenum]"; | ||
this.aliases = new String[]{"list"}; | ||
this.bePlaying = true; | ||
this.botPermissions = new Permission[]{Permission.MESSAGE_ADD_REACTION,Permission.MESSAGE_EMBED_LINKS}; | ||
builder = new PaginatorBuilder() | ||
.setColumns(1) | ||
.setFinalAction(m -> {try{m.clearReactions().queue();}catch(PermissionException e){}}) | ||
.setItemsPerPage(10) | ||
.waitOnSinglePage(false) | ||
.useNumberedItems(true) | ||
.showPageNumbers(true) | ||
.setEventWaiter(bot.getWaiter()) | ||
.setTimeout(1, TimeUnit.MINUTES) | ||
; | ||
} | ||
|
||
@Override | ||
public void doCommand(CommandEvent event) { | ||
int pagenum = 1; | ||
try{ | ||
pagenum = Integer.parseInt(event.getArgs()); | ||
}catch(NumberFormatException e){} | ||
AudioHandler ah = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); | ||
List<QueuedTrack> list = ah.getQueue().getList(); | ||
if(list.isEmpty()) | ||
{ | ||
event.replyWarning("There is no music in the queue!" | ||
+(!ah.isMusicPlaying() ? "" : " Now playing:\n\n**"+ah.getCurrentTrack().getTrack().getInfo().title+"**\n"+FormatUtil.embedformattedAudio(ah))); | ||
return; | ||
} | ||
String[] songs = new String[list.size()]; | ||
long total = 0; | ||
for(int i=0; i<list.size(); i++) | ||
{ | ||
total += list.get(i).getTrack().getDuration(); | ||
songs[i] = list.get(i).toString(); | ||
} | ||
long fintotal = total; | ||
builder.setText((i1,i2) -> getQueueTitle(ah, event.getClient().getSuccess(), songs.length, fintotal)) | ||
.setItems(songs) | ||
.setUsers(event.getAuthor()) | ||
.setColor(event.getSelfMember().getColor()) | ||
; | ||
builder.build().paginate(event.getChannel(), pagenum); | ||
} | ||
|
||
private String getQueueTitle(AudioHandler ah, String success, int songslength, long total) | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
if(ah.getCurrentTrack()!=null) | ||
sb.append("**").append(ah.getCurrentTrack().getTrack().getInfo().title).append("**\n").append(FormatUtil.embedformattedAudio(ah)).append("\n\n"); | ||
return sb.append(success).append(" Current Queue | ").append(songslength).append(" entries | `").append(FormatUtil.formatTime(total)).append("` ").toString(); | ||
} | ||
} |
Oops, something went wrong.