Improved help and actually added it to cmds

This commit is contained in:
Norbi Peti 2016-11-12 20:14:16 +01:00
parent 6a4b776c37
commit 8c5dd3b320
5 changed files with 52 additions and 8 deletions

View file

@ -36,10 +36,16 @@ public class CommandListener {
String cmdwithargs = message.getContent();
final String mention = DiscordPlugin.dc.getOurUser().mention(false);
final String mentionNick = DiscordPlugin.dc.getOurUser().mention(true);
if (message.getContent().startsWith(mention) && cmdwithargs.length() > mention.length() + 1) // TODO: Resolve mentions: Compound arguments, either a mention or text
cmdwithargs = cmdwithargs.substring(mention.length() + 1);
if (message.getContent().startsWith(mentionNick) && cmdwithargs.length() > mentionNick.length() + 1)
cmdwithargs = cmdwithargs.substring(mentionNick.length() + 1);
if (message.getContent().startsWith(mention)) // TODO: Resolve mentions: Compound arguments, either a mention or text
if (cmdwithargs.length() > mention.length() + 1)
cmdwithargs = cmdwithargs.substring(mention.length() + 1);
else
cmdwithargs = "help";
if (message.getContent().startsWith(mentionNick))
if (cmdwithargs.length() > mentionNick.length() + 1)
cmdwithargs = cmdwithargs.substring(mentionNick.length() + 1);
else
cmdwithargs = "help";
int index = cmdwithargs.indexOf(' ');
String cmd;
String args;

View file

@ -65,4 +65,13 @@ public class ConnectCommand extends DiscordCommandBase {
+ message.getAuthor().getDiscriminator() + " do /discord accept");
}
@Override
public String[] getHelpText() {
return new String[] { //
"---- Connect command ----", //
"This commands let's you connect your acoount with a Minecraft account. This'd allow using the Minecraft chat and other things.", //
"Usage: connect <Minecraftname>" //
};
}
}

View file

@ -10,19 +10,22 @@ public abstract class DiscordCommandBase {
public abstract String getCommandName();
public abstract void run(IMessage message, String args);
public abstract String[] getHelpText();
static final HashMap<String, DiscordCommandBase> commands = new HashMap<String, DiscordCommandBase>();
static {
commands.put("connect", new ConnectCommand()); // TODO: API for adding commands?
commands.put("userinfo", new UserinfoCommand());
commands.put("help", new HelpCommand());
}
public static void runCommand(String cmd, String args, IMessage message) {
DiscordCommandBase command = commands.get(cmd);
if (command == null) {
// TODO: Help command
DiscordPlugin.sendMessageToChannel(message.getChannel(), "Unknown command: " + cmd + " with args: " + args);
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"Unknown command: " + cmd + " with args: " + args + "\nDo @ChromaBot help for help");
return;
}
try {

View file

@ -1,5 +1,6 @@
package buttondevteam.discordplugin.commands;
import java.util.Arrays;
import java.util.stream.Collectors;
import buttondevteam.discordplugin.DiscordPlugin;
@ -14,8 +15,24 @@ public class HelpCommand extends DiscordCommandBase {
@Override
public void run(IMessage message, String args) {
DiscordPlugin.sendMessageToChannel(message.getChannel(), "Available commands:\n" + DiscordCommandBase.commands
.values().stream().map(dc -> dc.getCommandName()).collect(Collectors.joining("\n")));
DiscordCommandBase argdc;
if (args.length() == 0)
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"Available commands:\n" + DiscordCommandBase.commands.values().stream()
.map(dc -> dc.getCommandName()).collect(Collectors.joining("\n")));
else
DiscordPlugin.sendMessageToChannel(message.getChannel(),
(argdc = DiscordCommandBase.commands.get(args)) == null ? "Command not found: " + args
: Arrays.stream(argdc.getHelpText()).collect(Collectors.joining("\n")));
}
@Override
public String[] getHelpText() {
return new String[] { //
"---- Help command ----", //
"Shows some info about a command or lists the available commands.", //
"Usage: help [command]"//
};
}
}

View file

@ -82,4 +82,13 @@ public class UserinfoCommand extends DiscordCommandBase {
"The user is not found in our system (player has to be on the MC server for now)!");
}
@Override
public String[] getHelpText() {
return new String[] { //
"---- User information ----", //
"Shows some information about users, from Discord, from Minecraft or from Reddit if they have these accounts connected.", //
"Usage: userinfo <Discordname>" //
};
}
}