Search in sources :

Example 1 with Command

use of stream.flarebot.flarebot.commands.Command in project FlareBot by FlareBot.

the class PermissionsCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 2) {
        if (args[0].equalsIgnoreCase("group")) {
            String groupString = args[1];
            if (!groupNamePattern.matcher(groupString).matches()) {
                if (groupString.length() > 32)
                    MessageUtils.sendWarningMessage("Please make sure the group name is a maximum of 32 chars!", channel);
                else if (groupString.length() < 3)
                    MessageUtils.sendWarningMessage("Please make sure the group name is a minimum of 3 chars!", channel);
                else
                    MessageUtils.sendWarningMessage("You used some invalid characters in your group name!\n" + "Please only use alphanumeric (letters and numbers) and `-`, `_`.", channel);
                return;
            }
            Group group = getPermissions(channel).getGroup(groupString);
            if (args.length >= 3) {
                if (group == null && !args[2].equalsIgnoreCase("create")) {
                    MessageUtils.sendErrorMessage("That group doesn't exist! You can create it with `{%}permissions group " + groupString + " create`", channel);
                    return;
                } else if (args[2].equalsIgnoreCase("add")) {
                    if (args.length == 4) {
                        if (!Permission.isValidPermission(args[3])) {
                            MessageUtils.sendErrorMessage("That is an invalid permission! Permissions start with `flarebot.` followed with a command name!\n" + "**Example:** `flarebot.play`\n" + "See `_permissions list` for a full list!", channel);
                            return;
                        }
                        if (group.addPermission(args[3])) {
                            MessageUtils.sendSuccessMessage("Successfully added the permission `" + args[3] + "` to the group `" + groupString + "`", channel, sender);
                            return;
                        } else {
                            MessageUtils.sendErrorMessage("Couldn't add the permission (it probably already exists)", channel);
                            return;
                        }
                    }
                } else if (args[2].equalsIgnoreCase("remove")) {
                    if (args.length == 4) {
                        if (group.removePermission(args[3])) {
                            MessageUtils.sendSuccessMessage("Successfully removed the permission `" + args[3] + "` from the group `" + groupString + "`", channel, sender);
                            return;
                        } else {
                            MessageUtils.sendErrorMessage("Couldn't remove the permission (it probably didn't exist)", channel);
                            return;
                        }
                    }
                } else if (args[2].equalsIgnoreCase("create")) {
                    if (!GuildWrapperLoader.ALLOWED_CHARS_REGEX.matcher(groupString).matches()) {
                        MessageUtils.sendErrorMessage("This group name has invalid characters! Please only use word characters and any of these: `" + new String(GuildWrapperLoader.ALLOWED_SPECIAL_CHARACTERS) + "`", channel);
                    }
                    if (getPermissions(channel).addGroup(groupString)) {
                        MessageUtils.sendSuccessMessage("Successfully created group: `" + groupString + "`", channel, sender);
                        return;
                    } else {
                        MessageUtils.sendErrorMessage("That group already exists!!", channel);
                        return;
                    }
                } else if (args[2].equalsIgnoreCase("delete")) {
                    getPermissions(channel).deleteGroup(groupString);
                    MessageUtils.sendSuccessMessage("Deleted group `" + groupString + "`", channel, sender);
                    return;
                } else if (args[2].equalsIgnoreCase("link")) {
                    if (args.length == 4) {
                        Role role = GuildUtils.getRole(args[3], guild.getGuildId());
                        if (role != null) {
                            group.linkRole(role.getId());
                            MessageUtils.sendSuccessMessage("Successfully linked the group `" + groupString + "` to the role `" + role.getName() + "`", channel, sender);
                            return;
                        } else {
                            MessageUtils.sendErrorMessage("That role doesn't exist!", channel);
                            return;
                        }
                    }
                } else if (args[2].equalsIgnoreCase("unlink")) {
                    Role role;
                    if (group.getRoleId() == null || (role = guild.getGuild().getRoleById(group.getRoleId())) == null) {
                        MessageUtils.sendErrorMessage("Cannot unlink if a role isn't linked!!", channel);
                        return;
                    } else {
                        group.linkRole(null);
                        MessageUtils.sendSuccessMessage("Successfully unlinked the role " + role.getName() + " from the group " + group.getName(), channel, sender);
                        return;
                    }
                } else if (args[2].equalsIgnoreCase("list")) {
                    if (args.length <= 4) {
                        int page = args.length == 4 ? Integer.valueOf(args[3]) : 1;
                        Set<String> perms = group.getPermissions();
                        List<String> permList = GeneralUtils.orderList(perms);
                        String list = permList.stream().collect(Collectors.joining("\n"));
                        PagedEmbedBuilder<String> pe = new PagedEmbedBuilder<>(PaginationUtil.splitStringToList(list, PaginationUtil.SplitMethod.NEW_LINES, 25));
                        pe.setTitle("Permissions for the group: " + group.getName());
                        pe.enableCodeBlock();
                        PaginationUtil.sendEmbedPagedMessage(pe.build(), page - 1, channel, sender, ButtonGroupConstants.PERMISSIONS_GROUP);
                        return;
                    }
                } else if (args[2].equalsIgnoreCase("massadd")) {
                    if (args.length == 4) {
                        List<Member> roleMembers;
                        String roleName = "";
                        switch(args[3]) {
                            case "@everyone":
                                roleMembers = guild.getGuild().getMembers();
                                roleName = "everyone";
                                break;
                            case "@here":
                                roleMembers = channel.getMembers();
                                roleName = "here";
                                break;
                            default:
                                Role role = GuildUtils.getRole(args[3], guild.getGuildId());
                                if (role != null) {
                                    roleMembers = guild.getGuild().getMembersWithRoles(role);
                                } else {
                                    MessageUtils.sendErrorMessage("That role doesn't exist!!", channel);
                                    return;
                                }
                                break;
                        }
                        for (Member user : roleMembers) {
                            getPermissions(channel).getUser(user).addGroup(group);
                        }
                        MessageUtils.sendSuccessMessage("Successfully added the group `" + groupString + "` to everyone in the role @" + roleName, channel, sender);
                        return;
                    }
                } else if (args[2].equalsIgnoreCase("clear")) {
                    group.getPermissions().clear();
                    MessageUtils.sendSuccessMessage("Cleared all permissions from the group: " + group.getName(), channel);
                    return;
                } else if (args[2].equalsIgnoreCase("move") && args.length >= 4) {
                    int pos = GeneralUtils.getInt(args[3], -1);
                    if (pos < 1 || pos >= guild.getPermissions().getGroups().size()) {
                        MessageUtils.sendWarningMessage("Invalid Position: " + args[3], channel);
                        return;
                    } else {
                        guild.getPermissions().moveGroup(group, pos - 1);
                        MessageUtils.sendSuccessMessage("Moved group `" + groupString + "` to position " + pos, channel, sender);
                        return;
                    }
                } else if (args[2].equalsIgnoreCase("clone") && args.length >= 4) {
                    if (guild.getPermissions().cloneGroup(group, args[3])) {
                        MessageUtils.sendMessage("Cloned group Successfully", channel);
                        return;
                    } else {
                        MessageUtils.sendWarningMessage("Error cloning group (The group might already exist)", channel);
                        return;
                    }
                } else if (args[2].equalsIgnoreCase("rename") && args.length >= 4) {
                    if (guild.getPermissions().renameGroup(group, args[3])) {
                        MessageUtils.sendMessage("Renamed group Successfully", channel);
                        return;
                    } else {
                        MessageUtils.sendWarningMessage("Error renaming group (The destination group might already exist)", channel);
                        return;
                    }
                }
            }
        } else if (args[0].equalsIgnoreCase("user")) {
            String userString = args[1];
            User user = GuildUtils.getUser(userString, guild.getGuildId());
            if (user == null) {
                MessageUtils.sendErrorMessage("That user doesn't exist!!", channel);
                return;
            }
            stream.flarebot.flarebot.permissions.User permUser = getPermissions(channel).getUser(guild.getGuild().getMember(user));
            if (args.length >= 3) {
                if (args[2].equalsIgnoreCase("group")) {
                    if (args.length >= 4) {
                        if (args[3].equalsIgnoreCase("add")) {
                            if (args.length == 5) {
                                String groupString = args[4];
                                Group group = getPermissions(channel).getGroup(groupString);
                                if (group == null) {
                                    MessageUtils.sendErrorMessage("That group doesn't exists!! You can create it with `" + getPrefix(channel.getGuild()) + "permissions group " + groupString + " create`", channel);
                                    return;
                                }
                                permUser.addGroup(group);
                                MessageUtils.sendSuccessMessage("Successfully added the group `" + groupString + "` to " + user.getAsMention(), channel, sender);
                                return;
                            }
                        } else if (args[3].equalsIgnoreCase("remove")) {
                            if (args.length == 5) {
                                String groupString = args[4];
                                Group group = getPermissions(channel).getGroup(groupString);
                                if (group == null) {
                                    MessageUtils.sendErrorMessage("That group doesn't exists!!", channel);
                                    return;
                                }
                                if (permUser.removeGroup(group)) {
                                    MessageUtils.sendSuccessMessage("Successfully removed the group `" + groupString + "` from " + user.getAsMention(), channel, sender);
                                    return;
                                } else {
                                    MessageUtils.sendErrorMessage("The user doesn't have that group!!", channel);
                                    return;
                                }
                            }
                        } else if (args[3].equalsIgnoreCase("list")) {
                            int page = (args.length == 5 ? GeneralUtils.getInt(args[4], 1) : 1) - 1;
                            Set<String> groups = new HashSet<>(permUser.getGroups());
                            groups.addAll(getPermissions(channel).getGroups().stream().filter(g -> guild.getGuild().getMember(user).getRoles().contains(guild.getGuild().getRoleById(g.getRoleId())) || g.getRoleId().equals(guild.getGuildId())).map(Group::getName).collect(Collectors.toList()));
                            List<String> groupList = GeneralUtils.orderList(groups);
                            String list = groupList.stream().collect(Collectors.joining("\n"));
                            PagedEmbedBuilder pe = new PagedEmbedBuilder<>(PaginationUtil.splitStringToList(list, PaginationUtil.SplitMethod.NEW_LINES, 25)).setTitle("Groups for " + MessageUtils.getTag(user)).enableCodeBlock();
                            PaginationUtil.sendEmbedPagedMessage(pe.build(), page, channel, sender, ButtonGroupConstants.PERMISSIONS_USER_GROUPS);
                            return;
                        }
                    }
                } else if (args[2].equalsIgnoreCase("permission")) {
                    if (args.length >= 4) {
                        if (args[3].equalsIgnoreCase("add")) {
                            if (args.length == 5) {
                                if (!Permission.isValidPermission(args[4])) {
                                    MessageUtils.sendErrorMessage("That is an invalid permission! Permissions start with `flarebot.` followed with a command name!\n" + "**Example:** `flarebot.play`\n" + "See `_permissions list` for a full list!", channel);
                                    return;
                                }
                                if (permUser.addPermission(args[4])) {
                                    MessageUtils.sendSuccessMessage("Successfully added the permission `" + args[4] + "` to " + user.getAsMention(), channel, sender);
                                    return;
                                } else {
                                    MessageUtils.sendErrorMessage("The user doesn't have that permission!!", channel);
                                    return;
                                }
                            }
                        } else if (args[3].equalsIgnoreCase("remove")) {
                            if (args.length == 5) {
                                if (permUser.removePermission(args[4])) {
                                    MessageUtils.sendSuccessMessage("Successfully removed the permission `" + args[4] + "` from " + user.getAsMention(), channel, sender);
                                    return;
                                } else {
                                    MessageUtils.sendErrorMessage("The user already has that permission!!", channel);
                                    return;
                                }
                            }
                        } else if (args[3].equalsIgnoreCase("list")) {
                            int page = (args.length == 5 ? Integer.valueOf(args[4]) : 1) - 1;
                            Set<String> perms = permUser.getPermissions();
                            List<String> permList = GeneralUtils.orderList(perms);
                            String list = permList.stream().collect(Collectors.joining("\n"));
                            PagedEmbedBuilder<String> pe = new PagedEmbedBuilder<>(PaginationUtil.splitStringToList(list, PaginationUtil.SplitMethod.NEW_LINES, 25));
                            pe.setTitle("Permissions for " + MessageUtils.getTag(user));
                            pe.enableCodeBlock();
                            PaginationUtil.sendEmbedPagedMessage(pe.build(), page, channel, sender, ButtonGroupConstants.PERMISSIONS_USER_PERMISSIONS);
                            return;
                        }
                    }
                } else if (args[2].equalsIgnoreCase("check")) {
                    if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.ALL_PERMISSIONS)) {
                        EmbedBuilder builder = new EmbedBuilder();
                        builder.setTitle("Permissions for " + user.getName());
                        builder.setDescription("**All Permissions!**");
                        channel.sendMessage(builder.build()).queue();
                        return;
                    } else {
                        String perms = Arrays.stream(Permission.values()).filter(p -> getPermissions(channel).hasPermission(guild.getGuild().getMember(user), p)).map(m -> "`" + m + "`").collect(Collectors.joining("\n"));
                        PagedEmbedBuilder<String> embedBuilder = new PagedEmbedBuilder<>(PaginationUtil.splitStringToList(perms, PaginationUtil.SplitMethod.NEW_LINES, 20));
                        embedBuilder.setTitle("Permissions for " + MessageUtils.getTag(user));
                        PaginationUtil.sendEmbedPagedMessage(embedBuilder.build(), 0, channel, sender, ButtonGroupConstants.PERMISSIONS_USER_CHECK);
                        return;
                    }
                } else if (args[2].equalsIgnoreCase("clear")) {
                    permUser.getPermissions().clear();
                    MessageUtils.sendSuccessMessage("Cleared all permissions from: " + MessageUtils.getTag(user), channel);
                    return;
                }
            }
        }
    } else if (args.length >= 1) {
        if (args[0].equalsIgnoreCase("groups")) {
            if (this.getPermissions(channel).getGroups().isEmpty()) {
                channel.sendMessage(MessageUtils.getEmbed(sender).setColor(Color.RED).setDescription("There are no groups for this guild!").build()).queue();
                return;
            } else {
                int page = args.length == 2 ? Integer.valueOf(args[1]) : 1;
                StringBuilder stringBuilder = new StringBuilder();
                int i = 1;
                for (Group group : guild.getPermissions().getGroups()) {
                    stringBuilder.append(i).append(". ").append(group.getName()).append("\n");
                    i++;
                }
                PagedEmbedBuilder<String> pe = new PagedEmbedBuilder<>(PaginationUtil.splitStringToList(stringBuilder.toString(), PaginationUtil.SplitMethod.NEW_LINES, 20));
                pe.setTitle("Groups");
                pe.enableCodeBlock();
                PaginationUtil.sendEmbedPagedMessage(pe.build(), page - 1, channel, sender, ButtonGroupConstants.PERMISSIONS_GROUPS);
                return;
            }
        } else if (args[0].equalsIgnoreCase("list")) {
            StringBuilder defaultPerms = new StringBuilder("**Default Permissions**\n");
            StringBuilder nonDefaultPerms = new StringBuilder("**Non-Default Permissions**\n");
            for (Permission p : Permission.values()) {
                if (p == Permission.ALL_PERMISSIONS)
                    continue;
                if (p.isDefaultPerm())
                    defaultPerms.append("`").append(p).append("`").append("\n");
                else
                    nonDefaultPerms.append("`").append(p).append("`").append("\n");
            }
            PagedEmbedBuilder<String> embedBuilder = new PagedEmbedBuilder<>(PaginationUtil.splitStringToList(defaultPerms.append("\n").append(nonDefaultPerms.toString()).toString(), PaginationUtil.SplitMethod.NEW_LINES, 20));
            embedBuilder.setTitle("Permissions");
            PaginationUtil.sendEmbedPagedMessage(embedBuilder.build(), 0, channel, sender, ButtonGroupConstants.PERMISSIONS_LIST);
            return;
        } else if (args[0].equalsIgnoreCase("reset")) {
            guild.setPermissions(new PerGuildPermissions());
            MessageUtils.sendSuccessMessage("Successfully reset perms", channel, sender);
            return;
        }
    }
    MessageUtils.sendUsage(this, channel, sender, args);
}
Also used : Color(java.awt.Color) Group(stream.flarebot.flarebot.permissions.Group) java.util(java.util) GuildWrapperLoader(stream.flarebot.flarebot.objects.GuildWrapperLoader) PaginationUtil(stream.flarebot.flarebot.util.pagination.PaginationUtil) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) GeneralUtils(stream.flarebot.flarebot.util.general.GeneralUtils) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ButtonGroupConstants(stream.flarebot.flarebot.util.buttons.ButtonGroupConstants) Permission(stream.flarebot.flarebot.permissions.Permission) PagedEmbedBuilder(stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder) Command(stream.flarebot.flarebot.commands.Command) PerGuildPermissions(stream.flarebot.flarebot.permissions.PerGuildPermissions) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) Pattern(java.util.regex.Pattern) CommandType(stream.flarebot.flarebot.commands.CommandType) GuildUtils(stream.flarebot.flarebot.util.general.GuildUtils) Group(stream.flarebot.flarebot.permissions.Group) PerGuildPermissions(stream.flarebot.flarebot.permissions.PerGuildPermissions) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) PagedEmbedBuilder(stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder) PagedEmbedBuilder(stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder) Permission(stream.flarebot.flarebot.permissions.Permission)

