Search in sources :

Example 1 with PlayerManager

use of com.arsenarsen.lavaplayerbridge.PlayerManager in project FlareBot by FlareBot.

the class GuildUtils method joinChannel.

/**
 * Joins the bot to a {@link TextChannel}.
 *
 * @param channel The chanel to send an error message to in case this fails.
 * @param member  The member requesting the join. This is also how we determine what channel to join.
 */
public static void joinChannel(TextChannel channel, Member member) {
    if (channel.getGuild().getSelfMember().hasPermission(member.getVoiceState().getChannel(), Permission.VOICE_CONNECT) && channel.getGuild().getSelfMember().hasPermission(member.getVoiceState().getChannel(), Permission.VOICE_SPEAK)) {
        if (member.getVoiceState().getChannel().getUserLimit() > 0 && member.getVoiceState().getChannel().getMembers().size() >= member.getVoiceState().getChannel().getUserLimit() && !member.getGuild().getSelfMember().hasPermission(member.getVoiceState().getChannel(), Permission.MANAGE_CHANNEL)) {
            MessageUtils.sendErrorMessage("We can't join :(\n\nThe channel user limit has been reached and we don't have the 'Manage Channel' permission to " + "bypass it!", channel);
            return;
        }
        PlayerManager musicManager = FlareBot.instance().getMusicManager();
        channel.getGuild().getAudioManager().openAudioConnection(member.getVoiceState().getChannel());
        musicManager.getPlayer(channel.getGuild().getId()).play();
        if (musicManager.getPlayer(channel.getGuild().getId()).getPaused()) {
            MessageUtils.sendWarningMessage("The music is currently paused do `{%}resume`", channel);
        }
    } else {
        MessageUtils.sendErrorMessage("I do not have permission to " + (!channel.getGuild().getSelfMember().hasPermission(member.getVoiceState().getChannel(), Permission.VOICE_CONNECT) ? "connect" : "speak") + " in your voice channel!", channel);
    }
}
Also used : PlayerManager(com.arsenarsen.lavaplayerbridge.PlayerManager)

Example 2 with PlayerManager

use of com.arsenarsen.lavaplayerbridge.PlayerManager in project FlareBot by FlareBot.

the class QueueCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    PlayerManager manager = FlareBot.instance().getMusicManager();
    if (message.getContentRaw().substring(1).startsWith("playlist")) {
        MessageUtils.sendWarningMessage("This command is deprecated! Please use `{%}queue` instead!", channel);
    }
    if (args.length < 1 || args.length > 2) {
        send(channel, member);
    } else {
        if (args.length == 1) {
            if (args[0].equalsIgnoreCase("clear")) {
                if (!this.getPermissions(channel).hasPermission(member, Permission.QUEUE_CLEAR)) {
                    MessageUtils.sendErrorMessage("You need the `" + Permission.QUEUE_CLEAR + "` permission to do this!", channel, sender);
                    return;
                }
                manager.getPlayer(channel.getGuild().getId()).getPlaylist().clear();
                channel.sendMessage("Cleared the current playlist!").queue();
            } else if (args[0].equalsIgnoreCase("remove")) {
                MessageUtils.sendUsage(this, channel, sender, args);
            } else if (args[0].equalsIgnoreCase("here")) {
                send(channel, member);
            } else {
                MessageUtils.sendUsage(this, channel, sender, args);
            }
        } else {
            if (args[0].equalsIgnoreCase("remove")) {
                int number;
                try {
                    number = Integer.parseInt(args[1]);
                } catch (NumberFormatException e) {
                    MessageUtils.sendErrorMessage("That is an invalid number!", channel);
                    return;
                }
                Queue<Track> queue = manager.getPlayer(channel.getGuild().getId()).getPlaylist();
                if (number < 1 || number > queue.size()) {
                    MessageUtils.sendErrorMessage("There is no song with that index. Make sure your number is at least 1 and either " + queue.size() + " or below!", channel);
                    return;
                }
                List<Track> playlist = new ArrayList<>(queue);
                playlist.remove(number - 1);
                queue.clear();
                queue.addAll(playlist);
                channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("Removed number " + number + " from the playlist!").build()).queue();
            }
        }
    }
}
Also used : PlayerManager(com.arsenarsen.lavaplayerbridge.PlayerManager) ArrayList(java.util.ArrayList) Track(com.arsenarsen.lavaplayerbridge.player.Track)

Example 3 with PlayerManager

use of com.arsenarsen.lavaplayerbridge.PlayerManager in project FlareBot by FlareBot.

