FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add `filters.IS_BOT` by fahadhewad · Pull Request #5335 · python-telegram-bot/python-telegram-bot · GitHub

Add filters.IS_BOT - #5335

Open
fahadhewad wants to merge 1 commit into
python-telegram-bot:masterfrom
fahadhewad:is-bot-filter
Open

Add filters.IS_BOT#5335
fahadhewad wants to merge 1 commit into
python-telegram-bot:masterfrom
fahadhewad:is-bot-filter

Conversation

Copy link
Copy Markdown

Adds filters.IS_BOT, a ready to use filter that matches updates whose telegram.Update.effective_user is a bot. Until now nothing in the filters module exposed telegram.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_BOT covers the human only case.

The filter is implemented as an UpdateFilter over Update.effective_user, which is the same approach the existing PREMIUM_USER and USER_ATTACHMENT filters take for other telegram.User attributes. It returns False when 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

  • Added .. versionadded:: NEXT.VERSION, .. versionchanged:: NEXT.VERSION, .. deprecated:: NEXT.VERSION or ``.. versionremoved:: NEXT.VERSION` to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)
  • Created new or adapted existing unit tests
  • Documented code changes according to the CSI standard
  • Added myself alphabetically to AUTHORS.rst (optional)
  • Added new classes & modules to the docs and all suitable __all__ s
  • Checked the Stability Policy in case of deprecations or changes to documented behavior

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add filters.IS_BOT — no filter exposes User.is_bot (needed for multi-bot group chats)

1 participant


Back | FazBrowse Home | New Git URL