Example 2 with Command

use of stream.flarebot.flarebot.commands.Command in project FlareBot by FlareBot.

the class HelpCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 1) {
        CommandType type;
        try {
            type = CommandType.valueOf(args[0].toUpperCase());
        } catch (IllegalArgumentException ignored) {
            channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("No such category!").build()).queue();
            return;
        }
        if (GeneralUtils.canRunInternalCommand(type, sender)) {
            List<String> pages = new ArrayList<>();
            List<String> help = type.getCommands().stream().filter(cmd -> getPermissions(channel).hasPermission(member, cmd.getPermission())).map(command -> guild.getPrefix() + command.getCommand() + " - " + command.getDescription() + '\n').collect(Collectors.toList());
            StringBuilder sb = new StringBuilder();
            for (String s : help) {
                if (sb.length() + s.length() > 1024) {
                    pages.add(sb.toString());
                    sb.setLength(0);
                }
                sb.append(s);
            }
            pages.add(sb.toString());
            PagedEmbedBuilder<String> builder = new PagedEmbedBuilder<>(new PaginationList<>(pages));
            builder.setTitle("***FlareBot " + type + " commands!***");
            builder.setColor(Color.CYAN);
            PaginationUtil.sendEmbedPagedMessage(builder.build(), 0, channel, sender, ButtonGroupConstants.HELP);
        } else {
            channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("No such category!").build()).queue();
        }
    } else {
        sendCommands(channel.getGuild(), channel, sender);
    }
}
Also used : Color(java.awt.Color) PaginationUtil(stream.flarebot.flarebot.util.pagination.PaginationUtil) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) GeneralUtils(stream.flarebot.flarebot.util.general.GeneralUtils) Collectors(java.util.stream.Collectors) ButtonGroupConstants(stream.flarebot.flarebot.util.buttons.ButtonGroupConstants) ArrayList(java.util.ArrayList) List(java.util.List) Permission(stream.flarebot.flarebot.permissions.Permission) PagedEmbedBuilder(stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder) Command(stream.flarebot.flarebot.commands.Command) FlareBotManager(stream.flarebot.flarebot.FlareBotManager) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) PaginationList(stream.flarebot.flarebot.util.pagination.PaginationList) CommandType(stream.flarebot.flarebot.commands.CommandType) CommandType(stream.flarebot.flarebot.commands.CommandType) PagedEmbedBuilder(stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder) ArrayList(java.util.ArrayList)