the class SkipCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    boolean songMessage = message.getAuthor().getIdLong() == Getters.getSelfUser().getIdLong();
    PlayerManager musicManager = FlareBot.instance().getMusicManager();
    if (!channel.getGuild().getAudioManager().isConnected() || musicManager.getPlayer(channel.getGuild().getId()).getPlayingTrack() == null) {
        channel.sendMessage("I am not playing anything!").queue();
        return;
    }
    if (member.getVoiceState().inVoiceChannel() && !channel.getGuild().getSelfMember().getVoiceState().getChannel().getId().equals(member.getVoiceState().getChannel().getId()) && !getPermissions(channel).hasPermission(member, Permission.SKIP_FORCE)) {
        channel.sendMessage("You must be in the channel in order to skip songs!").queue();
        return;
    }
    Track currentTrack = musicManager.getPlayer(guild.getGuildId()).getPlayingTrack();
    if (args.length == 0 && currentTrack.getMeta().get("requester").equals(sender.getId())) {
        channel.sendMessage("Skipped your own song!").queue();
        musicManager.getPlayer(guild.getGuildId()).skip();
        if (songMessage)
            SongCommand.updateSongMessage(sender, message, channel);
        return;
    }
    if (args.length != 1) {
        if (!channel.getGuild().getMember(sender).getVoiceState().inVoiceChannel() || channel.getGuild().getMember(sender).getVoiceState().getChannel().getIdLong() != channel.getGuild().getSelfMember().getVoiceState().getChannel().getIdLong()) {
            MessageUtils.sendErrorMessage("You cannot skip if you aren't listening to it!", channel);
            return;
        }
        if (VoteUtil.contains(skipUUID, guild.getGuild()))
            MessageUtils.sendWarningMessage("There is already a vote to skip current song! Vote with `{%}skip yes | no`", channel, sender);
        else {
            VoteGroup group = new VoteGroup("Skip current song", skipUUID);
            List<User> users = new ArrayList<>();
            for (Member inChannelMember : channel.getGuild().getSelfMember().getVoiceState().getChannel().getMembers()) {
                if (channel.getGuild().getSelfMember().getUser().getIdLong() != inChannelMember.getUser().getIdLong()) {
                    users.add(inChannelMember.getUser());
                }
            }
            group.limitUsers(users);
            VoteUtil.sendVoteMessage(skipUUID, (vote) -> {
                if (vote.equals(VoteGroup.Vote.NONE) || vote.equals(VoteGroup.Vote.NO)) {
                    MessageUtils.sendMessage("Results are in: Keep!", channel);
                } else {
                    MessageUtils.sendMessage("Skipping!", channel);
                    if (songMessage)
                        SongCommand.updateSongMessage(sender, message, channel);
                    musicManager.getPlayer(guild.getGuildId()).skip();
                }
            }, group, TimeUnit.MINUTES.toMillis(1), channel, sender, ButtonGroupConstants.VOTE_SKIP, new ButtonGroup.Button("\u23ED", (owner, user, message1) -> {
                if (getPermissions(channel).hasPermission(channel.getGuild().getMember(user), Permission.SKIP_FORCE)) {
                    musicManager.getPlayer(channel.getGuild().getId()).skip();
                    if (songMessage) {
                        SongCommand.updateSongMessage(user, message1, channel);
                    }
                    musicManager.getPlayer(guild.getGuildId()).skip();
                    VoteUtil.remove(skipUUID, guild.getGuild());
                } else {
                    channel.sendMessage("You are missing the permission `" + Permission.SKIP_FORCE + "` which is required for use of this button!").queue();
                }
            }));
        }
    } else {
        if (args[0].equalsIgnoreCase("force")) {
            if (getPermissions(channel).hasPermission(member, Permission.SKIP_FORCE)) {
                if (songMessage)
                    SongCommand.updateSongMessage(sender, message, channel);
                VoteUtil.remove(skipUUID, guild.getGuild());
                musicManager.getPlayer(guild.getGuildId()).skip();
            } else {
                channel.sendMessage("You are missing the permission `" + Permission.SKIP_FORCE + "` which is required for use of this command!").queue();
            }
            return;
        } else if (args[0].equalsIgnoreCase("cancel")) {
            if (getPermissions(channel).hasPermission(member, Permission.SKIP_CANCEL)) {
                VoteUtil.remove(skipUUID, channel.getGuild());
            } else
                channel.sendMessage("You are missing the permission `" + Permission.SKIP_CANCEL + "` which is required for use of this command!").queue();
            return;
        }
        if (!channel.getGuild().getMember(sender).getVoiceState().inVoiceChannel() || channel.getGuild().getMember(sender).getVoiceState().getChannel().getIdLong() != channel.getGuild().getSelfMember().getVoiceState().getChannel().getIdLong()) {
            MessageUtils.sendWarningMessage("You cannot vote to skip if you aren't listening to it!", channel);
            return;
        }
        VoteGroup.Vote vote = VoteGroup.Vote.parseVote(args[0]);
        if (vote != null) {
            if (!VoteUtil.contains(skipUUID, guild.getGuild()))
                MessageUtils.sendWarningMessage("Their is no vote currently running!", channel, sender);
            else
                VoteUtil.getVoteGroup(skipUUID, guild.getGuild()).addVote(vote, sender);
        } else
            MessageUtils.sendUsage(this, channel, sender, args);
    }
}
Also used : stream.flarebot.flarebot.commands(stream.flarebot.flarebot.commands) ButtonGroup(stream.flarebot.flarebot.util.objects.ButtonGroup) Track(com.arsenarsen.lavaplayerbridge.player.Track) Member(net.dv8tion.jda.core.entities.Member) TextChannel(net.dv8tion.jda.core.entities.TextChannel) FlareBot(stream.flarebot.flarebot.FlareBot) PlayerManager(com.arsenarsen.lavaplayerbridge.PlayerManager) UUID(java.util.UUID) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) Message(net.dv8tion.jda.core.entities.Message) Getters(stream.flarebot.flarebot.Getters) ButtonGroupConstants(stream.flarebot.flarebot.util.buttons.ButtonGroupConstants) VoteGroup(stream.flarebot.flarebot.util.votes.VoteGroup) VoteUtil(stream.flarebot.flarebot.util.votes.VoteUtil) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Permission(stream.flarebot.flarebot.permissions.Permission) User(net.dv8tion.jda.core.entities.User) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) User(net.dv8tion.jda.core.entities.User) PlayerManager(com.arsenarsen.lavaplayerbridge.PlayerManager) ButtonGroup(stream.flarebot.flarebot.util.objects.ButtonGroup) ArrayList(java.util.ArrayList) Member(net.dv8tion.jda.core.entities.Member) Track(com.arsenarsen.lavaplayerbridge.player.Track) VoteGroup(stream.flarebot.flarebot.util.votes.VoteGroup)

