Skip to content

Commit

Permalink
Merge pull request rubenlagus#789 from addo37/fix-longest-match
Browse files Browse the repository at this point in the history
Fix matching longest ability name on continuous text feature
  • Loading branch information
rubenlagus authored Aug 1, 2020
2 parents 749c6d3 + 402c36e commit e6b9fd8
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static java.lang.String.format;
import static java.time.ZonedDateTime.now;
import static java.util.Arrays.stream;
import static java.util.Comparator.comparingInt;
import static java.util.Objects.isNull;
import static java.util.Optional.ofNullable;
import static java.util.regex.Pattern.CASE_INSENSITIVE;
Expand Down Expand Up @@ -517,7 +518,8 @@ Trio<Update, Ability, String[]> getAbility(Update update) {
if (allowContinuousText()) {
String abName = abilities.keySet().stream()
.filter(name -> msg.getText().startsWith(format("%s%s", getCommandPrefix(), name)))
.findFirst().orElse(DEFAULT);
.max(comparingInt(String::length))
.orElse(DEFAULT);
tokens = msg.getText()
.replaceFirst(getCommandPrefix() + abName, "")
.split(getCommandRegexSplit());
Expand Down

0 comments on commit e6b9fd8

Please sign in to comment.