Change global flag to always return true and make ability flags as predicates
This commit is contained in:
parent
3414d8c9f5
commit
1f5706b525
|
@ -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.
|
||||||
* <p>
|
* <p>
|
||||||
* This method should be <b>overridden</b> if the user wants updates that don't require a MESSAGE to pass through.
|
* This method should be <b>overridden</b> if the user wants to restrict bot usage to only certain updates.
|
||||||
*
|
*
|
||||||
* @param update a Telegram {@link Update}
|
* @param update a Telegram {@link Update}
|
||||||
* @return <tt>true</tt> if the update satisfies the global flags
|
* @return <tt>true</tt> if the update satisfies the global flags
|
||||||
*/
|
*/
|
||||||
protected boolean checkGlobalFlags(Update update) {
|
protected boolean checkGlobalFlags(Update update) {
|
||||||
return MESSAGE.test(update);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -149,7 +149,7 @@ public final class Ability {
|
||||||
private Consumer<MessageContext> consumer;
|
private Consumer<MessageContext> consumer;
|
||||||
private Consumer<MessageContext> postConsumer;
|
private Consumer<MessageContext> postConsumer;
|
||||||
private List<Reply> replies;
|
private List<Reply> replies;
|
||||||
private Flag[] flags;
|
private Predicate<Update>[] flags;
|
||||||
|
|
||||||
private AbilityBuilder() {
|
private AbilityBuilder() {
|
||||||
replies = newArrayList();
|
replies = newArrayList();
|
||||||
|
@ -170,7 +170,7 @@ public final class Ability {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbilityBuilder flag(Flag... flags) {
|
public AbilityBuilder flag(Predicate<Update>... flags) {
|
||||||
this.flags = flags;
|
this.flags = flags;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -410,13 +410,9 @@ public class AbilityBotTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canCheckGlobalFlags() {
|
public void defaultGlobalFlagIsTrue() {
|
||||||
Update update = mock(Update.class);
|
Update update = mock(Update.class);
|
||||||
Message message = mock(Message.class);
|
assertEquals("Unexpected result when checking for the default global flags", true, bot.checkGlobalFlags(update));
|
||||||
|
|
||||||
when(update.hasMessage()).thenReturn(true);
|
|
||||||
when(update.getMessage()).thenReturn(message);
|
|
||||||
assertEquals("Unexpected result when checking for locality", true, bot.checkGlobalFlags(update));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ArithmeticException.class)
|
@Test(expected = ArithmeticException.class)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user