Example 4 with PlayerManager

use of com.arsenarsen.lavaplayerbridge.PlayerManager in project FlareBot by FlareBot.

the class SongCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    PlayerManager manager = FlareBot.instance().getMusicManager();
    if (manager.getPlayer(channel.getGuild().getId()).getPlayingTrack() != null) {
        Track track = manager.getPlayer(channel.getGuild().getId()).getPlayingTrack();
        EmbedBuilder eb = MessageUtils.getEmbed(sender).addField("Current Song", getLink(track), false).setThumbnail("https://img.youtube.com/vi/" + track.getTrack().getIdentifier() + "/hqdefault.jpg");
        if (track.getTrack().getInfo().isStream)
            eb.addField("Amount Played", "Issa livestream ;)", false);
        else
            eb.addField("Amount Played", GeneralUtils.getProgressBar(track), true).addField("Time", String.format("%s / %s", FormatUtils.formatDuration(track.getTrack().getPosition()), FormatUtils.formatDuration(track.getTrack().getDuration())), false);
        ButtonGroup buttonGroup = new ButtonGroup(sender.getIdLong(), ButtonGroupConstants.SONG);
        buttonGroup.addButton(new ButtonGroup.Button("\u23EF", (owner, user, message1) -> {
            if (manager.hasPlayer(guild.getGuildId())) {
                if (manager.getPlayer(guild.getGuild().getId()).getPaused()) {
                    if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.RESUME_COMMAND)) {
                        manager.getPlayer(guild.getGuild().getId()).play();
                    }
                } else {
                    if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.PAUSE_COMMAND)) {
                        manager.getPlayer(guild.getGuild().getId()).setPaused(true);
                    }
                }
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u23F9", (owner, user, message1) -> {
            if (manager.hasPlayer(guild.getGuildId()) && getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.STOP_COMMAND)) {
                manager.getPlayer(guild.getGuildId()).stop();
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u23ED", (owner, user, message1) -> {
            if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.SKIP_COMMAND)) {
                Command cmd = FlareBot.getCommandManager().getCommand("skip", user);
                if (cmd != null)
                    cmd.onCommand(user, guild, channel, message1, new String[0], guild.getGuild().getMember(user));
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\uD83D\uDD01", (ownerID, user, message1) -> {
            updateSongMessage(user, message1, message1.getTextChannel());
        }));
        ButtonUtil.sendButtonedMessage(channel, eb.build(), buttonGroup);
    } else {
        channel.sendMessage(MessageUtils.getEmbed(sender).addField("Current song", "**No song playing right now!**", false).build()).queue();
    }
}
Also used : YouTubeExtractor(stream.flarebot.flarebot.music.extractors.YouTubeExtractor) ButtonGroup(stream.flarebot.flarebot.util.objects.ButtonGroup) Track(com.arsenarsen.lavaplayerbridge.player.Track) Member(net.dv8tion.jda.core.entities.Member) TextChannel(net.dv8tion.jda.core.entities.TextChannel) ButtonUtil(stream.flarebot.flarebot.util.buttons.ButtonUtil) FlareBot(stream.flarebot.flarebot.FlareBot) PlayerManager(com.arsenarsen.lavaplayerbridge.PlayerManager) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) GeneralUtils(stream.flarebot.flarebot.util.general.GeneralUtils) Message(net.dv8tion.jda.core.entities.Message) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ButtonGroupConstants(stream.flarebot.flarebot.util.buttons.ButtonGroupConstants) FormatUtils(stream.flarebot.flarebot.util.general.FormatUtils) Permission(stream.flarebot.flarebot.permissions.Permission) User(net.dv8tion.jda.core.entities.User) Command(stream.flarebot.flarebot.commands.Command) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) CommandType(stream.flarebot.flarebot.commands.CommandType) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) PlayerManager(com.arsenarsen.lavaplayerbridge.PlayerManager) ButtonGroup(stream.flarebot.flarebot.util.objects.ButtonGroup) Command(stream.flarebot.flarebot.commands.Command) Track(com.arsenarsen.lavaplayerbridge.player.Track)

