-
Notifications
You must be signed in to change notification settings - Fork 6k
Added: Filter for file ending/extension #2156
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
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """""" # 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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