Add filters.IS_BOT - #5335
Open
fahadhewad wants to merge 1 commit into
Open
Conversation
Expose telegram.User.is_bot through a ready-to-use filter, so that handlers can be registered for, or excluded from, messages authored by a bot without inspecting the sender inside the callback. The filter is an UpdateFilter based on Update.effective_user, matching the existing PREMIUM_USER and USER_ATTACHMENT filters, and returns False when the update has no user, e.g. for channel posts. Closes python-telegram-bot#5315
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
filters.IS_BOT, a ready to use filter that matches updates whosetelegram.Update.effective_useris a bot. Until now nothing in the filters module exposedtelegram.User.is_bot, so telling bot authored messages apart from human ones had to happen inside the callback. With this filter the decision can be made at handler registration time, and~filters.IS_BOTcovers the human only case.The filter is implemented as an
UpdateFilteroverUpdate.effective_user, which is the same approach the existingPREMIUM_USERandUSER_ATTACHMENTfilters take for othertelegram.Userattributes. It returnsFalsewhen the update carries no user at all, for example for channel posts.The docstring also points out that in groups a bot only receives messages from other bots when privacy mode is disabled, since that is the setting that decides whether the filter can ever match in a multi bot chat.
Fixes #5315.
Check-list for PRs
.. versionadded:: NEXT.VERSION,.. versionchanged:: NEXT.VERSION,.. deprecated:: NEXT.VERSIONor ``.. versionremoved:: NEXT.VERSION` to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)AUTHORS.rst(optional)__all__s