From 1f5706b525656887d741cb9e8f028090c2bb6039 Mon Sep 17 00:00:00 2001 From: Abbas Abou Daya Date: Tue, 31 Oct 2017 23:06:03 -0400 Subject: [PATCH] Change global flag to always return true and make ability flags as predicates --- .../java/org/telegram/abilitybots/api/bot/AbilityBot.java | 6 +++--- .../org/telegram/abilitybots/api/objects/Ability.java | 4 ++-- .../org/telegram/abilitybots/api/bot/AbilityBotTest.java | 8 ++------ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityBot.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityBot.java index f102ec6f..c512e7c4 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityBot.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityBot.java @@ -220,15 +220,15 @@ public abstract class AbilityBot extends TelegramLongPollingBot { } /** - * Test the update against the provided global flags. The default implementation requires a {@link Flag#MESSAGE}. + * Test the update against the provided global flags. The default implementation is a passthrough to all updates. *

- * This method should be overridden if the user wants updates that don't require a MESSAGE to pass through. + * This method should be overridden if the user wants to restrict bot usage to only certain updates. * * @param update a Telegram {@link Update} * @return true if the update satisfies the global flags */ protected boolean checkGlobalFlags(Update update) { - return MESSAGE.test(update); + return true; } /** diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Ability.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Ability.java index 1064bb29..43446eef 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Ability.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Ability.java @@ -149,7 +149,7 @@ public final class Ability { private Consumer consumer; private Consumer postConsumer; private List replies; - private Flag[] flags; + private Predicate[] flags; private AbilityBuilder() { replies = newArrayList(); @@ -170,7 +170,7 @@ public final class Ability { return this; } - public AbilityBuilder flag(Flag... flags) { + public AbilityBuilder flag(Predicate... flags) { this.flags = flags; return this; } diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java index feac9999..634d222d 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java @@ -410,13 +410,9 @@ public class AbilityBotTest { } @Test - public void canCheckGlobalFlags() { + public void defaultGlobalFlagIsTrue() { Update update = mock(Update.class); - Message message = mock(Message.class); - - when(update.hasMessage()).thenReturn(true); - when(update.getMessage()).thenReturn(message); - assertEquals("Unexpected result when checking for locality", true, bot.checkGlobalFlags(update)); + assertEquals("Unexpected result when checking for the default global flags", true, bot.checkGlobalFlags(update)); } @Test(expected = ArithmeticException.class)