Skip to content

Commit

Permalink
Merge pull request rubenlagus#112 from dartwata/patch-1
Browse files Browse the repository at this point in the history
Message filter for TelegramLongPollingCommandBot
  • Loading branch information
rubenlagus authored Jul 13, 2016
2 parents f9ab74d + 13e4513 commit df0d597
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public TelegramLongPollingCommandBot() {
public final void onUpdateReceived(Update update) {
if (update.hasMessage()) {
Message message = update.getMessage();
if (message.isCommand()) {
if ((message.isCommand()) && (filter(message))) {
if (commandRegistry.executeCommand(this, message)) {
return;
}
Expand All @@ -41,6 +41,19 @@ public final void onUpdateReceived(Update 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();
* #
*/
protected boolean filter(Message message) {
return true;
}

@Override
public final boolean register(BotCommand botCommand) {
return commandRegistry.register(botCommand);
Expand Down

0 comments on commit df0d597

Please sign in to comment.