|
|
|
@ -12,6 +12,8 @@ import java.util.Map;
|
|
|
|
|
@Controllable(name="internal")
|
|
|
|
|
class InternalCommandsModule extends AbstractModule
|
|
|
|
|
{
|
|
|
|
|
private static final int LINES_PER_PAGE = 10;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor doing all the basic stuff, like registering as a Listener to Discord, getting a logger, etc.
|
|
|
|
|
* @param client Discord Client instance used to register self.
|
|
|
|
@ -82,7 +84,7 @@ class InternalCommandsModule extends AbstractModule
|
|
|
|
|
Map<String, String> shorthands = CommandDispatcher.getInstance().getShortList();
|
|
|
|
|
if(page == null) page = 1;
|
|
|
|
|
|
|
|
|
|
int pagesCount = (int) Math.ceil(commands.size()/10.0);
|
|
|
|
|
int pagesCount = (int) Math.ceil(commands.size()/(double)LINES_PER_PAGE);
|
|
|
|
|
if(page > pagesCount || page <= 0)
|
|
|
|
|
return "Page #" + page + " doesn't exist. " + pagesCount + " pages are available.";
|
|
|
|
|
|
|
|
|
@ -90,13 +92,25 @@ class InternalCommandsModule extends AbstractModule
|
|
|
|
|
toReturn.append("(page ").append(page).append("/").append(pagesCount).append(") ");
|
|
|
|
|
toReturn.append("- Call `" + Configuration.getValue("general", "commandPrefix") + "help command` for individual help and usage.\n");
|
|
|
|
|
|
|
|
|
|
int maxNameLength = 0, maxDescLength = 0;
|
|
|
|
|
for(Map.Entry<String, InvokableMethod> i : commands.entrySet())
|
|
|
|
|
{
|
|
|
|
|
// Maximum name length
|
|
|
|
|
if(i.getKey().length() > maxNameLength)
|
|
|
|
|
maxNameLength = i.getKey().length();
|
|
|
|
|
|
|
|
|
|
// Maximum desc length
|
|
|
|
|
if(i.getValue().getMethod().getAnnotation(Command.class).description().length() > maxDescLength)
|
|
|
|
|
maxDescLength = i.getValue().getMethod().getAnnotation(Command.class).description().length();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pos = 1;
|
|
|
|
|
for(Map.Entry<String, InvokableMethod> i : commands.entrySet())
|
|
|
|
|
{
|
|
|
|
|
if(pos > page*10-10 && pos <= page*10)
|
|
|
|
|
if(pos > page*LINES_PER_PAGE-LINES_PER_PAGE && pos <= page*LINES_PER_PAGE)
|
|
|
|
|
{
|
|
|
|
|
toReturn.append("- ").append(i.getKey());
|
|
|
|
|
toReturn.append("\t").append(i.getValue().getMethod().getAnnotation(Command.class).description());
|
|
|
|
|
toReturn.append("* ").append(String.format("%1$-" + (maxNameLength+1) + "s", i.getKey()));
|
|
|
|
|
toReturn.append(String.format("%1$-" + (maxDescLength+1) + "s", i.getValue().getMethod().getAnnotation(Command.class).description()));
|
|
|
|
|
|
|
|
|
|
// Shorthand
|
|
|
|
|
if(shorthands.containsValue(i.getKey()))
|
|
|
|
|