Search in sources :

Example 1 with CommandContext

use of com.discordbolt.api.command.CommandContext in project BoltBot by DiscordBolt.

the class QueueCommand method queueCommand.

@BotCommand(command = "queue", module = MusicModule.MODULE, description = "Show the currently queued songs", usage = "Queue", allowedChannels = "music", args = 1)
public static void queueCommand(CommandContext cc) throws CommandException {
    List<AudioTrack> queue = MusicModule.getVoiceManager().getQueue(cc.getGuild());
    AudioTrack nowPlaying = MusicModule.getVoiceManager().getNowPlaying(cc.getGuild());
    if (nowPlaying == null)
        throw new CommandStateException("The queue is empty! Play something with !Play");
    final long totalTime = MusicModule.getVoiceManager().getQueue(cc.getGuild()).stream().map(AudioTrack::getDuration).reduce(0L, (x, y) -> x + y) + MusicModule.getVoiceManager().getNowPlaying(cc.getGuild()).getDuration();
    EmbedBuilder embed = new EmbedBuilder();
    embed.withTitle(":clock1030: Queue Length");
    embed.withDescription(TimeUtil.getFormattedTime(totalTime));
    embed.withColor(MusicModule.EMBED_COLOR);
    StringBuilder songs = new StringBuilder();
    int i = 2;
    songs.append("***1. ").append(nowPlaying.getInfo().title).append("***").append('\n');
    for (AudioTrack audioTrack : queue) {
        if ((songs.length() + audioTrack.getInfo().title.length()) >= 975 && (i - 1) < queue.size()) {
            songs.append("\n");
            songs.append("    ***... and ").append(queue.size() - (i - 1)).append(" more***");
            break;
        }
        songs.append(i++).append(". ").append(audioTrack.getInfo().title).append('\n');
    }
    embed.appendField(":arrow_forward: Now Playing", songs.length() > 1 ? songs.toString() : "\n", true);
    cc.replyWith(embed.build());
}
Also used : CommandException(com.discordbolt.api.command.exceptions.CommandException) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) List(java.util.List) TimeUtil(com.discordbolt.boltbot.utils.TimeUtil) MusicModule(com.discordbolt.boltbot.modules.music.MusicModule) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) CommandContext(com.discordbolt.api.command.CommandContext) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) BotCommand(com.discordbolt.api.command.BotCommand) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) BotCommand(com.discordbolt.api.command.BotCommand)

Aggregations

BotCommand (com.discordbolt.api.command.BotCommand)1 CommandContext (com.discordbolt.api.command.CommandContext)1 CommandArgumentException (com.discordbolt.api.command.exceptions.CommandArgumentException)1 CommandException (com.discordbolt.api.command.exceptions.CommandException)1 CommandStateException (com.discordbolt.api.command.exceptions.CommandStateException)1 MusicModule (com.discordbolt.boltbot.modules.music.MusicModule)1 TimeUtil (com.discordbolt.boltbot.utils.TimeUtil)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 List (java.util.List)1 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)1