package stream.flarebot.flarebot.util.objects;

import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.User;
import stream.flarebot.flarebot.Getters;
import stream.flarebot.flarebot.util.buttons.ButtonRunnable;

import java.util.ArrayList;
import java.util.List;

public class ButtonGroup {

    private List<Button> buttons;

    public ButtonGroup() {
        buttons = new ArrayList<>();
    }

    /**
     * Adds a button to the button group.
     *
     * @param btn The button which you would like to add.
     */
    public void addButton(Button btn) {
        // Note I don't check if it already exists... so just don't fuck up :blobthumbsup:
        this.buttons.add(btn);
    }

    public List<Button> getButtons() {
        return buttons;
    }

    public static class Button {

        private String unicode;
        private long emoteId;
        private ButtonRunnable runnable;
        private Message message;
        private int clicks;

        public Button(String unicode, ButtonRunnable runnable) {
            this.unicode = unicode;
            this.runnable = runnable;
            clicks = 0;
        }

        public Button(long emoteId, ButtonRunnable runnable) {
            this.emoteId = emoteId;
            this.runnable = runnable;
            clicks = 0;
        }

        public long getEmoteId() {
            return emoteId;
        }

        public String getUnicode() {
            return unicode;
        }

        public void addReaction(Message message) {
            this.message = message;
            if (unicode != null)
                message.addReaction(unicode).queue();
            else
                message.addReaction(Getters.getEmoteById(emoteId)).queue();
        }

        public void onClick(User user) {
            runnable.run(user, message);
            clicks++;
        }

        public int getClicks() {
            return clicks;
        }
    }
}

@@ -41,16 +41,106 @@
 jects;%0A%0A
+import net.dv8tion.jda.core.Permission;%0Aimport net.dv8tion.jda.core.entities.ChannelType;%0A
 import n
@@ -1613,24 +1613,396 @@
  message) %7B%0A
+            if (!(message.getChannel().getType() == ChannelType.TEXT && message.getGuild().getSelfMember()%0A                    .hasPermission(message.getTextChannel(), Permission.MESSAGE_HISTORY))) %7B%0A                message.getChannel().sendMessage(%22I can't add buttons due to not having the %60Message History%60 permission!%22).queue();%0A                return;%0A            %7D%0A%0A
             

Fix button missing perm error