/*
 * MIT License
 *
 * Copyright (c) 2017 Duncan Casteleyn
 *
 * 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 be.duncanc.discordmodbot.bot.commands;

import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

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

/**
 * Quit command for the bot
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class QuitBot extends CommandModule {
    private static final String[] ALIASES = new String[]{"Quit", "Shutdown", "Disconnect"};
    private static final String DESCRIPTION = "Shuts down the bot.";

    private List<BeforeBotQuit> callBeforeBotQuit;

    private QuitBot() {
        super(ALIASES, null, DESCRIPTION, true, true);
        callBeforeBotQuit = new ArrayList<>();
    }

    @Override
    public void commandExec(@NotNull MessageReceivedEvent event, @NotNull String command, String arguments) {
        if (event.getAuthor().getIdLong() == 159419654148718593L) {
            callBeforeBotQuit.forEach(beforeBotQuit -> {
                try {
                    beforeBotQuit.onAboutToQuit();
                } catch (Exception e) {
                    Companion.getLOG().error("Failed executing a task before quit due to an exception", e);
                }
            });
            event.getChannel().sendMessage(event.getAuthor().getAsMention() + " **Shutting down... :wave: **").queue();
            /*try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }*/
            event.getJDA().shutdown();
        } else {
            event.getChannel().sendMessage(event.getAuthor().getAsMention() + " you don't have permission to shutdown the bot!").queue();
        }

    }

    public void addCallBeforeQuit(BeforeBotQuit beforeBotQuit) {
        callBeforeBotQuit.add(beforeBotQuit);
    }

    /**
     * This interface can be used to perform actions before quiting
     */
    public interface BeforeBotQuit {
        /**
         * Actions to perform before the quit command is finished with executing.
         */
        void onAboutToQuit();
    }
}

@@ -1336,38 +1336,223 @@
 ory.
-config.ConfigurableBeanFactory
+annotation.Autowired;%0Aimport org.springframework.beans.factory.config.ConfigurableBeanFactory;%0Aimport org.springframework.context.ApplicationContext;%0Aimport org.springframework.context.ConfigurableApplicationContext
 ;%0Aim
@@ -2061,29 +2061,123 @@
 it;%0A
-%0A    private QuitBot(
+    private final ApplicationContext applicationContext;%0A%0A    private QuitBot(ApplicationContext applicationContext
 ) %7B%0A
@@ -2274,24 +2274,78 @@
 ayList%3C%3E();%0A
+        this.applicationContext = applicationContext;%0A
     %7D%0A%0A    @
@@ -3176,24 +3176,99 @@
 shutdown();%0A
+            ((ConfigurableApplicationContext) applicationContext).close();%0A
         %7D el

Quit command will now close Spring