/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Command.InformationModule;

import Command.*;
import static Command.InformationModule.InfoBotCommand.HELP;
import Config.Emoji;
import Config.Info;
import Config.Prefix;
import Main.Main;
import java.awt.Color;
import java.time.Instant;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

/**
 *
 * @author Alien Ideology <alien.ideology at alien.org>
 */
public class StatusCommand implements Command{

    public final static String HELP = "This command is for getting this bot's status.\n"
                              + "Command Usage: `" + Prefix.getDefaultPrefix() + "status` or `" + Prefix.getDefaultPrefix() + "uptime`\n"
                              + "Parameter: `-h | null`";
    
    private EmbedBuilder embedstatus = new EmbedBuilder();
    private String type = "";
    
    public StatusCommand(String invoke)
    {
        if("status".equals(invoke)) type = "status";
        else if("uptime".equals(invoke)) type = "uptime";
    }
    
    @Override
    public boolean called(String[] args, MessageReceivedEvent e) {
        return true;
    }

    @Override
    public void help(MessageReceivedEvent e) {
        embed.setColor(Color.red);
        embed.setTitle("Information Module", null);
        embed.addField("Status -Help", HELP, true);
        embed.setFooter("Command Help/Usage", Info.I_help);
        embed.setTimestamp(Instant.now());

        MessageEmbed me = embed.build();
        e.getChannel().sendMessage(me).queue();
        embed.clearFields();
    }

    @Override
    public void action(String[] args, MessageReceivedEvent e) {
        
        JDA bot = e.getJDA();
        String avatar, status, game, shard, upinfo;
        int guild;
        long timeCurrent = System.currentTimeMillis(), uptime;

        avatar = bot.getSelfUser().getAvatarUrl();
        status = bot.getPresence().getStatus().getKey();
        guild = bot.getGuilds().size();
        try{shard = bot.getShardInfo().getShardString();} catch(NullPointerException ne) {shard = "None";}
        uptime = timeCurrent - Main.timeStart;
        upinfo = uptime/3600000 + " hours, " + (uptime/60000)%60 + " minutes, and " + (uptime/1000)%60 + " seconds.";
        
        if(args.length > 0 && "-h".equals(args[0]))
        {
            help(e);
        }
        
        if(args.length == 0)
        {
            if("uptime".equals(type))
            {
                e.getTextChannel().sendMessage(Emoji.stopwatch + " AIBot has been up for: " + upinfo).queue();
            }

            else if("status".equals(type))
            {
                embedstatus.setColor(Color.blue);
                embedstatus.setTitle("AIBot Status", null);
                embedstatus.setThumbnail(avatar);

                embedstatus.addField(Emoji.stopwatch + " Uptime", upinfo, true);
                embedstatus.addField(Emoji.status + " Status", status, true);
                embedstatus.addField(Emoji.guilds + " Servers", String.valueOf(guild), true);
                embedstatus.addField(Emoji.shards + "Shards", shard, true);
                embedstatus.setFooter("Requested by " + e.getAuthor().getName(), e.getAuthor().getEffectiveAvatarUrl());
                embedstatus.setTimestamp(Instant.now());

                MessageEmbed me = embedstatus.build();
                e.getChannel().sendMessage(me).queue();
                embedstatus.clearFields();   
            }
        }
    }

    @Override
    public void executed(boolean success, MessageReceivedEvent e) {
        
    }
    
}

@@ -613,16 +613,47 @@
 edEvent;
+%0Aimport java.lang.management.*;
 %0A%0A/**%0A *
@@ -2018,16 +2018,22 @@
 , upinfo
+, more
 ;%0A      
@@ -2213,24 +2213,101 @@
 ).getKey();%0A
+        status = status.substring(0, 1).toUpperCase() + status.substring(1);%0A
         guil
@@ -2607,32 +2607,714 @@
 nds.%22;%0A        %0A
+        OperatingSystemMXBean os = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();%0A        double loadAverage = os.getSystemLoadAverage();%0A        int processors = os.getAvailableProcessors();%0A        String osversion = os.getVersion();%0A        %0A        MemoryUsage osx = (MemoryUsage)ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();%0A        String memory = osx.getUsed() + %22/%22 + osx.getCommitted() + %22 bytes%22;%0A        %0A        more = %22Load Average: %22 + loadAverage%0A               + %22%5CnAvailable Processors: %22 + processors %0A               + %22%5CnOperating System Version: Mac Sierra %22 + osversion%0A               + %22%5CnUsed Memory: %22 + memory;%0A        %0A
         if(args.
@@ -4140,16 +4140,17 @@
 ards + %22
+ 
 Shards%22,
@@ -4156,32 +4156,93 @@
 , shard, true);%0A
+                embedstatus.addField(%22More...%22, more, true);%0A
                 

Add System info like memory usage