Search in sources :

Example 1 with CommandType

use of stream.flarebot.flarebot.commands.CommandType 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 2 with CommandType

use of stream.flarebot.flarebot.commands.CommandType 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

Color (java.awt.Color)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)2 FlareBotManager (stream.flarebot.flarebot.FlareBotManager)2 Command (stream.flarebot.flarebot.commands.Command)2 CommandType (stream.flarebot.flarebot.commands.CommandType)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 GeneralUtils (stream.flarebot.flarebot.util.general.GeneralUtils)2 PagedEmbedBuilder (stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder)2 PaginationList (stream.flarebot.flarebot.util.pagination.PaginationList)2 PaginationUtil (stream.flarebot.flarebot.util.pagination.PaginationUtil)2