Search in sources :

Example 31 with GuildVoiceState

use of net.dv8tion.jda.api.entities.GuildVoiceState in project discord-bot-reddit-java by Glaxier0.

the class SkipCommand method execute.

@Override
public void execute(SlashCommandInteractionEvent event) {
    GuildVoiceState botVoiceState = event.getGuild().getSelfMember().getVoiceState();
    GuildVoiceState userVoiceState = event.getMember().getVoiceState();
    if (utils.channelControl(botVoiceState, userVoiceState)) {
        PlayerManager.getInstance().getMusicManager(event).scheduler.nextTrack();
        event.replyEmbeds(new EmbedBuilder().setDescription("Song skipped").setColor(Color.GREEN).build()).queue();
    } else {
        event.replyEmbeds(new EmbedBuilder().setDescription("Please be in a same voice channel as bot.").setColor(Color.RED).build()).queue();
    }
    net.dv8tion.jda.api.entities.User user = event.getUser();
    utils.counter(user.getId(), user.getAsTag());
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState)

Example 32 with GuildVoiceState

use of net.dv8tion.jda.api.entities.GuildVoiceState in project discord-bot-reddit-java by Glaxier0.

the class SwapCommand method execute.

@Override
public void execute(SlashCommandInteractionEvent event) {
    GuildVoiceState botVoiceState = event.getGuild().getSelfMember().getVoiceState();
    GuildVoiceState userVoiceState = event.getMember().getVoiceState();
    if (utils.channelControl(botVoiceState, userVoiceState)) {
        GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event);
        List<AudioTrack> trackList = new ArrayList<>(musicManager.scheduler.queue);
        if (trackList.size() > 1) {
            int first = event.getOption("songnum1").getAsInt() - 1;
            int second = event.getOption("songnum2").getAsInt() - 1;
            try {
                AudioTrack temp = trackList.get(first);
                trackList.set(first, trackList.get(second));
                trackList.set(second, temp);
            } catch (Exception e) {
                event.replyEmbeds(new EmbedBuilder().setDescription("Please enter a valid queue ids for both of the songs.").setColor(Color.RED).build()).queue();
                return;
            }
            musicManager.scheduler.queue.clear();
            for (AudioTrack track : trackList) {
                musicManager.scheduler.queue(track);
            }
            event.replyEmbeds(new EmbedBuilder().setDescription("Successfully swapped order of two songs").setColor(Color.GREEN).build()).queue();
        } else if (trackList.size() == 1) {
            event.replyEmbeds(new EmbedBuilder().setDescription("There is only one song in queue.").setColor(Color.RED).build()).queue();
        } else {
            event.replyEmbeds(new EmbedBuilder().setDescription("Queue is empty.").setColor(Color.RED).build()).queue();
        }
    } else {
        event.replyEmbeds(new EmbedBuilder().setDescription("Please be in a same voice channel as bot.").setColor(Color.RED).build()).queue();
    }
    net.dv8tion.jda.api.entities.User user = event.getUser();
    utils.counter(user.getId(), user.getAsTag());
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(com.discord.bot.audioplayer.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 33 with GuildVoiceState

use of net.dv8tion.jda.api.entities.GuildVoiceState in project toby-bot by ml404.

the class SetVolumeCommand 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 Member self = ctx.getSelfMember();
    final GuildVoiceState selfVoiceState = self.getVoiceState();
    if (!requestingUserDto.hasMusicPermission()) {
        sendErrorMessage(ctx, channel, deleteDelay);
        return;
    }
    if (ctx.getArgs().isEmpty()) {
        channel.sendMessage(getHelp(prefix)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
        return;
    }
    if (IMusicCommand.isInvalidChannelStateForCommand(ctx, channel, deleteDelay))
        return;
    final Member member = ctx.getMember();
    setNewVolume(ctx, prefix, channel, member, deleteDelay);
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) Member(net.dv8tion.jda.api.entities.Member)

Example 34 with GuildVoiceState

use of net.dv8tion.jda.api.entities.GuildVoiceState in project toby-bot by ml404.

the class JoinCommand method doJoinChannelValidation.

private GuildVoiceState doJoinChannelValidation(CommandContext ctx, TextChannel channel, Integer deleteDelay) {
    final Member self = ctx.getSelfMember();
    final GuildVoiceState selfVoiceState = self.getVoiceState();
    if (selfVoiceState.inVoiceChannel()) {
        channel.sendMessage("I'm already in a voice channel").queue(message -> ICommand.deleteAfter(message, deleteDelay));
        return null;
    }
    final Member member = ctx.getMember();
    final GuildVoiceState memberVoiceState = member.getVoiceState();
    if (!memberVoiceState.inVoiceChannel()) {
        channel.sendMessage("You need to be in a voice channel for this command to work").queue(message -> ICommand.deleteAfter(message, deleteDelay));
        return null;
    }
    return memberVoiceState;
}
Also used : GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) Member(net.dv8tion.jda.api.entities.Member)

