feat: File type filtering for Attachment options and FileUpload component - #3284
feat: File type filtering for Attachment options and FileUpload component#3284NeloBlivion wants to merge 11 commits into
Conversation
|
Thanks for opening this pull request! This pull request can be checked-out with: git fetch origin pull/3284/head:pr-3284
git checkout pr-3284This pull request can be installed with: pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3284/head |
| .. attribute:: image | ||
|
|
||
| Allow image files. This includes ``.png``, ``.gif``, ``.jpg``, ``.jpeg``, ``.jfif``, ``.webp``, and ``.avif``. | ||
|
|
||
| .. attribute:: video | ||
|
|
||
| Allow video files. This includes ``.mp4``, ``.mov``, ``.qt``, and ``.webm``. | ||
|
|
||
| .. attribute:: audio | ||
|
|
||
| Allow audio files. This includes ``.mp3``, ``.m4a``, ``.wav``, ``.ogg``, ``.opus``, and ``.flac``. |
There was a problem hiding this comment.
Documented twice? Docstring in the class too. Not sure if that's even considered.
| raise TypeError( | ||
| "items in file_types must be of type str or FileType" | ||
| ) | ||
| if len(str(f)) > 16: |
There was a problem hiding this comment.
This also checks the length of our enum values, which is a bit useless?
| payload["required"] = self.required | ||
|
|
||
| if self.file_types: | ||
| payload["file_types"] = [str(f) for f in self.file_types] |
There was a problem hiding this comment.
str(FileType) won't serialize correctly, since it subclasses Enum. Either make it subclass StrEnum, or explicitly serialize with .value when the item is a FileType.
| if self.max_length is not None: | ||
| as_dict["max_length"] = self.max_length | ||
| if self.file_types: | ||
| as_dict["file_types"] = [str(f) for f in self.file_types] |
There was a problem hiding this comment.
str(FileType) won't serialize correctly, since it subclasses Enum. Either make it subclass StrEnum, or explicitly serialize with .value when the item is a FileType.
| for f in data.get("file_types", []): | ||
| ( | ||
| self.file_types.append(f) | ||
| if f not in FileType.__members__ | ||
| else try_enum(FileType, f) | ||
| ) |
There was a problem hiding this comment.
Not sure the logic here matches what you were planning, unless I missed something. Currently, when f is a known FileType member, it goes into the else branch and calls try_enum(FileType, f), but the result is never appended anywhere, so it's just discarded. Only unknown values are in self.file_types.
| Whether the file upload field is required or not. Defaults to ``True``. | ||
| id: Optional[:class:`int`] | ||
| The file upload field's ID. | ||
| file_types: List[:class:`str`, :class:`FileType`] |
There was a problem hiding this comment.
List[X, Y] is not valid, because it only takes one type parameter.
| file_types: List[:class:`str`, :class:`FileType`] | |
| file_types: List[Union[:class:`str`, :class:`FileType`]] |
| The maximum number of files that can be uploaded. | ||
| required: Optional[:class:`bool`] | ||
| Whether the file upload field is required or not. Defaults to `True`. | ||
| file_types: List[:class:`str`, :class:`FileType`] |
There was a problem hiding this comment.
List[X, Y] is not valid, because it only takes one type parameter.
| file_types: List[:class:`str`, :class:`FileType`] | |
| file_types: List[Union[:class:`str`, :class:`FileType`]] |
| description_localizations: Dict[:class:`str`, :class:`str`] | ||
| The description localizations for this option. The values of this should be ``"locale": "description"``. | ||
| See `here <https://docs.discord.com/developers/reference#locales>`_ for a list of valid locales. | ||
| file_types: List[:class:`str`, :class:`FileType`] |
There was a problem hiding this comment.
List[X, Y] is not valid, because it only takes one type parameter.
| file_types: List[:class:`str`, :class:`FileType`] | |
| file_types: List[Union[:class:`str`, :class:`FileType`]] |
Lulalaby
left a comment
There was a problem hiding this comment.
can we potentially add a check if the provided file type string starts with .?
Was just typing that, you were faster |
Summary
Support
file_typesinOptionandFileUpload.Information
examples, ...).
Checklist
type: ignorecomments were used, a comment is also left explaining why.