Merge pull request #13 from paris-ci/rework_set_in_embeds
Make `Embed.image` and `Embed.thumbnail` full-featured properties
This commit is contained in:
commit
923a6a885d
@ -72,30 +72,36 @@ if TYPE_CHECKING:
|
|||||||
T = TypeVar('T')
|
T = TypeVar('T')
|
||||||
MaybeEmpty = Union[T, _EmptyEmbed]
|
MaybeEmpty = Union[T, _EmptyEmbed]
|
||||||
|
|
||||||
|
|
||||||
class _EmbedFooterProxy(Protocol):
|
class _EmbedFooterProxy(Protocol):
|
||||||
text: MaybeEmpty[str]
|
text: MaybeEmpty[str]
|
||||||
icon_url: MaybeEmpty[str]
|
icon_url: MaybeEmpty[str]
|
||||||
|
|
||||||
|
|
||||||
class _EmbedFieldProxy(Protocol):
|
class _EmbedFieldProxy(Protocol):
|
||||||
name: MaybeEmpty[str]
|
name: MaybeEmpty[str]
|
||||||
value: MaybeEmpty[str]
|
value: MaybeEmpty[str]
|
||||||
inline: bool
|
inline: bool
|
||||||
|
|
||||||
|
|
||||||
class _EmbedMediaProxy(Protocol):
|
class _EmbedMediaProxy(Protocol):
|
||||||
url: MaybeEmpty[str]
|
url: MaybeEmpty[str]
|
||||||
proxy_url: MaybeEmpty[str]
|
proxy_url: MaybeEmpty[str]
|
||||||
height: MaybeEmpty[int]
|
height: MaybeEmpty[int]
|
||||||
width: MaybeEmpty[int]
|
width: MaybeEmpty[int]
|
||||||
|
|
||||||
|
|
||||||
class _EmbedVideoProxy(Protocol):
|
class _EmbedVideoProxy(Protocol):
|
||||||
url: MaybeEmpty[str]
|
url: MaybeEmpty[str]
|
||||||
height: MaybeEmpty[int]
|
height: MaybeEmpty[int]
|
||||||
width: MaybeEmpty[int]
|
width: MaybeEmpty[int]
|
||||||
|
|
||||||
|
|
||||||
class _EmbedProviderProxy(Protocol):
|
class _EmbedProviderProxy(Protocol):
|
||||||
name: MaybeEmpty[str]
|
name: MaybeEmpty[str]
|
||||||
url: MaybeEmpty[str]
|
url: MaybeEmpty[str]
|
||||||
|
|
||||||
|
|
||||||
class _EmbedAuthorProxy(Protocol):
|
class _EmbedAuthorProxy(Protocol):
|
||||||
name: MaybeEmpty[str]
|
name: MaybeEmpty[str]
|
||||||
url: MaybeEmpty[str]
|
url: MaybeEmpty[str]
|
||||||
@ -397,6 +403,19 @@ class Embed:
|
|||||||
"""
|
"""
|
||||||
return EmbedProxy(getattr(self, '_image', {})) # type: ignore
|
return EmbedProxy(getattr(self, '_image', {})) # type: ignore
|
||||||
|
|
||||||
|
@image.setter
|
||||||
|
def image(self: E, *, url: Any):
|
||||||
|
self._image = {
|
||||||
|
'url': str(url),
|
||||||
|
}
|
||||||
|
|
||||||
|
@image.deleter
|
||||||
|
def image(self: E):
|
||||||
|
try:
|
||||||
|
del self._image
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
def set_image(self: E, *, url: MaybeEmpty[Any]) -> E:
|
def set_image(self: E, *, url: MaybeEmpty[Any]) -> E:
|
||||||
"""Sets the image for the embed content.
|
"""Sets the image for the embed content.
|
||||||
|
|
||||||
@ -413,14 +432,9 @@ class Embed:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if url is EmptyEmbed:
|
if url is EmptyEmbed:
|
||||||
try:
|
del self.image
|
||||||
del self._image
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
self._image = {
|
self.image = url
|
||||||
'url': str(url),
|
|
||||||
}
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@ -439,7 +453,25 @@ class Embed:
|
|||||||
"""
|
"""
|
||||||
return EmbedProxy(getattr(self, '_thumbnail', {})) # type: ignore
|
return EmbedProxy(getattr(self, '_thumbnail', {})) # type: ignore
|
||||||
|
|
||||||
def set_thumbnail(self: E, *, url: MaybeEmpty[Any]) -> E:
|
@thumbnail.setter
|
||||||
|
def thumbnail(self: E, *, url: Any):
|
||||||
|
"""Sets the thumbnail for the embed content.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._thumbnail = {
|
||||||
|
'url': str(url),
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
@thumbnail.deleter
|
||||||
|
def thumbnail(self):
|
||||||
|
try:
|
||||||
|
del self.thumbnail
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def set_thumbnail(self: E, *, url: MaybeEmpty[Any]):
|
||||||
"""Sets the thumbnail for the embed content.
|
"""Sets the thumbnail for the embed content.
|
||||||
|
|
||||||
This function returns the class instance to allow for fluent-style
|
This function returns the class instance to allow for fluent-style
|
||||||
@ -453,16 +485,10 @@ class Embed:
|
|||||||
url: :class:`str`
|
url: :class:`str`
|
||||||
The source URL for the thumbnail. Only HTTP(S) is supported.
|
The source URL for the thumbnail. Only HTTP(S) is supported.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if url is EmptyEmbed:
|
if url is EmptyEmbed:
|
||||||
try:
|
del self.thumbnail
|
||||||
del self._thumbnail
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
self._thumbnail = {
|
self.thumbnail = url
|
||||||
'url': str(url),
|
|
||||||
}
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user