From 402c36e6b25813dfea7b819f086d48e92bc497ad Mon Sep 17 00:00:00 2001 From: Abbas Abou Daya Date: Sat, 1 Aug 2020 05:56:50 -0700 Subject: [PATCH] Fix matching longest ability name on continuous text feature --- .../java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java index 4df00437..317f222f 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java @@ -36,6 +36,7 @@ import static com.google.common.collect.Sets.difference; 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; @@ -517,7 +518,8 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability 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());