Example 3 with Command

use of stream.flarebot.flarebot.commands.Command 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 4 with Command

use of stream.flarebot.flarebot.commands.Command in project FlareBot by FlareBot.

the class DisableCommandCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (PerGuildPermissions.isCreator(sender) || PerGuildPermissions.isContributor(sender)) {
        if (args.length == 0) {
            channel.sendMessage("Can't really disable commands if you don't supply any ¯\\_(ツ)_/¯").queue();
            return;
        }
        if (args.length == 1 && args[0].equalsIgnoreCase("list")) {
            StringBuilder sb = new StringBuilder();
            Map<String, String> disabledCmds = FlareBotManager.instance().getDisabledCommands();
            for (String cmd : disabledCmds.keySet()) {
                sb.append("`").append(cmd).append("` - ").append(disabledCmds.get(cmd));
            }
            channel.sendMessage(MessageUtils.getEmbed(sender).setColor(Color.orange).addField("Disabled Commands", sb.toString(), false).build()).queue();
            return;
        }
        String msg = MessageUtils.getMessage(args, 0);
        String reason = "This command is currently disabled! Please check our support server for more info! " + "https://flarebot.stream/support-server";
        if (msg.contains("-"))
            reason = msg.substring(msg.indexOf("-") + 1).trim();
        String[] cmds = msg.substring(0, msg.contains("-") ? msg.indexOf("-") : msg.length()).trim().split("\\|");
        StringBuilder sb = new StringBuilder();
        for (String command : cmds) {
            Command cmd = FlareBot.getCommandManager().getCommand(command.trim(), sender);
            if (cmd == null || cmd.getType() == CommandType.SECRET)
                continue;
            // If it's already disabled and there's only 1 (with a reason supplied) just update the reason.
            if (cmds.length == 1 && msg.contains("-") && FlareBotManager.instance().isCommandDisabled(cmd.getCommand())) {
                FlareBotManager.instance().getDisabledCommands().put(cmd.getCommand(), reason);
                sb.append("`").append(cmd.getCommand()).append("` - ").append(getEmote(false)).append(" New reason: ").append(reason);
            } else
                sb.append("`").append(cmd.getCommand()).append("` - ").append(getEmote(FlareBotManager.instance().toggleCommand(cmd.getCommand(), reason))).append("\n");
        }
        if (sb.toString().isEmpty())
            return;
        channel.sendMessage(MessageUtils.getEmbed(sender).setColor(Color.orange).setDescription(sb.toString()).build()).queue();
    }
}
Also used : InternalCommand(stream.flarebot.flarebot.commands.InternalCommand) Command(stream.flarebot.flarebot.commands.Command)

