Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple text filter #176

Merged
merged 7 commits into from
Aug 5, 2019
Merged

Add multiple text filter #176

merged 7 commits into from
Aug 5, 2019

Conversation

Birdi7
Copy link
Contributor

@Birdi7 Birdi7 commented Jul 27, 2019

Description

Add the multiple text filter as required at #151, Multiple text filter (aiogram_ru#73126).
The following patterns are applied for comparison methods:

  • equals - True if any of strings in the list is equal to the text
  • contains - True if the text contains all strings from the list. Reason: There is no way to do such comparison right now (except using custom filters), while the condition "if the text contains any string" can be implemented with a bunch of register_message_handler
  • startswith - True if text starts with any string from the list. Reason: There is no need to implement "if text starts with all strings from the list" as all prefixes can be mixed in one
  • endswith - True if text ends with any string from the list. Reason: There is no need to implement "if text ends with all strings from the list" as all postfixes can be mixed in one

Tests are included for all methods. An example of usage was added.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@Birdi7 Birdi7 marked this pull request as ready for review July 28, 2019 09:03
@mahenzon
Copy link
Contributor

mahenzon commented Aug 4, 2019

Your ANY filters are redundant because the same result can be achieved by adding multiple registrators

Maybe only the contains all of the entries has its place

You have the same code in your example

@dp.message_handler(text_contains='spam')
@dp.message_handler(text_contains='eggs')
await def my_handler(message):
    await foobar()

@Birdi7
Copy link
Contributor Author

Birdi7 commented Aug 4, 2019

@surik00 yes, they may be replaced with a bunch of registrations. Although, my filters make code clearer and more readable while don't break the existing code written using previous filters. Command filter works the same way, and it take place in aiogram

Copy link
Member

@JrooTJunior JrooTJunior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You marked item "I have made corresponding changes to the documentation" as completed but don't add any information to the documentations.

Please add information described in this PR to the docs/source/dispatcher/filters.rst

@JrooTJunior
Copy link
Member

I'll uncheck documentation mark until you don't update the documentations.

@Birdi7
Copy link
Contributor Author

Birdi7 commented Aug 5, 2019

@JrooTJunior I added the docs in the last 2 commits. Here is the built version of docs for this branch

@JrooTJunior JrooTJunior merged commit 8823c8f into aiogram:dev-2.x Aug 5, 2019
@Birdi7 Birdi7 deleted the add-multiple-text-filter branch August 5, 2019 10:09
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.

None yet

4 participants