|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package net.pingex.discordbot;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.ClassUtils;
|
|
|
|
|
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
|
|
|
|
import sx.blah.discord.api.EventSubscriber;
|
|
|
|
|
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
|
|
|
@ -112,24 +113,37 @@ class CommandDispatcher
|
|
|
|
|
|
|
|
|
|
if(commandAnswer == null)
|
|
|
|
|
{
|
|
|
|
|
if(foundMethod.getMethod().getParameterCount()-1 == args.size())
|
|
|
|
|
if(foundMethod.getMethod().getParameterCount()-1 >= args.size())
|
|
|
|
|
{
|
|
|
|
|
for(int i=1; i < foundMethod.getMethod().getParameterCount(); i++)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
parsedArray[i] = parse(foundMethod.getMethod().getParameterTypes()[i], args.get(i-1));
|
|
|
|
|
parsedArray[i] = parse(foundMethod.getMethod().getParameterTypes()[i], args.size() > i-1 ? args.get(i-1) : null);
|
|
|
|
|
} catch (IllegalArgumentException e)
|
|
|
|
|
{
|
|
|
|
|
commandAnswer = "Failed to parse arguments, are they correct ? Call `/help " + fullCommand + "` for help.";
|
|
|
|
|
commandAnswer = "Invalid arguments. Call `" + Configuration.getValue("general", "commandPrefix") + "help " + fullCommand + "` for help.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to know if the field is required (or not) from the Command annotation
|
|
|
|
|
boolean isRequired = true;
|
|
|
|
|
try { isRequired = foundMethod.getMethod().getAnnotation(Command.class).required()[i-1]; } catch (ArrayIndexOutOfBoundsException e) {}
|
|
|
|
|
|
|
|
|
|
// if(ArgumentIsNull && (IsRequired || ArgumentIsRealPrimitiveOrObject))
|
|
|
|
|
if(parsedArray[i] == null && (isRequired ||
|
|
|
|
|
!(ClassUtils.isPrimitiveWrapper(foundMethod.getMethod().getParameterTypes()[i]) || foundMethod.getMethod().getParameterTypes()[i] == String.class)))
|
|
|
|
|
{
|
|
|
|
|
commandAnswer = "Invalid arguments. Call `" + Configuration.getValue("general", "commandPrefix") + "help " + fullCommand + "` for help.";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
commandAnswer = "Invalid arguments. Call `/help " + fullCommand + "` for help.";
|
|
|
|
|
commandAnswer = "Invalid arguments. Call `" + Configuration.getValue("general", "commandPrefix") + "help " + fullCommand + "` for help.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
commandAnswer = "Unknown command. Call `/list 1` to see all available commands.";
|
|
|
|
|
commandAnswer = "Unknown command. Call `" + Configuration.getValue("general", "commandPrefix") + "list` to see all available commands.";
|
|
|
|
|
|
|
|
|
|
// Run command
|
|
|
|
|
if(commandAnswer == null)
|
|
|
|
@ -151,10 +165,6 @@ class CommandDispatcher
|
|
|
|
|
} catch (MissingPermissionsException | HTTP429Exception | DiscordException e)
|
|
|
|
|
{
|
|
|
|
|
logger.warning("Couldn't reply to command (" + e.getClass().getName() + "): " + e.getMessage());
|
|
|
|
|
} catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logger.severe("Error in threaded command");
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|