Example 5 with Command

use of stream.flarebot.flarebot.commands.Command in project FlareBot by FlareBot.

the class HelpCommand method sendCommands.

private void sendCommands(Guild guild, TextChannel channel, User sender) {
    List<String> pages = new ArrayList<>();
    for (CommandType c : CommandType.getTypes()) {
        List<String> help = c.getCommands().stream().filter(cmd -> cmd.getPermission() != null && FlareBotManager.instance().getGuild(guild.getId()).getPermissions().hasPermission(guild.getMember(sender), cmd.getPermission())).map(command -> FlareBotManager.instance().getGuild(guild.getId()).getPrefix() + command.getCommand() + " - " + command.getDescription() + '\n').collect(Collectors.toList());
        StringBuilder sb = new StringBuilder();
        sb.append("**").append(c).append("**\n");
        for (String s : help) {
            if (sb.length() + s.length() > 1024) {
                pages.add(sb.toString());
                sb.setLength(0);
                sb.append("**").append(c).append("**\n");
            }
            sb.append(s);
        }
        if (sb.toString().trim().isEmpty())
            continue;
        pages.add(sb.toString());
    }
    PagedEmbedBuilder<String> builder = new PagedEmbedBuilder<>(new PaginationList<>(pages));
    builder.setColor(Color.CYAN);
    PaginationUtil.sendEmbedPagedMessage(builder.build(), 0, channel, sender, ButtonGroupConstants.HELP);
}
Also used : Color(java.awt.Color) PaginationUtil(stream.flarebot.flarebot.util.pagination.PaginationUtil) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) GeneralUtils(stream.flarebot.flarebot.util.general.GeneralUtils) Collectors(java.util.stream.Collectors) ButtonGroupConstants(stream.flarebot.flarebot.util.buttons.ButtonGroupConstants) ArrayList(java.util.ArrayList) List(java.util.List) Permission(stream.flarebot.flarebot.permissions.Permission) PagedEmbedBuilder(stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder) Command(stream.flarebot.flarebot.commands.Command) FlareBotManager(stream.flarebot.flarebot.FlareBotManager) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) PaginationList(stream.flarebot.flarebot.util.pagination.PaginationList) CommandType(stream.flarebot.flarebot.commands.CommandType) CommandType(stream.flarebot.flarebot.commands.CommandType) PagedEmbedBuilder(stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder) ArrayList(java.util.ArrayList)

Aggregations

Command (stream.flarebot.flarebot.commands.Command)5 CommandType (stream.flarebot.flarebot.commands.CommandType)4 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)4 Permission (stream.flarebot.flarebot.permissions.Permission)4 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)4 ButtonGroupConstants (stream.flarebot.flarebot.util.buttons.ButtonGroupConstants)4 GeneralUtils (stream.flarebot.flarebot.util.general.GeneralUtils)4 Color (java.awt.Color)3 Collectors (java.util.stream.Collectors)3 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)3 PagedEmbedBuilder (stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder)3 PaginationUtil (stream.flarebot.flarebot.util.pagination.PaginationUtil)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)2 FlareBotManager (stream.flarebot.flarebot.FlareBotManager)2 PaginationList (stream.flarebot.flarebot.util.pagination.PaginationList)2 PlayerManager (com.arsenarsen.lavaplayerbridge.PlayerManager)1 Track (com.arsenarsen.lavaplayerbridge.player.Track)1 java.util (java.util)1