Search in sources :

Example 1 with GuildAudioPlayer

use of at.xirado.bean.music.GuildAudioPlayer 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 GuildAudioPlayer

use of at.xirado.bean.music.GuildAudioPlayer in project Bean by Xirado.

the class PlayerCommand method executeCommand.

@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
    GuildAudioPlayer player = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
    AudioTrack track = player.getPlayer().getPlayingTrack();
    boolean isRepeat = player.getScheduler().isRepeat();
    boolean isPaused = player.getPlayer().isPaused();
    event.reply("One moment...").queue(x -> player.playerSetup((GuildMessageChannel) event.getChannel(), (success) -> event.getHook().deleteOriginal().queue(), (error) -> event.reply("An error occurred!").setEphemeral(true).queue()));
}
Also used : Commands(net.dv8tion.jda.api.interactions.commands.build.Commands) SlashCommandContext(at.xirado.bean.command.SlashCommandContext) GuildAudioPlayer(at.xirado.bean.music.GuildAudioPlayer) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) SlashCommand(at.xirado.bean.command.SlashCommand) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildMessageChannel(net.dv8tion.jda.api.entities.GuildMessageChannel) Bean(at.xirado.bean.Bean) NotNull(org.jetbrains.annotations.NotNull) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildAudioPlayer(at.xirado.bean.music.GuildAudioPlayer) GuildMessageChannel(net.dv8tion.jda.api.entities.GuildMessageChannel)

Example 3 with GuildAudioPlayer

use of at.xirado.bean.music.GuildAudioPlayer in project Bean by Xirado.

the class Shutdown method executeCommand.

@Override
public void executeCommand(String invoke, String[] args) {
    Set<GuildAudioPlayer> audioPlayers = Bean.getInstance().getAudioManager().getAudioPlayers();
    if (args.length == 0 || !args[0].equalsIgnoreCase("-f")) {
        int playing = audioPlayers.stream().mapToInt(pl -> pl.getPlayer().getPlayingTrack() == null ? 0 : 1).sum();
        int mee6QueueSize = Bean.getInstance().getMEE6Queue().getQueue().size();
        if (playing > 0)
            Shell.println(MCColor.translate('&', "&eCareful: There are &2" + playing + "&e players running! Use shutdown -f to force-shutdown."));
        if (mee6QueueSize > 0)
            Shell.println(MCColor.translate('&', "&eCareful: There are &2" + mee6QueueSize + "&e pending MEE6 requests!"));
        if (playing > 0 || mee6QueueSize > 0)
            return;
    }
    logger.info("Shutting down...");
    logger.info("Deleting player messages...");
    audioPlayers.forEach(pl -> {
        if (pl.getOpenPlayer() != null)
            pl.getOpenPlayer().delete().complete();
    });
    logger.info("Destroying players...");
    audioPlayers.forEach(GuildAudioPlayer::destroy);
    Bean.getInstance().getShardManager().shutdown();
    logger.info("Awaiting JDA ShardManager shutdown...");
    for (JDA jda : Bean.getInstance().getShardManager().getShards()) {
        while (jda.getStatus() != JDA.Status.SHUTDOWN) {
            Thread.onSpinWait();
        }
    }
    logger.info("Stopped all shards");
    logger.info("Goodbye");
    System.exit(0);
}
Also used : JDA(net.dv8tion.jda.api.JDA) Logger(org.slf4j.Logger) MCColor(at.xirado.bean.log.MCColor) GuildAudioPlayer(at.xirado.bean.music.GuildAudioPlayer) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Bean(at.xirado.bean.Bean) ConsoleCommand(at.xirado.bean.command.ConsoleCommand) Shell(at.xirado.bean.log.Shell) JDA(net.dv8tion.jda.api.JDA) GuildAudioPlayer(at.xirado.bean.music.GuildAudioPlayer)

Example 4 with GuildAudioPlayer

use of at.xirado.bean.music.GuildAudioPlayer in project Bean by Xirado.

the class JoinCommand method executeCommand.

