Search in sources :

Example 6 with GuildMusicManager

use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.

the class Skip method handle.

@Override
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    VoiceChannel vc = ctx.getSelfMember().getVoiceState().getChannel();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    AudioPlayer audioPlayer = musicManager.audioPlayer;
    if (audioPlayer.getPlayingTrack() == null) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", null, null, null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    if (musicManager.scheduler.votingGoingOn) {
        EmbedBuilder builder = Embeds.createBuilder(null, "A voting is going on already. Please be patient !", null, null, null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    List<Member> filteredMembers = vc.getMembers().stream().filter(member -> !member.getUser().isBot()).collect(Collectors.toList());
    if (filteredMembers.size() >= 3) {
        musicManager.scheduler.votingGoingOn = true;
        musicManager.scheduler.votes.clear();
        musicManager.scheduler.totalMembers.clear();
        musicManager.scheduler.totalMembers = filteredMembers;
        String unicode = "U+1F44D";
        channel.sendMessageEmbeds(Embeds.createBuilder("Voting starts now", "React with :thumbsup: to vote for next song . I will wait for 20 seconds", "Requested by " + ctx.getMember().getEffectiveName(), ctx.getMember().getEffectiveAvatarUrl(), null).build()).queue((message) -> {
            message.addReaction(unicode).queue();
            this.waiter.waitForEvent(GuildMessageReactionAddEvent.class, (e) -> {
                if (e.getMember().getUser().isBot() || !e.getReactionEmote().getEmoji().equalsIgnoreCase("👍") || !e.getMessageId().equals(message.getId()))
                    return false;
                if (!e.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
                    message.removeReaction(unicode).queue();
                    return false;
                }
                if (!e.getMember().getVoiceState().inVoiceChannel()) {
                    message.removeReaction(unicode).queue();
                    e.getReaction().removeReaction().queue();
                    return false;
                }
                if (!e.getMember().getVoiceState().getChannel().getId().equalsIgnoreCase(e.getGuild().getSelfMember().getVoiceState().getChannel().getId())) {
                    e.getReaction().removeReaction().queue();
                    return false;
                }
                if (musicManager.scheduler.votingGoingOn) {
                    if (musicManager.scheduler.votes.contains(e.getMember())) {
                        e.getReaction().removeReaction().queue();
                        return false;
                    }
                    if (!musicManager.scheduler.totalMembers.contains(e.getMember())) {
                        musicManager.scheduler.totalMembers.add(e.getMember());
                    }
                    musicManager.scheduler.votes.add(e.getMember());
                    return musicManager.scheduler.votes.size() >= Math.ceil(musicManager.scheduler.totalMembers.size() / 2f);
                }
                return false;
            }, (e) -> {
                if (musicManager.scheduler.votes.size() >= Math.ceil(musicManager.scheduler.totalMembers.size() / 2f)) {
                    musicManager.scheduler.totalMembers.clear();
                    musicManager.scheduler.votes.clear();
                    musicManager.scheduler.votingGoingOn = false;
                    // Skip the song
                    musicManager.scheduler.nextTrack();
                    message.delete().queue();
                    EmbedBuilder builder = Embeds.createBuilder(null, "Skipped the current track", null, null, null);
                    channel.sendMessageEmbeds(builder.build()).queue();
                }
            }, 20, TimeUnit.SECONDS, () -> {
                if (musicManager.scheduler.votingGoingOn) {
                    musicManager.scheduler.totalMembers.clear();
                    musicManager.scheduler.votes.clear();
                    musicManager.scheduler.votingGoingOn = false;
                    message.delete().queue();
                    channel.sendMessageEmbeds(Embeds.createBuilder(null, "Voting did not come to an end . Try again next time..", null, null, null).build()).queue();
                }
            });
            this.waiter.waitForEvent(GuildMessageReactionRemoveEvent.class, (e) -> {
                if (e.getMember().getUser().isBot() || !e.getReactionEmote().getEmoji().equalsIgnoreCase("👍") || !e.getMessageId().equals(message.getId()))
                    return false;
                if (!e.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
                    return false;
                }
                if (!e.getMember().getVoiceState().inVoiceChannel()) {
                    return false;
                }
                if (!e.getMember().getVoiceState().getChannel().getId().equalsIgnoreCase(e.getGuild().getSelfMember().getVoiceState().getChannel().getId())) {
                    return false;
                }
                if (musicManager.scheduler.votingGoingOn) {
                    if (musicManager.scheduler.votes.contains(e.getMember())) {
                        musicManager.scheduler.votes = musicManager.scheduler.votes.stream().filter((vote) -> vote != e.getMember()).collect(Collectors.toList());
                        return false;
                    }
                    return musicManager.scheduler.votes.size() >= Math.ceil(musicManager.scheduler.totalMembers.size() / 2f);
                }
                return false;
            }, (e) -> {
                if (musicManager.scheduler.votes.size() >= Math.ceil(musicManager.scheduler.totalMembers.size() / 2f)) {
                    musicManager.scheduler.totalMembers.clear();
                    musicManager.scheduler.votes.clear();
                    musicManager.scheduler.votingGoingOn = false;
                    // Skip the song
                    musicManager.scheduler.nextTrack();
                    message.delete().queue();
                    EmbedBuilder builder = Embeds.createBuilder(null, "Skipped the current track", null, null, null);
                    channel.sendMessageEmbeds(builder.build()).queue();
                }
            }, 20, TimeUnit.SECONDS, () -> {
            });
        });
        return;
    }
    musicManager.scheduler.nextTrack();
    EmbedBuilder builder = Embeds.createBuilder(null, "Skipped the current track", null, null, null);
    channel.sendMessageEmbeds(builder.build()).queue();
}
Also used : AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) GuildMessageReceivedEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent) ICommand(me.fero.ascent.commands.ICommand) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) EventWaiter(com.jagrosh.jdautilities.commons.waiter.EventWaiter) Collectors(java.util.stream.Collectors) GuildMessageReactionRemoveEvent(net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionRemoveEvent) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) TimeUnit(java.util.concurrent.TimeUnit) CommandContext(me.fero.ascent.commands.CommandContext) Embeds(me.fero.ascent.utils.Embeds) List(java.util.List) GuildMessageReactionAddEvent(net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent) PlayerManager(me.fero.ascent.lavaplayer.PlayerManager) TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Member(net.dv8tion.jda.api.entities.Member)

