|
|
|
@ -4,14 +4,16 @@ import net.pingex.dcf.commands.parser.BasicParser;
|
|
|
|
|
import net.pingex.dcf.commands.parser.ICommandParser;
|
|
|
|
|
import net.pingex.dcf.commands.parser.ParserException;
|
|
|
|
|
import net.pingex.dcf.modularity.PluginWrapper;
|
|
|
|
|
import net.pingex.dcf.util.DiscordInteractionsUtil;
|
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Landing class for a MRE
|
|
|
|
|
* Landing class for the whole command package
|
|
|
|
|
*/
|
|
|
|
|
public class CommandHandler
|
|
|
|
|
{
|
|
|
|
@ -33,6 +35,7 @@ public class CommandHandler
|
|
|
|
|
String command;
|
|
|
|
|
List<String> arguments;
|
|
|
|
|
|
|
|
|
|
// Parse
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
command = PARSER.parseCommand(event.getMessage().getContent());
|
|
|
|
@ -42,7 +45,26 @@ public class CommandHandler
|
|
|
|
|
{
|
|
|
|
|
return; // Not a command
|
|
|
|
|
}
|
|
|
|
|
LOGGER.debug("Attempting to run command {} by user #{}.", command, event.getMessage().getAuthor().getID());
|
|
|
|
|
LOGGER.debug("Attempting to run command {} for user #{}.", command, event.getMessage().getAuthor().getID());
|
|
|
|
|
|
|
|
|
|
// Query command from the bank
|
|
|
|
|
Optional<Command> targetCommand = CommandRegistry.getCommandOrAliasByName(command);
|
|
|
|
|
if(!targetCommand.isPresent())
|
|
|
|
|
{
|
|
|
|
|
LOGGER.debug("No command with that name was found.");
|
|
|
|
|
DiscordInteractionsUtil.sendMessage(event.getMessage().getChannel(), "Command not found. Use `!list` to get a list of all available commands.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run it
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
targetCommand.get().execute(event, arguments);
|
|
|
|
|
}
|
|
|
|
|
catch(Throwable throwable)
|
|
|
|
|
{
|
|
|
|
|
LOGGER.error("Error while executing command " + command + ".", throwable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|