package com.bwfcwalshy.flarebot.commands.secret;

import com.bwfcwalshy.flarebot.FlareBot;
import com.bwfcwalshy.flarebot.MessageUtils;
import com.bwfcwalshy.flarebot.commands.Command;
import com.bwfcwalshy.flarebot.commands.CommandType;
import com.sedmelluq.discord.lavaplayer.jdaudp.NativeAudioSendFactory;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.exceptions.RateLimitedException;

import javax.security.auth.login.LoginException;

public class ShardRestart implements Command {
    @Override
    public void onCommand(User sender, TextChannel channel, Message message, String[] args, Member member) {
        if (getPermissions(channel).isCreator(sender)) {
            int shard = Integer.parseInt(args[0]);
            try {
                FlareBot.getInstance().getClients()[shard] = new JDABuilder(AccountType.BOT)
                                .addListener(FlareBot.getInstance().getEvents())
                                .useSharding(shard, FlareBot.getInstance().getClients().length)
                                .setToken(FlareBot.getToken())
                                .setAudioSendFactory(new NativeAudioSendFactory())
                                .buildAsync();
            } catch (LoginException | RateLimitedException e) {
                MessageUtils.sendException("", e, channel);
            }
        }
    }

    @Override
    public String getCommand() {
        return null;
    }

    @Override
    public String getDescription() {
        return null;
    }

    @Override
    public CommandType getType() {
        return null;
    }

    @Override
    public String getPermission() {
        return null;
    }

    @Override
    public boolean isDefaultPermission() {
        return false;
    }
}

@@ -975,16 +975,169 @@
   try %7B%0A
+                synchronized (FlareBot.getInstance().getClients()) %7B%0A                    FlareBot.getInstance().getClients()%5Bshard%5D.shutdown(false);%0A    
         
@@ -1249,20 +1249,16 @@
         
-   
- 
 .addList
@@ -1294,28 +1294,24 @@
 etEvents())%0A
-    
             
@@ -1414,28 +1414,24 @@
             
-    
 .setToken(Fl
@@ -1473,28 +1473,24 @@
             
-   
- 
 .setAudioSen
@@ -1556,20 +1556,16 @@
         
-    
 .buildAs
@@ -1571,16 +1571,34 @@
 sync();%0A
+                %7D%0A
         

Fix shard restart