Search in sources :

Example 1 with GuildMusicManager

use of com.ice.multiBot.music.GuildMusicManager 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 GuildMusicManager

use of com.ice.multiBot.music.GuildMusicManager in project OrderlyDiscordBot by IceLeiYu.

the class MusicBot method getMusicManager.

private GuildMusicManager getMusicManager(Guild guild) {
    GuildMusicManager musicManager = musicManagers.get(guild.getId());
    if (musicManager == null) {
        musicManager = new GuildMusicManager(playerManager, guild, this);
        musicManager.scheduler.setManagerEvent(event);
        musicManagers.put(guild.getId(), musicManager);
    }
    return musicManager;
}
Also used : GuildMusicManager(com.ice.multiBot.music.GuildMusicManager)

Example 3 with GuildMusicManager

use of com.ice.multiBot.music.GuildMusicManager in project OrderlyDiscordBot by IceLeiYu.

the class MultiMusicBotManager method play.

private void play(SlashCommandInteractionEvent event, MusicBot bot, boolean playNow) {
    List<String> lang = Main.language.getGuildLang(event.getGuild().getId());
    if (event.getOptions().size() > 0) {
        if (checkVcState(event, event.getHook())) {
            if (bot == null)
                // 取得機器人
                for (MusicBot thisBot : bots.values()) {
                    GuildMusicManager manager = thisBot.getMusicManager(event.getGuild().getId());
                    if (manager != null && manager.scheduler.musicInfo == null) {
                        bot = thisBot;
                        commandState = 1;
                        break;
                    }
                }
            if (bot == null) {
                event.getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_MG_ALL_BOT_USED), 0xFF0000)).queue();
                commandState = -1;
                return;
            }
            // 開始撥放
            OptionMapping url = event.getOption(NAME);
            if (Pattern.matches(".*\\.?youtu\\.?be(\\.com)?/+.*", url.getAsString())) {
                bot.loadAndPlay(event, event.getGuild(), url.getAsString(), false, playNow, null);
            } else if (Pattern.matches(".*open.spotify.com/playlist/\\w*", url.getAsString())) {
                bot.loadAndPlaySpotify(event, event.getGuild(), url.getAsString(), false, playNow, null);
            } else {
                // if (true) {
                // event.getHook().editOriginalEmbeds(createEmbed("目前 YouTube API 無法使用搜尋功能!正在等待修復", 0xFF0000)).queue();
                // return;
                // }
                String keyWord = URLEncoder.encode(event.getOption(NAME).getAsString(), UTF_8);
                SelectMenu.Builder builder = SelectMenu.create("MultiMusicBotManager:searchResult:" + event.getUser().getId() + ':' + bot.getID() + ':' + playNow);
                String result = getData("https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&type=video&q=" + keyWord + "&key=" + YT_APIKEY);
                if (result == null)
                    return;
                JSONArray videoInfo = new JSONObject(result).getJSONArray("items");
                for (Object vinfo : videoInfo) {
                    JSONObject snippet = ((JSONObject) vinfo).getJSONObject("snippet");
                    String title;
                    String channelOwner;
                    if ((channelOwner = snippet.getString("channelTitle")).length() > 25)
                        channelOwner = channelOwner.substring(0, 24) + "…";
                    if ((title = snippet.getString("title")).length() > 50)
                        title = title.substring(0, 49) + "…";
                    builder.addOption(channelOwner, ((JSONObject) vinfo).getJSONObject("id").getString("videoId"), title, Emoji.fromEmote(emoji.youtubeIcon));
                }
                if (builder.getOptions().size() == 0) {
                    event.getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_MG_SEARCH_NO_RESULT), 0xFF0000)).queue();
                } else
                    event.getHook().editOriginalComponents().setEmbeds(createEmbed(lang.get(MUSICBOT_MG_SEARCH), 0xa3d7fe)).setActionRow(builder.build()).queue();
            }
        }
    } else {
        if (bot.getMusicManager(event.getGuild().getId()).scheduler.musicPause) {
            bot.play(event, event.getGuild());
            event.getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_MG_START_PLAY), 0xbde3ae)).queue();
        } else
            event.getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_MG_START_PLAY_ALREADY), 0xFF0000)).queue();
    }
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) JSONObject(org.json.JSONObject) GuildMusicManager(com.ice.multiBot.music.GuildMusicManager) JDABuilder(net.dv8tion.jda.api.JDABuilder) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject)

