package com.avairebot.orion.middleware;

import com.avairebot.orion.Orion;
import com.avairebot.orion.contracts.middleware.AbstractMiddleware;
import com.avairebot.orion.factories.MessageFactory;
import com.avairebot.orion.permissions.Permissions;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Require extends AbstractMiddleware {

    public Require(Orion orion) {
        super(orion);
    }

    @Override
    public void handle(MessageReceivedEvent event, MiddlewareStack stack, String... args) {
        List<Permissions> missingPermissions = new ArrayList<>();

        for (String permissionNode : args) {
            Permissions permission = Permissions.fromNode(permissionNode);
            if (permission == null) {
                orion.logger.warning("Invalid permission node given for the \"%s\" command: %s", stack.getCommand().getName(), permissionNode);
                return;
            }

            if (!event.getMember().hasPermission(permission.getPermission())) {
                missingPermissions.add(permission);
            }
        }

        if (!missingPermissions.isEmpty()) {
            MessageFactory.makeError(
                    event.getMessage(),
                    "You're missing the required permission node for this command:\n`%s`",
                    missingPermissions.stream()
                            .map(Permissions::getPermission)
                            .map(Permission::getName)
                            .collect(Collectors.joining("`, `"))
            ).queue();
            return;
        }

        stack.next();
    }
}

@@ -647,32 +647,293 @@
 ring... args) %7B%0A
+        if (!event.getChannelType().isGuild()) %7B%0A            stack.next();%0A            return;%0A        %7D%0A%0A        if (event.getMember().hasPermission(Permissions.ADMINISTRATOR.getPermission())) %7B%0A            stack.next();%0A            return;%0A        %7D%0A        %0A
         List%3CPer

Check for guild types and admin permissions in require middleware