Skip to content

Commit

Permalink
feat: add Entitlement.deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv committed Oct 7, 2023
1 parent 8c7eb23 commit 502e1ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions disnake/entitlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class Entitlement(Hashable):
See also :attr:`guild`.
application_id: :class:`int`
The parent application's ID.
deleted: :class:`bool`
Whether the entitlement was deleted.
starts_at: Optional[:class:`datetime.datetime`]
The time at which the entitlement starts being active.
Set to ``None`` when this is a test entitlement.
Expand All @@ -84,6 +86,7 @@ class Entitlement(Hashable):
"guild_id",
"application_id",
"type",
"deleted",
"starts_at",
"ends_at",
)
Expand All @@ -97,6 +100,7 @@ def __init__(self, *, data: EntitlementPayload, state: ConnectionState) -> None:
self.guild_id: Optional[int] = _get_as_snowflake(data, "guild_id")
self.application_id: int = int(data["application_id"])
self.type: EntitlementType = try_enum(EntitlementType, data["type"])
self.deleted: bool = data.get("deleted", False)
self.starts_at: Optional[datetime.datetime] = parse_time(data.get("starts_at"))
self.ends_at: Optional[datetime.datetime] = parse_time(data.get("ends_at"))

Expand Down Expand Up @@ -135,11 +139,15 @@ def is_active(self) -> bool:
:return type: :class:`bool`
"""
if self.deleted:
return False

now = utcnow()
if self.starts_at is not None and now < self.starts_at:
return False
if self.ends_at is not None and now >= self.ends_at:
return False

return True

async def delete(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion disnake/types/entitlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class Entitlement(TypedDict):
guild_id: NotRequired[Snowflake]
application_id: Snowflake
type: EntitlementType
consumed: bool # always false in this case
deleted: bool
starts_at: NotRequired[str]
ends_at: NotRequired[str]

0 comments on commit 502e1ad

Please sign in to comment.