Example 35 with GuildVoiceState

use of net.dv8tion.jda.api.entities.GuildVoiceState in project toby-bot by ml404.

the class JoinCommand 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 Member self = ctx.getSelfMember();
    if (!requestingUserDto.hasMusicPermission()) {
        sendErrorMessage(ctx, channel, deleteDelay);
        return;
    }
    final GuildVoiceState memberVoiceState = doJoinChannelValidation(ctx, channel, deleteDelay);
    if (memberVoiceState == null)
        return;
    final AudioManager audioManager = ctx.getGuild().getAudioManager();
    final VoiceChannel memberChannel = memberVoiceState.getChannel();
    if (self.hasPermission(Permission.VOICE_CONNECT)) {
        audioManager.openAudioConnection(memberChannel);
        String volumePropertyName = ConfigDto.Configurations.VOLUME.getConfigValue();
        ConfigDto databaseConfig = configService.getConfigByName(volumePropertyName, ctx.getGuild().getId());
        int defaultVolume = databaseConfig != null ? Integer.parseInt(databaseConfig.getValue()) : 100;
        PlayerManager.getInstance().getMusicManager(ctx.getGuild()).getAudioPlayer().setVolume(defaultVolume);
        channel.sendMessageFormat("Connecting to `\uD83D\uDD0A %s` with volume '%s'", memberChannel.getName(), defaultVolume).queue(message -> ICommand.deleteAfter(message, deleteDelay));
    }
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) TextChannel(net.dv8tion.jda.api.entities.TextChannel) ConfigDto(toby.jpa.dto.ConfigDto) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Member(net.dv8tion.jda.api.entities.Member)

Aggregations

GuildVoiceState (net.dv8tion.jda.api.entities.GuildVoiceState)51 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)16 Member (net.dv8tion.jda.api.entities.Member)16 LogUtils (main.utils.json.logs.LogUtils)13 AudioManager (net.dv8tion.jda.api.managers.AudioManager)12 Guild (net.dv8tion.jda.api.entities.Guild)11 TextChannel (net.dv8tion.jda.api.entities.TextChannel)9 VoiceChannel (net.dv8tion.jda.api.entities.VoiceChannel)9 ArrayList (java.util.ArrayList)7 Permission (net.dv8tion.jda.api.Permission)5 CommandFlag (at.xirado.bean.command.CommandFlag)4 SlashCommand (at.xirado.bean.command.SlashCommand)4 SlashCommandContext (at.xirado.bean.command.SlashCommandContext)4 EmbedUtil (at.xirado.bean.misc.EmbedUtil)4 Message (net.dv8tion.jda.api.entities.Message)4 Bean (at.xirado.bean.Bean)3 GenericCommand (at.xirado.bean.command.GenericCommand)3 MessageContextCommand (at.xirado.bean.command.context.MessageContextCommand)3 UserContextCommand (at.xirado.bean.command.context.UserContextCommand)3 MockContextMenuCommand (at.xirado.bean.command.context.message.MockContextMenuCommand)3