@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
    Member member = event.getMember();
    GuildVoiceState voiceState = member.getVoiceState();
    if (voiceState.getChannel() == null) {
        event.replyEmbeds(EmbedUtil.errorEmbed("You must be listening in a voice channel to run this command!")).queue();
        return;
    }
    GuildVoiceState state = event.getGuild().getSelfMember().getVoiceState();
    if (state.getChannel() != null) {
        AudioChannel channel = state.getChannel();
        if (voiceState.getChannel().getIdLong() == channel.getIdLong()) {
            event.replyEmbeds(EmbedUtil.errorEmbed("I already joined this channel!")).queue();
            return;
        }
        if (Util.getListeningUsers(channel) > 0) {
            event.replyEmbeds(EmbedUtil.errorEmbed("I am already playing music in **" + channel.getName() + "**!")).queue();
            return;
        }
    }
    GuildAudioPlayer audioPlayer = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
    try {
        audioPlayer.getLink().connect(voiceState.getChannel());
    } catch (PermissionException exception) {
        event.replyEmbeds(EmbedUtil.errorEmbed("I do not have permission to join this channel!")).queue();
        return;
    }
    event.replyEmbeds(EmbedUtil.successEmbed("Joined <#" + voiceState.getChannel().getIdLong() + ">!")).setEphemeral(true).queue();
    audioPlayer.playerSetup((GuildMessageChannel) event.getChannel(), (s) -> {
    }, e -> {
    });
}
Also used : PermissionException(net.dv8tion.jda.api.exceptions.PermissionException) AudioChannel(net.dv8tion.jda.api.entities.AudioChannel) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) GuildAudioPlayer(at.xirado.bean.music.GuildAudioPlayer) Member(net.dv8tion.jda.api.entities.Member)

Example 5 with GuildAudioPlayer

use of at.xirado.bean.music.GuildAudioPlayer in project Bean by Xirado.

the class PauseCommand method executeCommand.

@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
    JdaLink link = Bean.getInstance().getLavalink().getLink(event.getGuild());
    LavalinkPlayer player = link.getPlayer();
    GuildAudioPlayer guildAudioPlayer = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
    if (player.getPlayingTrack() == null) {
        ctx.replyError("I'm currently not playing any music!").setEphemeral(true).queue();
        return;
    }
    if (player.isPaused()) {
        ctx.replyError("The player is already paused! Use `/resume`").setEphemeral(true).queue();
        return;
    }
    player.setPaused(true);
    guildAudioPlayer.forcePlayerComponentsUpdate();
    ctx.sendSimpleEphemeralEmbed("The player is now paused!");
}
Also used : GuildAudioPlayer(at.xirado.bean.music.GuildAudioPlayer) JdaLink(lavalink.client.io.jda.JdaLink) LavalinkPlayer(lavalink.client.player.LavalinkPlayer)

Aggregations

GuildAudioPlayer (at.xirado.bean.music.GuildAudioPlayer)14 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)7 TrackInfo (at.xirado.bean.misc.objects.TrackInfo)4 Bean (at.xirado.bean.Bean)3 GuildVoiceState (net.dv8tion.jda.api.entities.GuildVoiceState)3 SlashCommand (at.xirado.bean.command.SlashCommand)2 SlashCommandContext (at.xirado.bean.command.SlashCommandContext)2 ArrayList (java.util.ArrayList)2 JdaLink (lavalink.client.io.jda.JdaLink)2 LavalinkPlayer (lavalink.client.player.LavalinkPlayer)2 SlashCommandInteractionEvent (net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent)2 Commands (net.dv8tion.jda.api.interactions.commands.build.Commands)2 NotNull (org.jetbrains.annotations.NotNull)2 ConsoleCommand (at.xirado.bean.command.ConsoleCommand)1 GuildData (at.xirado.bean.data.GuildData)1 ButtonPaginator (at.xirado.bean.interactions.ButtonPaginator)1 MCColor (at.xirado.bean.log.MCColor)1 Shell (at.xirado.bean.log.Shell)1 FormatUtil (at.xirado.bean.misc.FormatUtil)1 Util (at.xirado.bean.misc.Util)1