Search in sources :

Example 1 with TrackInfo

use of at.xirado.bean.misc.objects.TrackInfo in project Bean by Xirado.

the class ClearCommand method executeCommand.

@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
    GuildVoiceState state = event.getGuild().getSelfMember().getVoiceState();
    if (state.getChannel() == null) {
        event.replyEmbeds(EmbedUtil.warningEmbed("I am not connected to a voice channel!")).setEphemeral(true).queue();
        return;
    }
    GuildAudioPlayer player = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
    if (player.getScheduler().getQueue().isEmpty()) {
        event.replyEmbeds(EmbedUtil.warningEmbed("The queue is already empty!")).setEphemeral(true).queue();
        return;
    }
    if (Util.getListeningUsers(state.getChannel()) == 1) {
        player.getScheduler().getQueue().clear();
        event.replyEmbeds(EmbedUtil.defaultEmbed("Cleared the queue!")).setEphemeral(true).queue();
        player.forcePlayerUpdate();
        return;
    }
    if (!ctx.getGuildData().isDJ(event.getMember())) {
        boolean allowedToStop = true;
        long userId = event.getUser().getIdLong();
        List<AudioTrack> tracks = new ArrayList<>(player.getScheduler().getQueue());
        for (AudioTrack track : tracks) {
            TrackInfo trackInfo = track.getUserData(TrackInfo.class);
            if (trackInfo.getRequesterIdLong() != userId) {
                allowedToStop = false;
                break;
            }
        }
        if (!allowedToStop) {
            event.replyEmbeds(EmbedUtil.errorEmbed("You need to be a DJ to do this!")).setEphemeral(true).queue();
            return;
        }
    }
    player.getScheduler().getQueue().clear();
    event.replyEmbeds(EmbedUtil.defaultEmbed("Cleared the queue!")).setEphemeral(true).queue();
    player.forcePlayerUpdate();
}
Also used : TrackInfo(at.xirado.bean.misc.objects.TrackInfo) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildAudioPlayer(at.xirado.bean.music.GuildAudioPlayer)

Example 2 with TrackInfo

use of at.xirado.bean.misc.objects.TrackInfo in project Bean by Xirado.

the class StopCommand method executeCommand.

@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
    GuildVoiceState state = event.getGuild().getSelfMember().getVoiceState();
    if (state.getChannel() == null) {
        event.replyEmbeds(EmbedUtil.warningEmbed("I am not connected to a voice channel!")).queue();
        return;
    }
    GuildAudioPlayer player = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
    if (player.getPlayer().getPlayingTrack() == null || Util.getListeningUsers(state.getChannel()) == 1) {
        String name = state.getChannel().getName();
        player.destroy();
        event.replyEmbeds(EmbedUtil.defaultEmbed("Disconnected from **" + name + "**!")).queue();
        player.setOpenPlayer(null);
        return;
    }
    if (!ctx.getGuildData().isDJ(event.getMember())) {
        boolean allowedToStop = true;
        long userId = event.getUser().getIdLong();
        List<AudioTrack> tracks = new ArrayList<>(player.getScheduler().getQueue());
        tracks.add(player.getPlayer().getPlayingTrack());
        for (AudioTrack track : tracks) {
            TrackInfo trackInfo = track.getUserData(TrackInfo.class);
            if (trackInfo.getRequesterIdLong() != userId) {
                allowedToStop = false;
                break;
            }
        }
        if (!allowedToStop) {
            event.replyEmbeds(EmbedUtil.errorEmbed("You need to be a DJ to do this!")).queue();
            return;
        }
    }
    player.setOpenPlayer(null);
    String name = state.getChannel().getName();
    player.destroy();
    event.replyEmbeds(EmbedUtil.defaultEmbed("Disconnected from **" + name + "**!")).queue();
}
Also used : TrackInfo(at.xirado.bean.misc.objects.TrackInfo) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildAudioPlayer(at.xirado.bean.music.GuildAudioPlayer)

Example 3 with TrackInfo

use of at.xirado.bean.misc.objects.TrackInfo in project Bean by Xirado.

the class VoteSkipCommand method executeCommand.

@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
    GuildAudioPlayer guildAudioPlayer = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
    if (event.getMember().getVoiceState().isDeafened()) {
        ctx.sendSimpleEphemeralEmbed("You can't do this since you're deafened!");
        return;
    }
    AudioTrack track = guildAudioPlayer.getPlayer().getPlayingTrack();
    if (track == null) {
        ctx.sendSimpleEphemeralEmbed("There is no music to skip!");
        return;
    }
    TrackInfo trackInfo = track.getUserData(TrackInfo.class);
    long requester = trackInfo.getRequesterIdLong();
    if (event.getUser().getIdLong() == requester) {
        if (guildAudioPlayer.getScheduler().isRepeat())
            guildAudioPlayer.getScheduler().setRepeat(false);
        guildAudioPlayer.getScheduler().nextTrack();
        AudioTrack nextTrack = guildAudioPlayer.getPlayer().getPlayingTrack();
        if (nextTrack == null) {
            ctx.sendSimpleEphemeralEmbed("**Skipped!**");
            guildAudioPlayer.forcePlayerUpdate();
            return;
        }
        ctx.sendSimpleEphemeralEmbed("**Skipped!** Now playing " + Util.titleMarkdown(nextTrack));
        guildAudioPlayer.forcePlayerUpdate();
        return;
    }
    int listeners = (int) event.getMember().getVoiceState().getChannel().getMembers().stream().filter(m -> !m.getUser().isBot() && !m.getVoiceState().isDeafened()).count();
    if (trackInfo.getVoteSkips().contains(event.getUser().getIdLong())) {
        ctx.sendSimpleEphemeralEmbed("You already voted to skip this song!");
        return;
    }
    trackInfo.addVoteSkip(event.getMember().getIdLong());
    int skippers = (int) event.getMember().getVoiceState().getChannel().getMembers().stream().filter(m -> trackInfo.getVoteSkips().contains(m.getIdLong())).count();
    int required = (int) Math.ceil(listeners * .55);
    if (skippers >= required) {
        if (guildAudioPlayer.getScheduler().isRepeat())
            guildAudioPlayer.getScheduler().setRepeat(false);
        guildAudioPlayer.getScheduler().nextTrack();
        AudioTrack nextTrack = guildAudioPlayer.getPlayer().getPlayingTrack();
        if (nextTrack == null) {
            ctx.sendSimpleEphemeralEmbed("**Skipped!**");
            guildAudioPlayer.forcePlayerUpdate();
            return;
        }
        ctx.sendSimpleEphemeralEmbed("**Skipped!** Now playing " + Util.titleMarkdown(nextTrack));
        guildAudioPlayer.forcePlayerUpdate();
    } else {
        ctx.sendSimpleEphemeralEmbed("Voted to skip: **" + (required - skippers) + "** more votes needed");
        guildAudioPlayer.forcePlayerUpdate();
    }
}
Also used : TrackInfo(at.xirado.bean.misc.objects.TrackInfo) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildAudioPlayer(at.xirado.bean.music.GuildAudioPlayer)

Aggregations

TrackInfo (at.xirado.bean.misc.objects.TrackInfo)3 GuildAudioPlayer (at.xirado.bean.music.GuildAudioPlayer)3 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)3 ArrayList (java.util.ArrayList)2 GuildVoiceState (net.dv8tion.jda.api.entities.GuildVoiceState)2