Add support for spoiler attachments.
This commit is contained in:
parent
dd884a6afe
commit
93d576a65b
@ -48,11 +48,13 @@ class File:
|
|||||||
The filename to display when uploading to Discord.
|
The filename to display when uploading to Discord.
|
||||||
If this is not given then it defaults to ``fp.name`` or if ``fp`` is
|
If this is not given then it defaults to ``fp.name`` or if ``fp`` is
|
||||||
a string then the ``filename`` will default to the string given.
|
a string then the ``filename`` will default to the string given.
|
||||||
|
spoiler: :class:`bool`
|
||||||
|
Whether the attachment is a spoiler.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ('fp', 'filename', '_true_fp')
|
__slots__ = ('fp', 'filename', '_true_fp')
|
||||||
|
|
||||||
def __init__(self, fp, filename=None):
|
def __init__(self, fp, filename=None, *, spoiler=False):
|
||||||
self.fp = fp
|
self.fp = fp
|
||||||
self._true_fp = None
|
self._true_fp = None
|
||||||
|
|
||||||
@ -64,6 +66,9 @@ class File:
|
|||||||
else:
|
else:
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|
||||||
|
if spoiler and not self.filename.startswith('SPOILER_'):
|
||||||
|
self.filename = 'SPOILER_' + self.filename
|
||||||
|
|
||||||
def open_file(self):
|
def open_file(self):
|
||||||
fp = self.fp
|
fp = self.fp
|
||||||
if isinstance(fp, str):
|
if isinstance(fp, str):
|
||||||
|
@ -71,6 +71,10 @@ class Attachment:
|
|||||||
self.proxy_url = data.get('proxy_url')
|
self.proxy_url = data.get('proxy_url')
|
||||||
self._http = state.http
|
self._http = state.http
|
||||||
|
|
||||||
|
def is_spoiler(self):
|
||||||
|
""":class:`bool`: Whether this attachment contains a spoiler."""
|
||||||
|
return self.filename.startswith('SPOILER_')
|
||||||
|
|
||||||
async def save(self, fp, *, seek_begin=True):
|
async def save(self, fp, *, seek_begin=True):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user