|
|
|
@ -2,8 +2,7 @@ package net.pingex.discordbot;
|
|
|
|
|
|
|
|
|
|
import sx.blah.discord.api.IDiscordClient;
|
|
|
|
|
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Internal commands of the bot, such as `help`, and so on
|
|
|
|
@ -45,4 +44,52 @@ class InternalCommandsModule extends AbstractModule
|
|
|
|
|
|
|
|
|
|
return toReturn.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List all commands registered
|
|
|
|
|
* @param page Page number
|
|
|
|
|
* @return String representation of this command
|
|
|
|
|
*/
|
|
|
|
|
@Command(shorthand = "list", description = "List all commands available to you.")
|
|
|
|
|
public String list(MessageReceivedEvent event, int page)
|
|
|
|
|
{
|
|
|
|
|
Map<String, InvokableMethod> commands = CommandDispatcher.getInstance().getCommandList();
|
|
|
|
|
Map<String, String> shorthands = CommandDispatcher.getInstance().getShortList();
|
|
|
|
|
|
|
|
|
|
int pagesCount = (int) Math.ceil(commands.size()/10.0);
|
|
|
|
|
if(page > pagesCount || page <= 0)
|
|
|
|
|
return "Page doesn't exist. " + pagesCount + " pages are available.";
|
|
|
|
|
|
|
|
|
|
StringBuffer toReturn = new StringBuffer("List of commands ");
|
|
|
|
|
toReturn.append("(page ").append(page).append("/").append(pagesCount).append(")\n");
|
|
|
|
|
|
|
|
|
|
int pos = 1;
|
|
|
|
|
for(Map.Entry<String, InvokableMethod> i : commands.entrySet())
|
|
|
|
|
{
|
|
|
|
|
if(pos > page*10-10 && pos <= page*10)
|
|
|
|
|
{
|
|
|
|
|
toReturn.append("- ").append(i.getKey());
|
|
|
|
|
for(Class<?> j : i.getValue().getMethod().getParameterTypes())
|
|
|
|
|
if(j != MessageReceivedEvent.class)
|
|
|
|
|
toReturn.append(" <").append(j.getName()).append(">");
|
|
|
|
|
toReturn.append("\t\t").append(i.getValue().getMethod().getAnnotation(Command.class).description());
|
|
|
|
|
|
|
|
|
|
// Shorthand
|
|
|
|
|
if(shorthands.containsValue(i.getKey()))
|
|
|
|
|
{
|
|
|
|
|
toReturn.append(" (shorthand: ");
|
|
|
|
|
for(Map.Entry<String, String> j : shorthands.entrySet())
|
|
|
|
|
if(j.getValue().equals(i.getKey()))
|
|
|
|
|
{
|
|
|
|
|
toReturn.append(j.getKey());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
toReturn.append(")");
|
|
|
|
|
}
|
|
|
|
|
toReturn.append("\n");
|
|
|
|
|
}
|
|
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
return toReturn.toString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|