|
|
|
@ -26,21 +26,40 @@ class InternalCommandsModule extends AbstractModule
|
|
|
|
|
* @param command Full command, ie `module:command`
|
|
|
|
|
* @return The man of this command
|
|
|
|
|
*/
|
|
|
|
|
@Command(shorthand = "help")
|
|
|
|
|
@Command(shorthand = "help", description = "Gives the usage of a command.")
|
|
|
|
|
public String help(MessageReceivedEvent event, String command)
|
|
|
|
|
{
|
|
|
|
|
if(!command.contains(":") && CommandDispatcher.getInstance().getShortList().containsKey(command))
|
|
|
|
|
// Shorthand and lower-case matcher
|
|
|
|
|
if(!command.contains(":") && CommandDispatcher.getInstance().getShortList().containsKey(command.toLowerCase()))
|
|
|
|
|
command = CommandDispatcher.getInstance().getShortList().get(command.toLowerCase());
|
|
|
|
|
else
|
|
|
|
|
command = command.toLowerCase();
|
|
|
|
|
if(!CommandDispatcher.getInstance().getCommandList().containsKey(command)) return "Command not found.";
|
|
|
|
|
|
|
|
|
|
if(!CommandDispatcher.getInstance().getCommandList().containsKey(command)) return "No help available for this command.";
|
|
|
|
|
InvokableMethod matchingMethod = CommandDispatcher.getInstance().getCommandList().get(command);
|
|
|
|
|
Map<String, String> shorthands = CommandDispatcher.getInstance().getShortList();
|
|
|
|
|
|
|
|
|
|
StringBuffer toReturn = new StringBuffer();
|
|
|
|
|
toReturn.append(Configuration.getValue("general", "commandPrefix")).append(command).append(" - ");
|
|
|
|
|
toReturn.append(matchingMethod.getMethod().getAnnotation(Command.class).description());
|
|
|
|
|
|
|
|
|
|
// Shorthand
|
|
|
|
|
if(shorthands.containsValue(command))
|
|
|
|
|
{
|
|
|
|
|
toReturn.append(" (shorthand: `");
|
|
|
|
|
for(Map.Entry<String, String> i : shorthands.entrySet())
|
|
|
|
|
if(i.getValue().equals(command))
|
|
|
|
|
{
|
|
|
|
|
toReturn.append(i.getKey());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
toReturn.append("`)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuffer toReturn = new StringBuffer("Usage: ");
|
|
|
|
|
toReturn.append((Configuration.exists("general", "commandPrefix") ? Configuration.getValue("general", "commandPrefix") : "!") + command + " ");
|
|
|
|
|
for(int i=1; i<matchingMethod.getMethod().getParameterCount(); i++)
|
|
|
|
|
toReturn.append(matchingMethod.getMethod().getParameterTypes()[i].getName() + " ");
|
|
|
|
|
toReturn.append("\nUsage: ").append(Configuration.getValue("general", "commandPrefix")).append(command);
|
|
|
|
|
for(Class<?> i : matchingMethod.getMethod().getParameterTypes())
|
|
|
|
|
if(i != MessageReceivedEvent.class)
|
|
|
|
|
toReturn.append(" <").append(i.getName()).append(">");
|
|
|
|
|
|
|
|
|
|
return toReturn.toString();
|
|
|
|
|
}
|
|
|
|
|