// Path: src/main/java/be/isach/samaritan/util/brainfuck/BrainfuckInterpreter.java
// public class BrainfuckInterpreter {
// 
//     public static final int MAX_CYCLE_COUNT = 10000;
// 
//     /**
//      * Processes Brainfuck Code.
//      *
//      * @param brainfuckCode
//      * @return Process Result.
//      */
//     public String processCode(String brainfuckCode, ByteBuffer bytes, char[] code) {
//         int data = 0;
//         char[] inChars = brainfuckCode.toCharArray();
//         int inChar = 0;
//         StringBuilder result = new StringBuilder();
//         int cycleCount = 0;
//         for (int instruction = 0; instruction < code.length; ++instruction) {
//             cycleCount++;
//             if (cycleCount > MAX_CYCLE_COUNT) {
//                 throw new BrainfuckException("Program exceeded the maximum cycle count of " + MAX_CYCLE_COUNT);
//             }
//             char command = code[instruction];
//             switch (command) {
//                 case '>':
//                     ++data;
//                     break;
//                 case '<':
//                     --data;
//                     if (data < 0) {
//                         throw new BrainfuckException("Data pointer out of bounds: " + data);
//                     }
//                     break;
//                 case '+':
//                     bytes.put(data, (byte) (bytes.get(data) + 1));
//                     break;
//                 case '-':
//                     bytes.put(data, (byte) (bytes.get(data) - 1));
//                     break;
//                 case '.':
//                     result.append((char) bytes.get(data));
//                     break;
//                 case ',':
//                     try {
//                         bytes.put(data, (byte) inChars[inChar++]);
//                         break;
//                     } catch (IndexOutOfBoundsException ex) {
//                         throw new BrainfuckException("Input out of bounds at position: " + (inChar - 1), ex);
//                     }
//                 case '[':
//                     if (bytes.get(data) == 0) {
//                         int depth = 1;
//                         do {
//                             command = code[++instruction];
//                             if (command == '[') {
//                                 ++depth;
//                             } else if (command == ']') {
//                                 --depth;
//                             }
//                         } while (depth > 0);
//                     }
//                     break;
//                 case ']':
//                     if (bytes.get(data) != 0) {
//                         int depth = -1;
//                         do {
//                             command = code[--instruction];
//                             if (command == '[') {
//                                 ++depth;
//                             } else if (command == ']') {
//                                 --depth;
//                             }
//                         } while (depth < 0);
//                     }
//                     break;
//             }
//         }
//         return result.toString();
//     }
// }
// 
// Path: src/main/java/be/isach/samaritan/util/brainfuck/exception/BrainfuckException.java
// public class BrainfuckException extends RuntimeException {
// 
//     public BrainfuckException(String string, Throwable thrwbl) {
//         super(string, thrwbl);
//     }
// 
//     public BrainfuckException(String string) {
//         super(string);
//     }
// }


import be.isach.samaritan.util.brainfuck.BrainfuckInterpreter;
import be.isach.samaritan.util.brainfuck.exception.BrainfuckException;
import net.dv8tion.jda.core.entities.MessageChannel;
import java.nio.ByteBuffer;
package be.isach.samaritan.command;



/**
 * Project: samaritan
 * Package: be.isach.samaritan.command
 * Created by: Sacha
 * Created on: 05th juin, 2016
// * at 14:23
// */
class CommandBrainFuck extends Command {

    ByteBuffer bytes = null;

    char[] code;

    /**
     * Command Constructor.
     *
     * @param messageChannel The text Channel where command is called.
     * @param commandData    The Command Data, providing the Guild, the executor and the Samaritan instance.
     * @param args           The args provided when command was called.
     */
    CommandBrainFuck(MessageChannel messageChannel, CommandData commandData, String[] args) {
        super(messageChannel, commandData, args);
    }

