Search in sources :

Example 1 with VoteGroup

use of stream.flarebot.flarebot.util.votes.VoteGroup 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)

Aggregations

PlayerManager (com.arsenarsen.lavaplayerbridge.PlayerManager)1 Track (com.arsenarsen.lavaplayerbridge.player.Track)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 Member (net.dv8tion.jda.core.entities.Member)1 Message (net.dv8tion.jda.core.entities.Message)1 TextChannel (net.dv8tion.jda.core.entities.TextChannel)1 User (net.dv8tion.jda.core.entities.User)1 FlareBot (stream.flarebot.flarebot.FlareBot)1 Getters (stream.flarebot.flarebot.Getters)1 stream.flarebot.flarebot.commands (stream.flarebot.flarebot.commands)1 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)1 Permission (stream.flarebot.flarebot.permissions.Permission)1 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)1 ButtonGroupConstants (stream.flarebot.flarebot.util.buttons.ButtonGroupConstants)1 ButtonGroup (stream.flarebot.flarebot.util.objects.ButtonGroup)1 VoteGroup (stream.flarebot.flarebot.util.votes.VoteGroup)1 VoteUtil (stream.flarebot.flarebot.util.votes.VoteUtil)1