Add default behaviour for some methods in CommandBot interface

This commit is contained in:
Korsakov A.N. (20211) 2022-02-10 12:07:22 +05:00
parent 54575990bc
commit db8aa6ac3e
3 changed files with 6 additions and 28 deletions

View File

@ -24,7 +24,9 @@ public interface CommandBot {
*
* @param update Received update from Telegram
*/
void processInvalidCommandUpdate(Update update);
default void processInvalidCommandUpdate(Update update) {
processNonCommandUpdate(update);
}
/**
* Override this function in your bot implementation to filter messages with commands
@ -39,5 +41,7 @@ public interface CommandBot {
* false otherwise
* @note Default implementation doesn't filter anything
*/
boolean filter(Message message);
default boolean filter(Message message) {
return false;
}
}

View File

@ -70,16 +70,6 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
processNonCommandUpdate(update);
}
@Override
public void processInvalidCommandUpdate(Update update) {
processNonCommandUpdate(update);
}
@Override
public boolean filter(Message message) {
return false;
}
@Override
public final boolean register(IBotCommand botCommand) {
return commandRegistry.register(botCommand);

View File

@ -72,16 +72,6 @@ public abstract class TelegramWebhookCommandBot extends TelegramWebhookBot imple
return null;
}
@Override
public void processInvalidCommandUpdate(Update update) {
processNonCommandUpdate(update);
}
@Override
public boolean filter(Message message) {
return false;
}
@Override
public final boolean register(IBotCommand botCommand) {
return commandRegistry.register(botCommand);
@ -116,10 +106,4 @@ public abstract class TelegramWebhookCommandBot extends TelegramWebhookBot imple
public final IBotCommand getRegisteredCommand(String commandIdentifier) {
return commandRegistry.getRegisteredCommand(commandIdentifier);
}
/**
* @return Bot username
*/
@Override
public abstract String getBotUsername();
}