Browse Source

Add TrialOffer.is_acked() and make expires_at nullable

pull/10109/head
dolfies 2 years ago
parent
commit
eec5f6341a
  1. 2
      discord/http.py
  2. 18
      discord/promotions.py
  3. 2
      discord/types/promotions.py

2
discord/http.py

@ -4249,7 +4249,7 @@ class HTTPClient:
def get_trial_offer(self) -> Response[promotions.TrialOffer]: def get_trial_offer(self) -> Response[promotions.TrialOffer]:
return self.request(Route('GET', '/users/@me/billing/user-trial-offer')) return self.request(Route('GET', '/users/@me/billing/user-trial-offer'))
def ack_trial_offer(self, trial_id: Snowflake) -> Response[None]: def ack_trial_offer(self, trial_id: Snowflake) -> Response[promotions.TrialOffer]:
return self.request(Route('POST', '/users/@me/billing/user-trial-offer/{trial_id}/ack', trial_id=trial_id)) return self.request(Route('POST', '/users/@me/billing/user-trial-offer/{trial_id}/ack', trial_id=trial_id))
def get_pricing_promotion(self) -> Response[promotions.WrappedPricingPromotion]: def get_pricing_promotion(self) -> Response[promotions.WrappedPricingPromotion]:

18
discord/promotions.py

@ -224,8 +224,8 @@ class TrialOffer(Hashable):
---------- ----------
id: :class:`int` id: :class:`int`
The ID of the trial offer. The ID of the trial offer.
expires_at: :class:`datetime.datetime` expires_at: Optional[:class:`datetime.datetime`]
When the trial offer expires. When the trial offer expires, if it has been acknowledged.
trial_id: :class:`int` trial_id: :class:`int`
The ID of the trial. The ID of the trial.
trial: :class:`SubscriptionTrial` trial: :class:`SubscriptionTrial`
@ -242,15 +242,24 @@ class TrialOffer(Hashable):
def __init__(self, *, data: TrialOfferPayload, state: ConnectionState) -> None: def __init__(self, *, data: TrialOfferPayload, state: ConnectionState) -> None:
self._state = state self._state = state
self._update(data)
def _update(self, data: TrialOfferPayload) -> None:
self.id: int = int(data['id']) self.id: int = int(data['id'])
self.expires_at: datetime = parse_time(data['expires_at']) self.expires_at: Optional[datetime] = parse_time(data.get('expires_at'))
self.trial_id: int = int(data['trial_id']) self.trial_id: int = int(data['trial_id'])
self.trial: SubscriptionTrial = SubscriptionTrial(data['subscription_trial']) self.trial: SubscriptionTrial = SubscriptionTrial(data['subscription_trial'])
def __repr__(self) -> str: def __repr__(self) -> str:
return f'<TrialOffer id={self.id} trial={self.trial!r}>' return f'<TrialOffer id={self.id} trial={self.trial!r}>'
def is_acked(self) -> bool:
""":class:`bool`: Checks if the trial offer has been acknowledged.
.. versionadded:: 2.1
"""
return self.expires_at is not None
async def ack(self) -> None: async def ack(self) -> None:
"""|coro| """|coro|
@ -261,7 +270,8 @@ class TrialOffer(Hashable):
HTTPException HTTPException
Acknowledging the trial offer failed. Acknowledging the trial offer failed.
""" """
await self._state.http.ack_trial_offer(self.id) data = await self._state.http.ack_trial_offer(self.id)
self._update(data)
class PricingPromotion: class PricingPromotion:

2
discord/types/promotions.py

@ -57,7 +57,7 @@ class ClaimedPromotion(TypedDict):
class TrialOffer(TypedDict): class TrialOffer(TypedDict):
id: Snowflake id: Snowflake
expires_at: str expires_at: Optional[str]
trial_id: Snowflake trial_id: Snowflake
subscription_trial: SubscriptionTrial subscription_trial: SubscriptionTrial

Loading…
Cancel
Save