Skip to content

Commit

Permalink
handle cases where attachments doesn't have new params
Browse files Browse the repository at this point in the history
  • Loading branch information
Snipy7374 committed Oct 12, 2023
1 parent 32f3ce5 commit 4247160
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions disnake/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,23 +324,31 @@ def __init__(self, *, data: AttachmentPayload, state: ConnectionState) -> None:
b64decode(waveform_data) if (waveform_data := data.get("waveform")) else None
)
_params = urlparse(self.url)
self._ex = parse_qs(_params.query)["ex"][0]
self._ex = parse_qs(_params.query).get("ex")
self._flags: int = data.get("flags", 0)

def expires_at(self) -> datetime.datetime:
def expires_at(self) -> Optional[datetime.datetime]:
"""The date when this attachment will expire.
``None`` if the ``ex`` param is not present in :attr:`.Attachment.url`.
:return type: :class:`datetime.datetime`
:return type: Optional[:class:`datetime.datetime`]
"""
timestamp = int(self._ex, 16)
if not self._ex:
return

timestamp = int(self._ex[0], 16)
return datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc)

def is_expired(self) -> bool:
"""Whether this attachment expired or not.
:return type: :class:`bool`
"""
return utils.utcnow() >= self.expires_at()
ex = self.expires_at()
if not ex:
return False

return utils.utcnow() >= ex

def is_spoiler(self) -> bool:
"""Whether this attachment contains a spoiler.
Expand Down

0 comments on commit 4247160

Please sign in to comment.