Added default command for fallback catching

This commit is contained in:
Aleksei 2020-07-23 20:34:06 -04:00
parent 0f1316aa30
commit d1dd1fe758
2 changed files with 35 additions and 6 deletions

View File

@ -0,0 +1,29 @@
package dev.salmonllama.fsbot.commands.developer;
import dev.salmonllama.fsbot.guthix.Command;
import dev.salmonllama.fsbot.guthix.CommandContext;
import dev.salmonllama.fsbot.guthix.CommandPermission;
import dev.salmonllama.fsbot.guthix.PermissionType;
import org.javacord.api.entity.message.embed.EmbedBuilder;
import java.util.Collection;
import java.util.Collections;
public class DefaultCommand extends Command {
@Override public String name() { return "Default"; }
@Override public String description() { return "The command that gets invoked when the prefix is used, but the command is not recognized"; }
@Override public String usage() { return "you don't use this command"; }
@Override public String category() { return "Invisible"; }
@Override public CommandPermission permission() { return new CommandPermission(PermissionType.OWNER); }
@Override public Collection<String> aliases() { return Collections.singletonList("default"); }
@Override
public void onCommand(CommandContext ctx) {
EmbedBuilder response = new EmbedBuilder()
.setTitle("Oops!")
.setAuthor(ctx.getApi().getYourself())
.setDescription("That's my prefix, but I don't know that command! Try using `~help` to see what I can do!");
ctx.reply(response);
}
}

View File

@ -101,15 +101,15 @@ public class Guthix implements MessageCreateListener {
RegistryCommand rComm = registry.getCommandInfo(content);
String cmdString = rComm.getCommand().toLowerCase();
if (registry.isCommandAlias(cmdString)) {
} else {
return;
}
// if (registry.isCommandAlias(cmdString)) {
//
// } else {
// return;
// }
String[] cmdArgs = rComm.getArgs();
Command cmd = registry.findCommand(cmdString).orElse(null); // TODO: default command here
Command cmd = registry.findCommand(cmdString).orElse(new DefaultCommand()); // TODO: default command here
CommandContext ctx = new CommandContext.CommandContextBuilder(
event,