Merge filter in commandbot
This commit is contained in:
parent
d4dc470706
commit
759d829252
@ -32,7 +32,7 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
|
|||||||
public final void onUpdateReceived(Update update) {
|
public final void onUpdateReceived(Update update) {
|
||||||
if (update.hasMessage()) {
|
if (update.hasMessage()) {
|
||||||
Message message = update.getMessage();
|
Message message = update.getMessage();
|
||||||
if (message.isCommand()) {
|
if (message.isCommand() && !filter(message)) {
|
||||||
if (commandRegistry.executeCommand(this, message)) {
|
if (commandRegistry.executeCommand(this, message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -41,6 +41,23 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
|
|||||||
processNonCommandUpdate(update);
|
processNonCommandUpdate(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function message filter.
|
||||||
|
* Override this function in your bot implementation to filter messages with commands
|
||||||
|
*
|
||||||
|
* For example, if you want to prevent commands execution incoming from group chat:
|
||||||
|
* #
|
||||||
|
* # return !message.getChat().isGroupChat();
|
||||||
|
* #
|
||||||
|
*
|
||||||
|
* @param message Received message
|
||||||
|
* @return true if the message must be ignored by the command bot and treated as a non command message,
|
||||||
|
* false otherwise
|
||||||
|
*/
|
||||||
|
protected boolean filter(Message message) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean register(BotCommand botCommand) {
|
public final boolean register(BotCommand botCommand) {
|
||||||
return commandRegistry.register(botCommand);
|
return commandRegistry.register(botCommand);
|
||||||
|
Loading…
Reference in New Issue
Block a user