Created ResponderContext#getUsageParts to get a list of parts from a message

This commit is contained in:
mathias 2021-10-03 19:05:02 +02:00
parent 974b55fba7
commit 91e3e70020
No known key found for this signature in database
GPG Key ID: 8950DF62139C852A

View File

@ -11,7 +11,10 @@ import de.gnmyt.autoresponder.event.group.GroupMessageReceivedEvent;
import de.gnmyt.autoresponder.http.controller.HttpResponseController;
import de.gnmyt.autoresponder.http.handler.SimpleHttpHandler;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ResponderContext extends SimpleHttpHandler {
@ -82,6 +85,24 @@ public class ResponderContext extends SimpleHttpHandler {
}
}
/**
* Gets the full message in parts (splits with spaces and quotation marks)
*
* @param input The message input
* @return the full message in parts
*/
public ArrayList<Object> getUsageParts(String input) {
Matcher argumentMatcher = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(input);
ArrayList<Object> arguments = new ArrayList<>();
while (argumentMatcher.find()) {
arguments.add(argumentMatcher.group(1));
}
return arguments;
}
/**
* Sends the usage error reply
*