    @Override
    void onExecute(String[] args) {
        String input = buildStringFromArgs();
        if (buildStringFromArgs().isEmpty()) {
            getMessageChannel().sendMessage("Please enter your Brainfuck code.");
            input = nextMessage().getContent();
        }

        code = input.toCharArray();
        bytes = ByteBuffer.allocateDirect(1024 * 1024 * 8);
        String inputArg = "";

        try {
            inputArg = args[2];
        } catch (Exception ignored) {

        }

        inputArg = inputArg.replaceAll("ZERO", String.valueOf((char) 0));

// Path: src/main/java/be/isach/samaritan/util/brainfuck/BrainfuckInterpreter.java
// public class BrainfuckInterpreter {
// 
//     public static final int MAX_CYCLE_COUNT = 10000;
// 
//     /**
//      * Processes Brainfuck Code.
//      *
//      * @param brainfuckCode
//      * @return Process Result.
//      */
//     public String processCode(String brainfuckCode, ByteBuffer bytes, char[] code) {
//         int data = 0;
//         char[] inChars = brainfuckCode.toCharArray();
//         int inChar = 0;
//         StringBuilder result = new StringBuilder();
//         int cycleCount = 0;
//         for (int instruction = 0; instruction < code.length; ++instruction) {
//             cycleCount++;
//             if (cycleCount > MAX_CYCLE_COUNT) {
//                 throw new BrainfuckException("Program exceeded the maximum cycle count of " + MAX_CYCLE_COUNT);
//             }
//             char command = code[instruction];
//             switch (command) {
//                 case '>':
//                     ++data;
//                     break;
//                 case '<':
//                     --data;
//                     if (data < 0) {
//                         throw new BrainfuckException("Data pointer out of bounds: " + data);
//                     }
//                     break;
//                 case '+':
//                     bytes.put(data, (byte) (bytes.get(data) + 1));
//                     break;
//                 case '-':
//                     bytes.put(data, (byte) (bytes.get(data) - 1));
//                     break;
//                 case '.':
//                     result.append((char) bytes.get(data));
//                     break;
//                 case ',':
//                     try {
//                         bytes.put(data, (byte) inChars[inChar++]);
//                         break;
//                     } catch (IndexOutOfBoundsException ex) {
//                         throw new BrainfuckException("Input out of bounds at position: " + (inChar - 1), ex);
//                     }
//                 case '[':
//                     if (bytes.get(data) == 0) {
//                         int depth = 1;
//                         do {
//                             command = code[++instruction];
//                             if (command == '[') {
//                                 ++depth;
//                             } else if (command == ']') {
//                                 --depth;
//                             }
//                         } while (depth > 0);
//                     }
//                     break;
//                 case ']':
//                     if (bytes.get(data) != 0) {
//                         int depth = -1;
//                         do {
//                             command = code[--instruction];
//                             if (command == '[') {
//                                 ++depth;
//                             } else if (command == ']') {
//                                 --depth;
//                             }
//                         } while (depth < 0);
//                     }
//                     break;
//             }
//         }
//         return result.toString();
//     }
// }
// 
// Path: src/main/java/be/isach/samaritan/util/brainfuck/exception/BrainfuckException.java
// public class BrainfuckException extends RuntimeException {
// 
//     public BrainfuckException(String string, Throwable thrwbl) {
//         super(string, thrwbl);
//     }
// 
//     public BrainfuckException(String string) {
//         super(string);
//     }
// }


// Path: src/main/java/be/isach/samaritan/command/CommandBrainFuck.java
import be.isach.samaritan.util.brainfuck.BrainfuckInterpreter;
import be.isach.samaritan.util.brainfuck.exception.BrainfuckException;
import net.dv8tion.jda.core.entities.MessageChannel;
import java.nio.ByteBuffer;

package be.isach.samaritan.command;



/**
 * Project: samaritan
 * Package: be.isach.samaritan.command
 * Created by: Sacha
 * Created on: 05th juin, 2016
// * at 14:23
// */
class CommandBrainFuck extends Command {

    ByteBuffer bytes = null;

    char[] code;

    /**
     * Command Constructor.
     *
     * @param messageChannel The text Channel where command is called.
     * @param commandData    The Command Data, providing the Guild, the executor and the Samaritan instance.
     * @param args           The args provided when command was called.
     */
    CommandBrainFuck(MessageChannel messageChannel, CommandData commandData, String[] args) {
        super(messageChannel, commandData, args);
    }

    @Override
    void onExecute(String[] args) {
        String input = buildStringFromArgs();
        if (buildStringFromArgs().isEmpty()) {
            getMessageChannel().sendMessage("Please enter your Brainfuck code.");
            input = nextMessage().getContent();
        }

        code = input.toCharArray();
        bytes = ByteBuffer.allocateDirect(1024 * 1024 * 8);
        String inputArg = "";

        try {
            inputArg = args[2];
        } catch (Exception ignored) {

        }

        inputArg = inputArg.replaceAll("ZERO", String.valueOf((char) 0));

        try {