Example 7 with GuildMusicManager

use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.

the class Volume method handle.

@Override
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    List<String> args = ctx.getArgs();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    AudioPlayer audioPlayer = musicManager.scheduler.player;
    if (args.isEmpty()) {
        int result = audioPlayer.getVolume();
        EmbedBuilder builder = Embeds.createBuilder(null, "Current volume is " + result + "%", null, null, null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    int amount = -1;
    try {
        amount = Integer.parseInt(args.get(0));
    } catch (NumberFormatException e) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "Please pass a value between 0-100 for volume", null, null, null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    if (amount < 0 || amount > 100) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "Please pass a value between 0-100 for volume", null, null, null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    audioPlayer.setVolume(amount);
    EmbedBuilder builder = Embeds.createBuilder(null, "Volume changed", null, null, null);
    channel.sendMessageEmbeds(builder.build()).queue();
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer)

Example 8 with GuildMusicManager

use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.

the class Leave method handle.

@Override
@SuppressWarnings("ConstantConditions")
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    final Member member = ctx.getMember();
    final GuildVoiceState memberVoiceState = member.getVoiceState();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    musicManager.scheduler.isRepeating = false;
    musicManager.scheduler.queue.clear();
    musicManager.scheduler.player.startTrack(null, false);
    AudioManager audioManager = ctx.getGuild().getAudioManager();
    audioManager.closeAudioConnection();
    String desc = "Disconnected from " + memberVoiceState.getChannel().getAsMention();
    EmbedBuilder builder = Embeds.createBuilder("Disconnected", desc, "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null);
    channel.sendMessageEmbeds(builder.build()).queue();
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) Member(net.dv8tion.jda.api.entities.Member)

Example 9 with GuildMusicManager

use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.

the class NowPlaying method handle.

@Override
@SuppressWarnings("ConstantConditions")
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    final Member member = ctx.getMember();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    AudioPlayer audioPlayer = musicManager.audioPlayer;
    AudioTrack playingTrack = audioPlayer.getPlayingTrack();
    if (playingTrack == null) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    EmbedBuilder builder = Embeds.songEmbed(member, playingTrack);
    builder.setTitle("Now playing 💿");
    long fullMillis = playingTrack.getPosition();
    String formattedFull;
    if (fullMillis >= 3600000) {
        formattedFull = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(fullMillis), TimeUnit.MILLISECONDS.toMinutes(fullMillis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(fullMillis)), TimeUnit.MILLISECONDS.toSeconds(fullMillis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(fullMillis)));
    } else {
        formattedFull = String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(fullMillis) - // The change is in this line
        TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(fullMillis)), TimeUnit.MILLISECONDS.toSeconds(fullMillis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(fullMillis)));
    }
    if (!playingTrack.getInfo().isStream) {
        builder.addField("Current position", formattedFull + " minutes", false);
    }
    channel.sendMessageEmbeds(builder.build()).queue();
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) Member(net.dv8tion.jda.api.entities.Member)

Example 10 with GuildMusicManager

use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.

the class Pause method handle.

@Override
@SuppressWarnings("ConstantConditions")
public void handle(@NotNull CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    final Member member = ctx.getMember();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    AudioPlayer audioPlayer = musicManager.audioPlayer;
    if (audioPlayer.getPlayingTrack() == null) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    AudioPlayer player = musicManager.scheduler.player;
    if (player.isPaused()) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "Player is already paused", "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    player.setPaused(true);
    EmbedBuilder builder = Embeds.createBuilder(null, "Player paused", "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null);
    channel.sendMessageEmbeds(builder.build()).queue();
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) Member(net.dv8tion.jda.api.entities.Member)

Aggregations

GuildMusicManager (me.fero.ascent.lavaplayer.GuildMusicManager)26 TextChannel (net.dv8tion.jda.api.entities.TextChannel)21 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)15 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)13 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)8 Member (net.dv8tion.jda.api.entities.Member)8 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)5 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)5 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ParseException (org.apache.hc.core5.http.ParseException)4 SpotifyWebApiException (se.michaelthelin.spotify.exceptions.SpotifyWebApiException)4 List (java.util.List)3 Matcher (java.util.regex.Matcher)3 AudioManager (net.dv8tion.jda.api.managers.AudioManager)3 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)2 HashMap (java.util.HashMap)2 SelectionMenu (net.dv8tion.jda.api.interactions.components.selections.SelectionMenu)2 EventWaiter (com.jagrosh.jdautilities.commons.waiter.EventWaiter)1