Skip to content

Commit

Permalink
Change eventsub timestamp to return optional
Browse files Browse the repository at this point in the history
  • Loading branch information
chillymosh committed Jan 25, 2025
1 parent 8e9e7dd commit 19bbd81
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions twitchio/models/eventsub_.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ def __init_subclass__(cls, **kwargs: Any) -> None:
BaseEvent._registry[cls.subscription_type] = cls

@property
def timestamp(self) -> datetime.datetime:
def timestamp(self) -> datetime.datetime | None:
"""The timestamp of the eventsub notification from Twitch in UTC.
If the notification Twitch sends is missing this data, then it will fall back to current UTC time.
If the notification Twitch sends is missing this data, then it will return `None`.
Returns
-------
Expand All @@ -95,7 +95,7 @@ def timestamp(self) -> datetime.datetime:
if self._headers and (timestamp := self._headers.get("Twitch-Eventsub-Message-Timestamp")):
return parse_timestamp(timestamp)

return datetime.datetime.now(datetime.UTC)
return None

@property
def metadata(self) -> Metadata | None:
Expand All @@ -105,9 +105,7 @@ def metadata(self) -> Metadata | None:
-------
Metadata | None
"""
if self._metadata is not None:
return Metadata(self._metadata)
return None
return Metadata(self._metadata) if self._metadata is not None else None

@property
def headers(self) -> Headers | None:
Expand All @@ -117,9 +115,7 @@ def headers(self) -> Headers | None:
-------
Headers | None
"""
if self._headers is not None:
return Headers(self._headers)
return None
return Headers(self._headers) if self._headers is not None else None

@property
def subscription_data(self) -> NotificationSubscription:
Expand Down

0 comments on commit 19bbd81

Please sign in to comment.