Browse Source

Added cached saving for attachments

Updated docstring
pull/1963/head
Maku 6 years ago
committed by Rapptz
parent
commit
6f1dff78d4
  1. 12
      discord/message.py

12
discord/message.py

@ -77,7 +77,7 @@ class Attachment:
""":class:`bool`: Whether this attachment contains a spoiler.""" """:class:`bool`: Whether this attachment contains a spoiler."""
return self.filename.startswith('SPOILER_') return self.filename.startswith('SPOILER_')
async def save(self, fp, *, seek_begin=True): async def save(self, fp, *, seek_begin=True, use_cached=False):
"""|coro| """|coro|
Saves this attachment into a file-like object. Saves this attachment into a file-like object.
@ -91,6 +91,12 @@ class Attachment:
seek_begin: bool seek_begin: bool
Whether to seek to the beginning of the file after saving is Whether to seek to the beginning of the file after saving is
successfully done. successfully done.
use_cached: bool
Whether to use the proxy_url property, rather than the url
property, as the attachment source. This will allow attachments
to be saved after deletion more often than with the url, which
is deleted after the message is deleted. Note that use_cached will
still fail after an uncertain amount of time.
Raises Raises
-------- --------
@ -104,8 +110,8 @@ class Attachment:
int int
The number of bytes written. The number of bytes written.
""" """
url = self.proxy_url if use_cached else self.url
data = await self._http.get_attachment(self.url) data = await self._http.get_attachment(url)
if isinstance(fp, str): if isinstance(fp, str):
with open(fp, 'wb') as f: with open(fp, 'wb') as f:
return f.write(data) return f.write(data)

Loading…
Cancel
Save