Defer Regex compilation to initialization

This commit is contained in:
Reperak 2021-11-23 21:32:24 -06:00
parent d31d36538e
commit 3df3a069c8
No known key found for this signature in database
GPG key ID: 12F30C9BA6950C0C

View file

@ -24,6 +24,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class Play implements Command { public class Play implements Command {
private static final Pattern URL_PATTERN = Pattern.compile("^(http|https)://([a-z]+\\.[a-z]+)+/\\S+$", Pattern.CASE_INSENSITIVE);
CommandMeta meta = new CommandMeta("play", "Play music!", new String[]{"p"}, false, false); CommandMeta meta = new CommandMeta("play", "Play music!", new String[]{"p"}, false, false);
@Override @Override
@ -52,9 +53,7 @@ public class Play implements Command {
// check if args merged are/have url, if so try to feed it into lava, else try to youtube api the fuck out of it. // check if args merged are/have url, if so try to feed it into lava, else try to youtube api the fuck out of it.
String mergedArgs = String.join(" ", args); String mergedArgs = String.join(" ", args);
Matcher matchedUrls = URL_PATTERN.matcher(mergedArgs);
Pattern urlPattern = Pattern.compile("^(http|https)://([a-z]+\\.[a-z]+)+/\\S+$", Pattern.CASE_INSENSITIVE);
Matcher matchedUrls = urlPattern.matcher(mergedArgs);
boolean urlFound = matchedUrls.find(); boolean urlFound = matchedUrls.find();
String identifier; String identifier;