Merge pull request #789 from addo37/fix-longest-match
Fix matching longest ability name on continuous text feature
This commit is contained in:
commit
e6b9fd892f
@ -36,6 +36,7 @@ import static com.google.common.collect.Sets.difference;
|
|||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
import static java.time.ZonedDateTime.now;
|
import static java.time.ZonedDateTime.now;
|
||||||
import static java.util.Arrays.stream;
|
import static java.util.Arrays.stream;
|
||||||
|
import static java.util.Comparator.comparingInt;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
import static java.util.Optional.ofNullable;
|
import static java.util.Optional.ofNullable;
|
||||||
import static java.util.regex.Pattern.CASE_INSENSITIVE;
|
import static java.util.regex.Pattern.CASE_INSENSITIVE;
|
||||||
@ -517,7 +518,8 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
|
|||||||
if (allowContinuousText()) {
|
if (allowContinuousText()) {
|
||||||
String abName = abilities.keySet().stream()
|
String abName = abilities.keySet().stream()
|
||||||
.filter(name -> msg.getText().startsWith(format("%s%s", getCommandPrefix(), name)))
|
.filter(name -> msg.getText().startsWith(format("%s%s", getCommandPrefix(), name)))
|
||||||
.findFirst().orElse(DEFAULT);
|
.max(comparingInt(String::length))
|
||||||
|
.orElse(DEFAULT);
|
||||||
tokens = msg.getText()
|
tokens = msg.getText()
|
||||||
.replaceFirst(getCommandPrefix() + abName, "")
|
.replaceFirst(getCommandPrefix() + abName, "")
|
||||||
.split(getCommandRegexSplit());
|
.split(getCommandRegexSplit());
|
||||||
|
Loading…
Reference in New Issue
Block a user