Example 5 with PlayerManager

use of com.arsenarsen.lavaplayerbridge.PlayerManager in project FlareBot by FlareBot.

the class QueueCommand method send.

private void send(TextChannel channel, Member sender) {
    PlayerManager manager = FlareBot.instance().getMusicManager();
    Track currentTrack = manager.getPlayer(channel.getGuild().getId()).getPlayingTrack();
    if (!manager.getPlayer(channel.getGuild().getId()).getPlaylist().isEmpty() || currentTrack != null) {
        List<String> songs = new ArrayList<>();
        songs.add("Current Song: " + String.format("[`%s`](%s) | Requested by <@!%s>\n", currentTrack.getTrack().getInfo().title, YouTubeExtractor.WATCH_URL + currentTrack.getTrack().getIdentifier(), currentTrack.getMeta().get("requester")));
        AtomicInteger i = new AtomicInteger(1);
        manager.getPlayer(channel.getGuild().getId()).getPlaylist().forEach(track -> songs.add(String.format("%s. [`%s`](%s) | Requested by <@!%s>\n", i.getAndIncrement(), track.getTrack().getInfo().title, YouTubeExtractor.WATCH_URL + track.getTrack().getIdentifier(), track.getMeta().get("requester"))));
        PagedEmbedBuilder pe = new PagedEmbedBuilder<>(PaginationUtil.splitStringToList(songs.stream().collect(Collectors.joining("\n")) + "\n", PaginationUtil.SplitMethod.NEW_LINES, 21)).setTitle("Queued Songs");
        PaginationUtil.sendEmbedPagedMessage(pe.build(), 0, channel, sender.getUser(), ButtonGroupConstants.QUEUE);
    } else {
        MessageUtils.sendErrorMessage(MessageUtils.getEmbed().setDescription("No songs in the playlist!"), channel);
    }
}
Also used : PlayerManager(com.arsenarsen.lavaplayerbridge.PlayerManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PagedEmbedBuilder(stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder) ArrayList(java.util.ArrayList) Track(com.arsenarsen.lavaplayerbridge.player.Track)

Aggregations

PlayerManager (com.arsenarsen.lavaplayerbridge.PlayerManager)5 Track (com.arsenarsen.lavaplayerbridge.player.Track)4 ArrayList (java.util.ArrayList)3 Member (net.dv8tion.jda.core.entities.Member)2 Message (net.dv8tion.jda.core.entities.Message)2 TextChannel (net.dv8tion.jda.core.entities.TextChannel)2 User (net.dv8tion.jda.core.entities.User)2 FlareBot (stream.flarebot.flarebot.FlareBot)2 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)2 Permission (stream.flarebot.flarebot.permissions.Permission)2 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)2 ButtonGroupConstants (stream.flarebot.flarebot.util.buttons.ButtonGroupConstants)2 ButtonGroup (stream.flarebot.flarebot.util.objects.ButtonGroup)2 List (java.util.List)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1 Getters (stream.flarebot.flarebot.Getters)1 stream.flarebot.flarebot.commands (stream.flarebot.flarebot.commands)1