Example 4 with GuildMusicManager

use of com.ice.multiBot.music.GuildMusicManager in project OrderlyDiscordBot by IceLeiYu.

the class MultiMusicBotManager method onButton.

public void onButton(ButtonInteractionEvent event, String[] args) {
    List<String> lang = Main.language.getGuildLang(event.getGuild().getId());
    if (!args[0].equals("MusicBot"))
        return;
    if (!checkVcState(event, event.getHook()))
        return;
    if (!event.getMember().getVoiceState().getChannel().getId().equals(args[4])) {
        event.deferEdit().setEmbeds(createEmbed(lang.get(MUSICBOT_MG_UNKNOWN_CHANNEL_BUTTON), 0xFF0000)).setActionRows().queue();
        return;
    }
    MusicBot bot = bots.get(args[3]);
    GuildMusicManager manager = bot.getMusicManager(event.getGuild().getId());
    TrackScheduler scheduler = manager.scheduler;
    int volume;
    switch(args[1]) {
        case "loopChange":
            {
                switch(scheduler.loopStatus = (scheduler.loopStatus + 1) % 3) {
                    case 0:
                        scheduler.repeat = false;
                        scheduler.loop = false;
                        break;
                    case 1:
                        scheduler.repeat = false;
                        scheduler.loop = true;
                        break;
                    case 2:
                        scheduler.repeat = true;
                        scheduler.loop = false;
                        break;
                    default:
                        return;
                }
                break;
            }
        case "pauseToggle":
            scheduler.switchPause();
            break;
        case "next":
            scheduler.nextTrack(null, false);
            break;
        case "volumeUp":
            volume = scheduler.getVolume() + 5;
            scheduler.setVolume(Math.min(volume, 100), null);
            break;
        case "volumeDown":
            volume = scheduler.getVolume() - 5;
            scheduler.setVolume(Math.max(volume, 0), null);
            break;
        default:
    }
    // 如果是等待的話要加時間
    scheduler.calculatePauseTime();
    GuildMusicManager musicManager = bot.getMusicManager(event.getGuild().getId());
    VoiceChannel vc = (VoiceChannel) musicManager.guild.getSelfMember().getVoiceState().getChannel();
    if (vc == null) {
        event.editMessageEmbeds(createEmbed(0xFF0000, lang.get(MUSICBOT_MG_NO_BOT_IN_CHANNEL))).setActionRows().queue();
        commandState = -1;
    } else {
        MessageEmbed[] embed = bot.playStatus(event.getMember(), scheduler);
        event.editMessageEmbeds(embed[0], embed[1]).setActionRows(bot.controlButtons(args[2], scheduler.musicPause, scheduler.loopStatus, vc.getId())).queue();
    }
}
Also used : GuildMusicManager(com.ice.multiBot.music.GuildMusicManager) TrackScheduler(com.ice.multiBot.music.TrackScheduler)

Example 5 with GuildMusicManager

use of com.ice.multiBot.music.GuildMusicManager 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

GuildMusicManager (com.ice.multiBot.music.GuildMusicManager)5 TrackScheduler (com.ice.multiBot.music.TrackScheduler)2 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)2 SlashCommandInteractionEvent (net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent)2 SelectMenuInteractionEvent (net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent)2 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)1 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 JDABuilder (net.dv8tion.jda.api.JDABuilder)1 OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1