Search in sources :

Example 6 with GuildMusicManager

use of toby.lavaplayer.GuildMusicManager in project toby-bot by ml404.

the class Handler method closeAudioPlayer.

private void closeAudioPlayer(Guild guild, AudioManager audioManager, int defaultVolume) {
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(guild);
    musicManager.getScheduler().setLooping(false);
    musicManager.getScheduler().getQueue().clear();
    musicManager.getAudioPlayer().stopTrack();
    musicManager.getAudioPlayer().setVolume(defaultVolume);
    audioManager.closeAudioConnection();
}
Also used : GuildMusicManager(toby.lavaplayer.GuildMusicManager)

Example 7 with GuildMusicManager

use of toby.lavaplayer.GuildMusicManager in project toby-bot by ml404.

the class NowPlayingCommand method handle.

@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
    ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
    final TextChannel channel = ctx.getChannel();
    if (requestingUserDto.hasMusicPermission()) {
        if (IMusicCommand.isInvalidChannelStateForCommand(ctx, channel, deleteDelay))
            return;
        final GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
        final AudioPlayer audioPlayer = musicManager.getAudioPlayer();
        final AudioTrack track = audioPlayer.getPlayingTrack();
        if (track == null) {
            channel.sendMessage("There is no track playing currently").queue(message -> ICommand.deleteAfter(message, deleteDelay));
            return;
        }
        final AudioTrackInfo info = track.getInfo();
        AudioTrack playingTrack = musicManager.getAudioPlayer().getPlayingTrack();
        if (!track.getInfo().isStream) {
            long position = playingTrack.getPosition();
            long duration = playingTrack.getDuration();
            String songPosition = QueueCommand.formatTime(position);
            String songDuration = QueueCommand.formatTime(duration);
            String nowPlaying = String.format("Now playing `%s` by `%s` `[%s/%s]` (Link: <%s>) ", info.title, info.author, songPosition, songDuration, info.uri);
            channel.sendMessage(nowPlaying).queue(message -> ICommand.deleteAfter(message, deleteDelay));
        } else {
            String nowPlaying = String.format("Now playing `%s` by `%s` (Link: <%s>) ", info.title, info.author, info.uri);
            channel.sendMessage(nowPlaying).queue(message -> ICommand.deleteAfter(message, deleteDelay));
        }
    }
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) GuildMusicManager(toby.lavaplayer.GuildMusicManager) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)

Example 8 with GuildMusicManager

use of toby.lavaplayer.GuildMusicManager in project toby-bot by ml404.

the class QueueCommand method handle.

@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
    ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
    final TextChannel channel = ctx.getChannel();
    final GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    final BlockingQueue<AudioTrack> queue = musicManager.getScheduler().getQueue();
    if (!requestingUserDto.hasMusicPermission()) {
        sendErrorMessage(ctx, channel, deleteDelay);
        return;
    }
    if (queue.isEmpty()) {
        channel.sendMessage("The queue is currently empty").queue(message -> ICommand.deleteAfter(message, deleteDelay));
        return;
    }
    final int trackCount = Math.min(queue.size(), 20);
    final List<AudioTrack> trackList = new ArrayList<>(queue);
    final MessageAction messageAction = channel.sendMessage("**Current Queue:**\n");
    for (int i = 0; i < trackCount; i++) {
        final AudioTrack track = trackList.get(i);
        final AudioTrackInfo info = track.getInfo();
        messageAction.append('#').append(String.valueOf(i + 1)).append(" `").append(String.valueOf(info.title)).append(" by ").append(info.author).append("` [`").append(formatTime(track.getDuration())).append("`]\n");
    }
    if (trackList.size() > trackCount) {
        messageAction.append("And `").append(String.valueOf(trackList.size() - trackCount)).append("` more...");
    }
    messageAction.queue(message -> ICommand.deleteAfter(message, deleteDelay));
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) GuildMusicManager(toby.lavaplayer.GuildMusicManager) MessageAction(net.dv8tion.jda.api.requests.restaction.MessageAction) ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)

Aggregations

GuildMusicManager (toby.lavaplayer.GuildMusicManager)8 TextChannel (net.dv8tion.jda.api.entities.TextChannel)6 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)3 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)3 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)2 ArrayList (java.util.ArrayList)1 Guild (net.dv8tion.jda.api.entities.Guild)1 Member (net.dv8tion.jda.api.entities.Member)1 AudioManager (net.dv8tion.jda.api.managers.AudioManager)1 MessageAction (net.dv8tion.jda.api.requests.restaction.MessageAction)1 ConfigDto (toby.jpa.dto.ConfigDto)1 TrackScheduler (toby.lavaplayer.TrackScheduler)1