Search in sources :

Example 1 with TrackScheduler

use of net.kodehawa.mantarobot.commands.music.requester.TrackScheduler in project MantaroBot by Mantaro.

the class MusicCmds method nextSong.

@Subscribe
public void nextSong(CommandRegistry cr) {
    cr.register("ns", new SimpleCommand(Category.MUSIC) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            GuildMusicManager musicManager = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
            TrackScheduler scheduler = musicManager.getTrackScheduler();
            AudioTrack next = scheduler.getQueue().peek();
            if (next == null) {
                event.getChannel().sendMessage(EmoteReference.TALKING + "Ow, there isn't any song next").queue();
            } else {
                event.getChannel().sendMessage(EmoteReference.MEGA + "Next song in queue: **" + next.getInfo().title + "** (" + Utils.getDurationMinutes(next.getDuration()) + ")" + " | *Total songs in queue: " + scheduler.getQueue().size() + "*").queue();
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Next Song Command").addField("Description", "**Shows the next song in queue!**", false).build();
        }
    });
    cr.registerAlias("ns", "nextsong");
}
Also used : SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) TrackScheduler(net.kodehawa.mantarobot.commands.music.requester.TrackScheduler) Subscribe(com.google.common.eventbus.Subscribe)

Example 2 with TrackScheduler

use of net.kodehawa.mantarobot.commands.music.requester.TrackScheduler in project MantaroBot by Mantaro.

the class MantaroAudioManager method loadAndPlay.

public void loadAndPlay(GuildMessageReceivedEvent event, String trackUrl, boolean skipSelection, boolean addFirst) {
    if (!AudioCmdUtils.connectToVoiceChannel(event))
        return;
    GuildMusicManager musicManager = getMusicManager(event.getGuild());
    TrackScheduler scheduler = musicManager.getTrackScheduler();
    scheduler.getAudioPlayer().setPaused(false);
    if (scheduler.getQueue().isEmpty())
        scheduler.setRepeatMode(null);
    playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoader(musicManager, event, skipSelection, addFirst));
}
Also used : TrackScheduler(net.kodehawa.mantarobot.commands.music.requester.TrackScheduler) AudioLoader(net.kodehawa.mantarobot.commands.music.requester.AudioLoader)

Example 3 with TrackScheduler

use of net.kodehawa.mantarobot.commands.music.requester.TrackScheduler in project MantaroBot by Mantaro.

the class VoiceChannelListener method onLeave.

private void onLeave(VoiceChannel vc) {
    GuildVoiceState vs = vc.getGuild().getSelfMember().getVoiceState();
    if (validate(vs))
        return;
    if (isAlone(vc)) {
        GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(vc.getGuild());
        if (gmm != null) {
            TrackScheduler scheduler = gmm.getTrackScheduler();
            if (scheduler != null && scheduler.getCurrentTrack() != null && scheduler.getRequestedChannelParsed() != null) {
                TextChannel tc = scheduler.getRequestedChannelParsed();
                if (tc.canTalk()) {
                    tc.sendMessage(EmoteReference.THINKING + "I'll leave **" + vc.getName() + "** in 2 minutes because I was left all alone :<").queue(m -> m.delete().queueAfter(30, TimeUnit.SECONDS));
                }
            }
            gmm.setAwaitingDeath(true);
            gmm.scheduleLeave();
            gmm.getAudioPlayer().setPaused(true);
        }
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.core.entities.GuildVoiceState) TrackScheduler(net.kodehawa.mantarobot.commands.music.requester.TrackScheduler)

Example 4 with TrackScheduler

use of net.kodehawa.mantarobot.commands.music.requester.TrackScheduler in project MantaroBot by Mantaro.

the class VoiceChannelListener method onJoin.

private void onJoin(VoiceChannel vc) {
    GuildVoiceState vs = vc.getGuild().getSelfMember().getVoiceState();
    if (validate(vs))
        return;
    if (!isAlone(vc)) {
        GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(vc.getGuild());
        if (gmm != null) {
            TrackScheduler scheduler = gmm.getTrackScheduler();
            if (scheduler.getCurrentTrack() != null) {
                if (gmm.isAwaitingDeath()) {
                    TextChannel tc = scheduler.getRequestedChannelParsed();
                    if (tc.canTalk()) {
                        tc.sendMessage(EmoteReference.POPPER + "Resuming playback because someone joined!").queue();
                    }
                }
            }
            gmm.cancelLeave();
            gmm.setAwaitingDeath(false);
            gmm.getAudioPlayer().setPaused(false);
        }
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.core.entities.GuildVoiceState) TrackScheduler(net.kodehawa.mantarobot.commands.music.requester.TrackScheduler)

Example 5 with TrackScheduler

use of net.kodehawa.mantarobot.commands.music.requester.TrackScheduler in project MantaroBot by Mantaro.

the class VoiceChannelListener method onGuildVoiceMute.

private void onGuildVoiceMute(GuildVoiceMuteEvent event) {
    if (event.getMember().getUser().getIdLong() != event.getJDA().getSelfUser().getIdLong())
        return;
    GuildVoiceState vs = event.getVoiceState();
    if (validate(vs))
        return;
    GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
    if (gmm != null) {
        if (event.isMuted()) {
            TrackScheduler scheduler = gmm.getTrackScheduler();
            if (scheduler.getCurrentTrack() != null && scheduler.getRequestedChannelParsed() != null) {
                TextChannel tc = scheduler.getRequestedChannelParsed();
                if (tc.canTalk()) {
                    tc.sendMessage(EmoteReference.SAD + "Pausing player because I got muted :(").queue();
                }
                gmm.getAudioPlayer().setPaused(true);
            }
        } else {
            if (!isAlone(vs.getChannel())) {
                if (gmm.getTrackScheduler().getCurrentTrack() != null) {
                    gmm.getAudioPlayer().setPaused(false);
                }
            }
        }
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.core.entities.GuildVoiceState) TrackScheduler(net.kodehawa.mantarobot.commands.music.requester.TrackScheduler)

Aggregations

TrackScheduler (net.kodehawa.mantarobot.commands.music.requester.TrackScheduler)7 GuildMusicManager (net.kodehawa.mantarobot.commands.music.GuildMusicManager)5 GuildVoiceState (net.dv8tion.jda.core.entities.GuildVoiceState)3 TextChannel (net.dv8tion.jda.core.entities.TextChannel)3 Subscribe (com.google.common.eventbus.Subscribe)2 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)2 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)2 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 AudioLoader (net.kodehawa.mantarobot.commands.music.requester.AudioLoader)1