Added: Filter for file ending/extension#2156
Closed
mlemosf wants to merge 3 commits intopython-telegram-bot:masterfrom
Closed
Added: Filter for file ending/extension#2156mlemosf wants to merge 3 commits intopython-telegram-bot:masterfrom
mlemosf wants to merge 3 commits intopython-telegram-bot:masterfrom
Conversation
Added class 'file_ending' that filter documents which end in the extension passed by the user to Filters.document.file_ending; Added name to AUTHORS.rst.
Bibo-Joshi
requested changes
Oct 21, 2020
Member
Bibo-Joshi
left a comment
There was a problem hiding this comment.
Hi! Thanks for the PR. I left some comments. Also we'll need unit tests. Please have a look at tests/test_filters.py for inspiration.
telegram/ext/filters.py
Outdated
| def filter(self, message : Message) -> bool: | ||
| """""" # remove method from docs | ||
| if message.document: | ||
| return message.document.file_name.endswith(self.file_ending) |
Member
There was a problem hiding this comment.
this way file_extension('jpg') would also allow foo.barjpg. Please adjust for the dot
Changed 'file_ending' to 'file_extension'; Use of fstrings on formatting instead of .format();
Added tests for some possible cases of file extensions.
Bibo-Joshi
requested changes
Oct 23, 2020
| """""" # remove method from docs | ||
| if message.document: | ||
| return message.document.file_name.endswith(self.file_ending) | ||
| return message.document.file_name.endswith(self.file_extension) |
Member
There was a problem hiding this comment.
This still needs to account for the dot. please make sure to add a unit test testing that file_extension('jpg') doesn't allow filename.foojpg as filename
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Feature: Added filter for file endings / file extensions on documents
Added class 'file_ending' that filter documents which end in the
extension passed by the user to Filters.document.file_ending;
Also added name to AUTHORS.rst.
This pull request solves issue #2140