package com.avairebot.orion.middleware;

import com.avairebot.orion.Orion;
import com.avairebot.orion.contracts.middleware.AbstractMiddleware;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.User;

import java.util.Arrays;
import java.util.regex.Pattern;

public class ProcessCommand extends AbstractMiddleware {

    private final Pattern argumentsRegEX;

    public ProcessCommand(Orion orion) {
        super(orion);

        this.argumentsRegEX = Pattern.compile("[\\s\"]+|\"([^\"]*)\"", Pattern.MULTILINE);
    }

    @Override
    public boolean handle(Message message, MiddlewareStack stack, String... args) {
        String[] arguments = argumentsRegEX.split(message.getContent());

        User author = message.getAuthor();
        orion.logger.info(String.format("Executing Command <%s> from %s#%s",
                message.getContent(),
                author.getName(),
                author.getDiscriminator()
        ));

        return stack.getCommand().onCommand(message, Arrays.copyOfRange(arguments, 1, arguments.length));
    }
}

@@ -185,51 +185,8 @@
 age;
-%0Aimport net.dv8tion.jda.core.entities.User;
 %0A%0Aim
@@ -299,16 +299,291 @@
 ware %7B%0A%0A
+    private final static String COMMAND_OUTPUT = %22Executing Command %5C%22%25command%25%5C%22 in %5C%22%25category%25%5C%22 category:%22%0A            + %22%5Cn%5Ct%5CtUser:%5Ct %25author%25%22%0A            + %22%5Cn%5Ct%5CtServer:%5Ct %25server%25%22%0A            + %22%5Cn%5Ct%5CtChannel: %25channel%25%22%0A            + %22%5Cn%5Ct%5CtMessage: %25message%25%22;%0A%0A
     priv
@@ -963,117 +963,674 @@
     
-User author = message.getAuthor();%0A        orion.logger.info(String.format(%22Executing Command %3C%25s%3E from %25s#%25s
+orion.logger.info(COMMAND_OUTPUT%0A                .replace(%22%25command%25%22, stack.getCommand().getName())%0A                .replace(%22%25category%25%22, stack.getCommandContainer().getCategory().getName())%0A                .replace(%22%25author%25%22, generateUsername(message))%0A                .replace(%22%25server%25%22, generateServer(message))%0A                .replace(%22%25channel%25%22, generateChannel(message))%0A                .replace(%22%25message%25%22, message.getRawContent())%0A        );%0A%0A        return stack.getCommand().onCommand(message, Arrays.copyOfRange(arguments, 1, arguments.length));%0A    %7D%0A%0A    private String generateUsername(Message message) %7B%0A        return String.format(%22%25s#%25s %5B%25s%5D
 %22,%0A 
@@ -1655,23 +1655,32 @@
 sage.get
-Content
+Author().getName
 (),%0A    
@@ -1695,22 +1695,44 @@
     
-a
+message.getA
 uthor
+()
 .get
-Name
+Discriminator
 (),%0A
@@ -1751,150 +1751,637 @@
     
-a
+message.getA
 uthor
+()
 .get
-Discriminator()%0A        ));%0A%0A        return stack.getCommand().onCommand(message, Arrays.copyOfRange(arguments, 1, arguments.length)
+Id()%0A        );%0A    %7D%0A%0A    private String generateServer(Message message) %7B%0A        if (message.getChannelType().isGuild()) %7B%0A            return %22PRIVATE%22;%0A        %7D%0A%0A        return String.format(%22%25s %5B%25s%5D%22,%0A                message.getGuild().getName(),%0A                message.getGuild().getId()%0A        );%0A    %7D%0A%0A    private CharSequence generateChannel(Message message) %7B%0A        if (message.getChannelType().isGuild()) %7B%0A            return %22PRIVATE%22;%0A        %7D%0A%0A        return String.format(%22%25s %5B%25s%5D%22,%0A                message.getChannel().getName(),%0A                message.getChannel().getId()%0A        
 );%0A 

Modify process command log message to contain more information