/*
 * MIT License
 *
 * Copyright (c) 2017 Frederik Ar. 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.FredBoat;
import fredboat.commandmeta.abs.Command;
import fredboat.commandmeta.abs.ICommandAdminRestricted;
import fredboat.util.TextUtils;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel;

/**
 *
 * @author frederik
 */
public class ReviveCommand extends Command implements ICommandAdminRestricted {

    @Override
    public void onInvoke(Guild guild, TextChannel channel, Member invoker, Message message, String[] args) {
        int shardId = Integer.parseInt(args[1]);

        channel.sendMessage(TextUtils.prefaceWithName(invoker, " Reviving shard " + shardId)).queue();
        FredBoat.getInstance(shardId).revive();
    }

    @Override
    public String help(Guild guild) {
        return "{0}{1} <shardId>\n#Revive the specified shard.";
    }
}

@@ -1191,24 +1191,90 @@
 redboat.
-FredBoat
+Config;%0Aimport fredboat.FredBoat;%0Aimport fredboat.command.util.HelpCommand
 ;%0Aimport
@@ -1814,24 +1814,25 @@
 g%5B%5D args) %7B%0A
+%0A
         int 
@@ -1842,37 +1842,626 @@
 rdId
- = Integer.parseInt(args%5B1%5D);
+;%0A        try %7B%0A            if (args%5B1%5D.equals(%22guild%22)) %7B%0A                long guildId = Long.valueOf(args%5B2%5D);%0A                //https://discordapp.com/developers/docs/topics/gateway#sharding%0A                shardId = (int) ((guildId %3E%3E 22) %25 Config.CONFIG.getNumShards());%0A            %7D else%0A                shardId = Integer.parseInt(args%5B1%5D);%0A%0A        %7D catch (NumberFormatException %7C IndexOutOfBoundsException e) %7B%0A            String command = args%5B0%5D.substring(Config.CONFIG.getPrefix().length());%0A            HelpCommand.sendFormattedCommandHelp(guild, channel, invoker, command);%0A            return;%0A        %7D
 %0A%0A  
@@ -2557,24 +2557,42 @@
 )).queue();%0A
+        try %7B%0A    
         Fred
@@ -2623,24 +2623,189 @@
 ).revive();%0A
+        %7D catch (IndexOutOfBoundsException e) %7B%0A            channel.sendMessage(TextUtils.prefaceWithName(invoker, %22 No such shard: %22 + shardId)).queue();%0A        %7D%0A
     %7D%0A%0A    @
@@ -2883,16 +2883,42 @@
 shardId%3E
+ OR %7B0%7D%7B1%7D guild %3CguildId%3E
 %5Cn#Reviv
@@ -2938,16 +2938,53 @@
 ed shard
+, or the shard of the specified guild
 .%22;%0A    

Extend ReviveCommand usage with a guildId