Search in sources :

Example 1 with CommandCategory

use of de.tectoast.emolga.commands.CommandCategory in project Emolga by TecToast.

the class HelpButton method process.

@Override
public void process(ButtonClickEvent e, String name) {
    Guild g = e.getGuild();
    Member mem = e.getMember();
    if (name.equals("BACK")) {
        EmbedBuilder builder = new EmbedBuilder();
        builder.setTitle("Commands").setColor(java.awt.Color.CYAN);
        builder.setDescription(getHelpDescripion(g, mem));
        builder.setColor(java.awt.Color.CYAN);
        e.editMessageEmbeds(builder.build()).queue();
    } else {
        CommandCategory c = CommandCategory.byName(name);
        if (c.allowsGuild(g) && c.allowsMember(mem)) {
            List<Command> l = getWithCategory(c, g, mem);
            List<MessageEmbed> embeds = new LinkedList<>();
            StringBuilder b = new StringBuilder();
            boolean first = true;
            for (Command cmd : l) {
                b.append(cmd.getHelp(g)).append("\n");
                if (b.length() > 1900) {
                    EmbedBuilder emb = new EmbedBuilder();
                    if (first)
                        emb.setTitle(c.getName());
                    embeds.add(emb.setColor(Color.CYAN).setDescription(b.toString()).build());
                    first = false;
                    b.setLength(0);
                }
            }
            if (b.length() > 0) {
                EmbedBuilder emb = new EmbedBuilder();
                if (first)
                    emb.setTitle(c.getName());
                embeds.add(emb.setColor(Color.CYAN).setDescription(b.toString()).build());
            }
            e.editMessageEmbeds(embeds).queue(i -> i.editOriginalComponents(getHelpButtons(g, mem)).queue());
        } else {
            e.reply("Auf die Kategorie " + c.getName() + " hast du keinen Zugriff!").queue();
        }
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) Command(de.tectoast.emolga.commands.Command) CommandCategory(de.tectoast.emolga.commands.CommandCategory) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member) LinkedList(java.util.LinkedList)

Aggregations

Command (de.tectoast.emolga.commands.Command)1 CommandCategory (de.tectoast.emolga.commands.CommandCategory)1 LinkedList (java.util.LinkedList)1 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1 Guild (net.dv8tion.jda.api.entities.Guild)1 Member (net.dv8tion.jda.api.entities.Member)1 MessageEmbed (net.dv8tion.jda.api.entities.MessageEmbed)1