package com.robothand.highqualitybot.command;

import com.robothand.highqualitybot.Config;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;

import java.util.ArrayList;
import java.util.Hashtable;

/**
 * Created by ethan on 6/22/17.
 */
public class Commands extends ListenerAdapter {
    private static Commands instance = new Commands();

    private final Hashtable<String, Command> commands;

    public static Commands getInstance() {
        return instance;
    }

    private Commands() {
        commands = new Hashtable<>();
    }

    public void setupListeners(JDA jda) {
        for (String key : commands.keySet()) {
            jda.addEventListener(commands.get(key));
        }
    }

    public void addCommand(Command command) {
        if (command != null) {
            for (String current : command.getNames()) {
                commands.put(current, command);
            }
        }
    }

    @Override
    public void onMessageReceived(MessageReceivedEvent event) {
        // grab basic info from event
        Message message = event.getMessage();
        String content = message.getRawContent();

        // check for command prefix
        if (content.startsWith(Config.PREFIX)) {
            // strip it off and split it
            String[] args = content.replaceFirst(Config.PREFIX, "").split(" ");

            // check for command in aliases
            for (String current : commands.keySet()) {
                if (args[0].equals(current)) {
                    commands.get(current).requestExecute(event, args);
                    break;
                }
            }
        }
    }

    public Command getCommand(String name) {
        return commands.get(name);
    }

    public ArrayList<Command> getCommands() {
        return new ArrayList<>(commands.values());
    }
}

@@ -278,16 +278,73 @@
 Adapter;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -406,34 +406,184 @@
  * C
-reated by ethan on 6/22/17
+ommands.java%0A * Singleton that maintains a Hashtable of all available commands and attempts to execute the proper command when a%0A * valid command message is received by the bot
 .%0A *
@@ -683,25 +683,24 @@
 Commands();%0A
-%0A
     private 
@@ -741,16 +741,82 @@
 ommands;
+%0A    private Logger log = LoggerFactory.getLogger(Commands.class);
 %0A%0A    pu
@@ -962,162 +962,64 @@
     
-public void setupListeners(JDA jda) %7B%0A        for (String key : commands.keySet()) %7B%0A            jda.addEventListener(commands.get(key));%0A        %7D%0A    %7D%0A
+// Adds a new Command to the Hashtable of known commands
 %0A   
@@ -1088,24 +1088,92 @@
  != null) %7B%0A
+            log.debug(%22Adding command: %7B%7D%22, command.getNames()%5B0%5D);%0A
             
@@ -1291,24 +1291,133 @@
    %7D%0A    %7D%0A%0A
+    // When a message is received on a Guild this bot is a member of, attempts to run an applicable command.%0A
     @Overrid
@@ -1868,16 +1868,51 @@
 aliases%0A
+            boolean found = false;%0A
         
@@ -2076,16 +2076,50 @@
  args);%0A
+                    found = true;%0A
         
@@ -2173,32 +2173,240 @@
   %7D%0A        
-%7D%0A    %7D%0A
+    if (!found) %7B%0A                log.info(%22Ignoring message from %7B%7D. %5C%22%7B%7D%5C%22 is not a known command.%22, event.getAuthor().getName(), args%5B0%5D);%0A            %7D%0A        %7D%0A    %7D%0A%0A    // Gets a Command by one of its aliases
 %0A    public 
@@ -2477,24 +2477,68 @@
 me);%0A    %7D%0A%0A
+    // Get the entire Hashtable of Commands%0A
     public A

add logging to Commands.java