From 8332ca3f2844419eac7b972caad26b3263e85464 Mon Sep 17 00:00:00 2001 From: blord0 Date: Thu, 17 Jul 2025 13:36:20 +0100 Subject: [PATCH] Move `VoiceMessageFile` into `File` --- discord/file.py | 54 ++++++++++++++----------------------------------- discord/http.py | 1 + docs/api.rst | 8 -------- 3 files changed, 16 insertions(+), 47 deletions(-) diff --git a/discord/file.py b/discord/file.py index e46d49411..804c3c0e6 100644 --- a/discord/file.py +++ b/discord/file.py @@ -34,7 +34,6 @@ from .utils import MISSING # fmt: off __all__ = ( 'File', - 'VoiceMessageFile', ) # fmt: on @@ -79,7 +78,7 @@ class File: .. versionadded:: 2.0 """ - __slots__ = ('fp', '_filename', 'spoiler', 'description', '_original_pos', '_owner', '_closer') + __slots__ = ('fp', '_filename', 'spoiler', 'description', '_original_pos', '_owner', '_closer', 'duation', '_waveform') def __init__( self, @@ -88,6 +87,8 @@ class File: *, spoiler: bool = MISSING, description: Optional[str] = None, + duration: Optional[float] = None, + waveform: Optional[str] = None, ): if isinstance(fp, io.IOBase): if not (fp.seekable() and fp.readable()): @@ -119,6 +120,8 @@ class File: self.spoiler: bool = spoiler self.description: Optional[str] = description + self.duation = duration + self._waveform = waveform @property def filename(self) -> str: @@ -128,6 +131,13 @@ class File: """ return 'SPOILER_' + self._filename if self.spoiler else self._filename + @property + def waveform(self) -> str: + """:class:`str`: The waveform data for the voice message.""" + if self._waveform is None: + return base64.b64encode(os.urandom(256)).decode('utf-8') + return self._waveform + @filename.setter def filename(self, value: str) -> None: self._filename, self.spoiler = _strip_spoiler(value) @@ -158,42 +168,8 @@ class File: if self.description is not None: payload['description'] = self.description - return payload - - -class VoiceMessageFile(File): - """A file object used for sending voice messages. - - This is a subclass of :class:`File` that is specifically used for sending voice messages. - - .. versionadded:: 2.6 - - Attributes - ----------- - duration: :class:`float` - The duration of the voice message in seconds. Does not need to be accurate - - """ - - def __init__( - self, - fp: Union[str, bytes, os.PathLike[Any], io.BufferedIOBase], - duration: float, - waveform: Optional[str] = None, - ): - super().__init__(fp, filename="voice-message.ogg", spoiler=False) - self.duration = duration - self._waveform = waveform + if self.duation is not None: + payload['duration_secs'] = self.duation + payload['waveform'] = self.waveform - def to_dict(self, index: int) -> Dict[str, Any]: - payload = super().to_dict(index) - payload['duration_secs'] = self.duration - payload['waveform'] = self.waveform return payload - - @property - def waveform(self) -> str: - """:class:`bytes`: The waveform data for the voice message.""" - if self._waveform is None: - return base64.b64encode(os.urandom(256)).decode('utf-8') - return self._waveform diff --git a/discord/http.py b/discord/http.py index 544bf2bec..02fd1e136 100644 --- a/discord/http.py +++ b/discord/http.py @@ -617,6 +617,7 @@ class HTTPClient: headers['X-Audit-Log-Reason'] = _uriquote(reason, safe='/ ') kwargs['headers'] = headers + # Proxy support if self.proxy is not None: kwargs['proxy'] = self.proxy diff --git a/docs/api.rst b/docs/api.rst index 5f58fa480..c7d9e351f 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -5632,14 +5632,6 @@ File .. autoclass:: File :members: -VoiceMessageFile -~~~~~~~~~~~~~~~~~ - -.. attributetable:: VoiceMessageFile - -.. autoclass:: VoiceMessageFile - :members: - Colour ~~~~~~