Search in sources :

Example 1 with SelectMenuInteractionEvent

use of net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent in project OrderlyDiscordBot by IceLeiYu.

the class MusicBot method displayQueue.

public void displayQueue(GenericInteractionCreateEvent event, boolean search, Guild guild, SelectMenuInteractionEvent SelectMenuInteractionEvent) {
    List<String> lang = Main.language.getGuildLang(guild.getId());
    GuildMusicManager musicManager = getMusicManager(guild);
    TrackScheduler scheduler = musicManager.scheduler;
    if (scheduler.musicInfo == null) {
        try {
            if (event instanceof SelectMenuInteractionEvent)
                ((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_MUSIC), 0xFF0000)).queue();
        } catch (Exception ignored) {
        }
        return;
    }
    scheduler.calculatePauseTime();
    MessageEmbed[] embed = playStatus(event.getMember(), scheduler);
    if (musicManager.guild.getSelfMember().getVoiceState().getChannel() == null) {
        if (search)
            SelectMenuInteractionEvent.replyEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).setEphemeral(true).queue();
        else {
            if (event instanceof SelectMenuInteractionEvent)
                ((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).queue();
            else if (event instanceof SlashCommandInteractionEvent)
                ((SlashCommandInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).queue();
        }
        return;
    }
    String vcID = musicManager.guild.getSelfMember().getVoiceState().getChannel().getId();
    if (search) {
        SelectMenuInteractionEvent.replyEmbeds(embed[0], embed[1]).setEphemeral(true).addActionRows(controlButtons(event.getMember().getId(), scheduler.musicPause, scheduler.loopStatus, vcID)).queue();
    } else {
        if (event instanceof SelectMenuInteractionEvent)
            ((SelectMenuInteractionEvent) event).getHook().editOriginalComponents().setEmbeds(embed[0], embed[1]).setActionRows(controlButtons(event.getMember().getId(), scheduler.musicPause, scheduler.loopStatus, vcID)).queue();
        else if (event instanceof SlashCommandInteractionEvent)
            ((SlashCommandInteractionEvent) event).getHook().editOriginalComponents().setEmbeds(embed[0], embed[1]).setActionRows(controlButtons(event.getMember().getId(), scheduler.musicPause, scheduler.loopStatus, vcID)).queue();
    }
    if (event.getGuild().getId().equals("882605953382514718"))
        event.getGuild().getTextChannelById("884070398742888478").sendMessageEmbeds(embed[0], embed[1]).setActionRows(controlButtons("", scheduler.musicPause, scheduler.loopStatus, vcID)).content(event.getUser().getAsTag()).queue();
}
Also used : SelectMenuInteractionEvent(net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent) GuildMusicManager(com.ice.multiBot.music.GuildMusicManager) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) TrackScheduler(com.ice.multiBot.music.TrackScheduler)

Example 2 with SelectMenuInteractionEvent

use of net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent in project OrderlyDiscordBot by IceLeiYu.

the class MusicBot method connectVC.

@SuppressWarnings("ALL")
private void connectVC(Guild guild, VoiceChannel vc, GenericInteractionCreateEvent event, Consumer consumer) {
    if (!guild.getAudioManager().isConnected()) {
        try {
            guild.getAudioManager().openAudioConnection(vc);
        } catch (Exception e) {
            List<String> lang = Main.language.getGuildLang(event.getGuild().getId());
            if (event instanceof SelectMenuInteractionEvent)
                ((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).queue();
            else if (event instanceof SlashCommandInteractionEvent)
                ((SlashCommandInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).queue();
            return;
        }
        final MusicBot bot = this;
        guild.getAudioManager().setConnectionListener(new ConnectionListener() {

            @Override
            public void onStatusChange(ConnectionStatus connectionStatus) {
                if (connectionStatus == ConnectionStatus.CONNECTED) {
                    consumer.accept(null);
                    if (workCount == 0) {
                        jda.getPresence().setStatus(OnlineStatus.DO_NOT_DISTURB);
                        jda.getPresence().setActivity(Activity.of(Activity.ActivityType.COMPETING, "來點歌吧!"));
                    }
                    workCount++;
                    jda.getPresence().setActivity(Activity.of(Activity.ActivityType.LISTENING, workCount + " 個頻道"));
                    guild.getAudioManager().setConnectionListener(null);
                    // 新增bot到頻道
                    musicBotManager.setBotToChannel(guild.getId(), vc.getId(), bot);
                    if (guild.getSelfMember().getPermissions().contains(Permission.VOICE_DEAF_OTHERS))
                        guild.getSelfMember().deafen(true).queue();
                }
            }

            @Override
            public void onPing(long l) {
            }

            @Override
            public void onUserSpeaking(User user, boolean b) {
            }
        });
    } else
        consumer.accept(null);
}
Also used : SelectMenuInteractionEvent(net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) List(java.util.List) ConnectionListener(net.dv8tion.jda.api.audio.hooks.ConnectionListener) ConnectionStatus(net.dv8tion.jda.api.audio.hooks.ConnectionStatus) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 3 with SelectMenuInteractionEvent

use of net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent in project OrderlyDiscordBot by IceLeiYu.

the class MusicBot method loadAndPlay.

public void loadAndPlay(final GenericInteractionCreateEvent event, Guild guild, final String trackUrl, boolean search, boolean playNow, SelectMenuInteractionEvent SelectMenuInteractionEvent) {
    List<String> lang = Main.language.getGuildLang(guild.getId());
    VoiceChannel vc = (VoiceChannel) event.getMember().getVoiceState().getChannel();
    GuildMusicManager manager = getMusicManager(jda.getGuildById(guild.getId()));
    // 取得音樂
    playerManager.loadItemOrdered(musicManagers, trackUrl, new AudioLoadResultHandler() {

        @Override
        public void trackLoaded(AudioTrack track) {
            play(track, vc, manager, event, search, playNow, SelectMenuInteractionEvent);
        }

        @Override
        public void playlistLoaded(AudioPlaylist playlist) {
            play(playlist, vc, manager, event, playNow);
        }

        @Override
        public void noMatches() {
            try {
                if (event instanceof SelectMenuInteractionEvent)
                    ((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_URL_NOT_FOUND) + ": " + trackUrl, 0xFF0000)).queue();
                else if (event instanceof SlashCommandInteractionEvent)
                    ((SlashCommandInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_URL_NOT_FOUND) + ": " + trackUrl, 0xFF0000)).queue();
            } catch (Exception ignored) {
            }
        }

        @Override
        public void loadFailed(FriendlyException exception) {
            try {
                if (event instanceof SelectMenuInteractionEvent)
                    ((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_CANT_PLAY_URL) + ": " + exception.getMessage(), 0xFF0000)).queue();
                else if (event instanceof SlashCommandInteractionEvent)
                    ((SlashCommandInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_CANT_PLAY_URL) + ": " + exception.getMessage(), 0xFF0000)).queue();
            } catch (Exception ignored) {
            }
        }
    });
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) SelectMenuInteractionEvent(net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent) GuildMusicManager(com.ice.multiBot.music.GuildMusicManager) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Aggregations

FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)3 SlashCommandInteractionEvent (net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent)3 SelectMenuInteractionEvent (net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent)3 GuildMusicManager (com.ice.multiBot.music.GuildMusicManager)2 TrackScheduler (com.ice.multiBot.music.TrackScheduler)1 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)1 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 List (java.util.List)1 ConnectionListener (net.dv8tion.jda.api.audio.hooks.ConnectionListener)1 ConnectionStatus (net.dv8tion.jda.api.audio.hooks.ConnectionStatus)1