/*
 * The MIT License (MIT)
 * Copyright (c) 2016 Frederik Mikkelsen
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package fredboat.command.admin;

import fredboat.commandmeta.abs.Command;
import fredboat.commandmeta.abs.ICommandOwnerRestricted;
import fredboat.util.log.SLF4JInputStreamErrorLogger;
import fredboat.util.log.SLF4JInputStreamLogger;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.Member;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class CompileCommand extends Command implements ICommandOwnerRestricted {

    private static final Logger log = LoggerFactory.getLogger(CompileCommand.class);

    @Override
    public void onInvoke(Guild guild, TextChannel channel, Member invoker, Message message, String[] args) {
        try {
            Runtime rt = Runtime.getRuntime();
            Message msg = channel.sendMessage("*Now updating...*\n\nRunning `git clone`... ");
            String branch = "master";
            if (args.length > 1) {
                branch = args[1];
            }

            //Clear any old update folder if it is still present
            try {
                Process rm = rt.exec("rm -rf update");
                rm.waitFor(5, TimeUnit.SECONDS);
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            Process gitClone = rt.exec("git clone https://github.com/Frederikam/FredBoat.git --branch " + branch + " --single-branch update");
            new SLF4JInputStreamLogger(log, gitClone.getInputStream()).start();
            new SLF4JInputStreamErrorLogger(log, gitClone.getInputStream()).start();

            if (!gitClone.waitFor(120, TimeUnit.SECONDS)) {
                msg = msg.updateMessage(msg.getRawContent() + "[:anger: timed out]\n\n");
                throw new RuntimeException("Operation timed out: git clone");
            } else if (gitClone.exitValue() != 0) {
                msg = msg.updateMessage(msg.getRawContent() + "[:anger: returned code " + gitClone.exitValue() + "]\n\n");
                throw new RuntimeException("Bad response code");
            }

            msg = msg.updateMessage(msg.getRawContent() + "👌🏽\n\nRunning `mvn package shade:shade`... ");
            File updateDir = new File("update/FredBoat");

            Process mvnBuild = rt.exec("mvn -f " + updateDir.getAbsolutePath() + "/pom.xml package shade:shade");
            new SLF4JInputStreamLogger(log, mvnBuild.getInputStream()).start();
            new SLF4JInputStreamErrorLogger(log, mvnBuild.getInputStream()).start();

            if (!mvnBuild.waitFor(600, TimeUnit.SECONDS)) {
                msg = msg.updateMessage(msg.getRawContent() + "[:anger: timed out]\n\n");
                throw new RuntimeException("Operation timed out: mvn package shade:shade");
            } else if (mvnBuild.exitValue() != 0) {
                msg = msg.updateMessage(msg.getRawContent() + "[:anger: returned code " + mvnBuild.exitValue() + "]\n\n");
                throw new RuntimeException("Bad response code");
            }

            msg.updateMessage(msg.getRawContent() + "👌🏽");

            if(!new File("./update/FredBoat/target/FredBoat-1.0.jar").renameTo(new File(System.getProperty("user.home") + "/FredBoat-1.0.jar"))){
                throw new RuntimeException("Failed to move jar to home");
            }
        } catch (InterruptedException | IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}

@@ -1521,24 +1521,85 @@
 ies.Member;%0A
+import net.dv8tion.jda.core.exceptions.RateLimitedException;%0A
 import org.s
@@ -2104,16 +2104,34 @@
 Message 
+msg;%0A%0A            
 msg = ch
@@ -2187,33 +2187,42 @@
 git clone%60... %22)
-;
+.block();%0A
 %0A            Str
@@ -2572,27 +2572,37 @@
     
-ex.printStackTrace(
+throw new RuntimeException(ex
 );%0A 
@@ -3002,38 +3002,36 @@
       msg = msg.
-update
+edit
 Message(msg.getR
@@ -3062,32 +3062,40 @@
 timed out%5D%5Cn%5Cn%22)
+.block()
 ;%0A              
@@ -3228,38 +3228,36 @@
       msg = msg.
-update
+edit
 Message(msg.getR
@@ -3321,32 +3321,40 @@
 lue() + %22%5D%5Cn%5Cn%22)
+.block()
 ;%0A              
@@ -3433,38 +3433,36 @@
       msg = msg.
-update
+edit
 Message(msg.getR
@@ -3521,16 +3521,24 @@
 e%60... %22)
+.block()
 ;%0A      
@@ -3948,38 +3948,36 @@
       msg = msg.
-update
+edit
 Message(msg.getR
@@ -4012,24 +4012,32 @@
 d out%5D%5Cn%5Cn%22)
+.block()
 ;%0A          
@@ -4192,30 +4192,28 @@
   msg = msg.
-update
+edit
 Message(msg.
@@ -4289,16 +4289,24 @@
 %22%5D%5Cn%5Cn%22)
+.block()
 ;%0A      
@@ -4395,22 +4395,20 @@
     msg.
-update
+edit
 Message(
@@ -4434,16 +4434,24 @@
  + %22%F0%9F%91%8C%F0%9F%8F%BD%22)
+.queue()
 ;%0A%0A     
@@ -4723,32 +4723,55 @@
 n %7C IOException 
+%7C RateLimitedException 
 ex) %7B%0A          

Fix CompileCommand