New `InternalCommandsModule`
Moved help command to `InternalCommandsModule` `CommandDispatcher` as a singletonmaster
parent
0df7e7b4f0
commit
039e62b311
@ -0,0 +1,42 @@
|
||||
package net.pingex.discordbot;
|
||||
|
||||
import sx.blah.discord.api.IDiscordClient;
|
||||
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Internal commands of the bot, such as `help`, and so on
|
||||
* @version 0.1-dev
|
||||
* @author Raphael "Pingex" NAAS
|
||||
*/
|
||||
@Controllable(name="internal")
|
||||
public class InternalCommandsModule extends AbstractModule
|
||||
{
|
||||
public InternalCommandsModule(IDiscordClient client)
|
||||
{
|
||||
super(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans and print the usage of a command
|
||||
* @param command Full command, ie `module:command`
|
||||
* @return The man of this command
|
||||
*/
|
||||
@Command(shorthand = "help")
|
||||
public String help(MessageReceivedEvent event, String command)
|
||||
{
|
||||
if(!command.contains(":") && CommandDispatcher.getInstance().getShortList().containsKey(command))
|
||||
command = CommandDispatcher.getInstance().getShortList().get(command);
|
||||
|
||||
if(!CommandDispatcher.getInstance().getCommandList().containsKey(command)) return "No help available for this command.";
|
||||
InvokableMethod matchingMethod = CommandDispatcher.getInstance().getCommandList().get(command);
|
||||
|
||||
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() + " ");
|
||||
|
||||
return toReturn.toString();
|
||||
}
|
||||
}
|
Reference in New Issue