Merge pull request #6 from Salmonllama/master
Update database-rewrite branch
This commit is contained in:
commit
e7a7b4f40e
@ -105,7 +105,8 @@ public class Guthix implements MessageCreateListener {
|
||||
return;
|
||||
}
|
||||
|
||||
String cmdString = registry.commandString(content);
|
||||
RegistryCommand rComm = registry.getCommandInfo(content);
|
||||
String cmdString = rComm.getCommand();
|
||||
|
||||
if (registry.isCommandAlias(cmdString)) {
|
||||
|
||||
@ -116,7 +117,7 @@ public class Guthix implements MessageCreateListener {
|
||||
Message msg = event.getMessage();
|
||||
TextChannel channel = event.getChannel();
|
||||
Server server = event.getServer().orElse(null);
|
||||
String[] cmdArgs = registry.getCmdArgs(content);
|
||||
String[] cmdArgs = rComm.getArgs();
|
||||
|
||||
Command cmd = registry.findCommand(cmdString).orElse(null); // TODO: default command here
|
||||
|
||||
|
@ -73,21 +73,25 @@ class Registry {
|
||||
if (input.contains(" ")) {
|
||||
input = removePrefix(input);
|
||||
String[] splits = input.split(" ");
|
||||
return new ArrayList<>(Arrays.asList(splits));
|
||||
System.out.println(Arrays.toString(splits));
|
||||
return cleanSpaces(splits);
|
||||
} else {
|
||||
input = removePrefix(input);
|
||||
return new ArrayList<>(Collections.singletonList(input));
|
||||
}
|
||||
}
|
||||
|
||||
String[] getCmdArgs(String input) {
|
||||
List<String> splits = splitArgs(input);
|
||||
splits.remove(0);
|
||||
return splits.toArray(new String[0]);
|
||||
List<String> cleanSpaces(String[] input) {
|
||||
List<String> list = new ArrayList<>(Arrays.asList(input));
|
||||
list.removeIf(""::equals);
|
||||
return list;
|
||||
}
|
||||
|
||||
String commandString(String input) {
|
||||
// Cleans the string of the prefix and any args, returning only the command
|
||||
return splitArgs(input).get(0);
|
||||
RegistryCommand getCommandInfo(String input) {
|
||||
List<String> args = splitArgs(input);
|
||||
String command = args.get(0);
|
||||
args.remove(0);
|
||||
|
||||
return new RegistryCommand(command, args.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2020. Aleksei Gryczewski
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package dev.salmonllama.fsbot.guthix;
|
||||
|
||||
class RegistryCommand {
|
||||
private String command;
|
||||
private String[] args;
|
||||
|
||||
|
||||
RegistryCommand(String command, String[] args) {
|
||||
this.command = command;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
String[] getArgs() {
|
||||
return args;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user