Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update monetization #2438

Merged
merged 52 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
10dddf5
Update enums.py
plun1331 Apr 26, 2024
52ee538
Update enums.rst
plun1331 Apr 26, 2024
ae35166
Update enums.py
plun1331 Apr 26, 2024
0503f40
Update enums.rst
plun1331 Apr 26, 2024
e2ecb7a
Update http.py
plun1331 Apr 26, 2024
05740a0
Update monetization.py
plun1331 Apr 26, 2024
7de9c5b
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 26, 2024
cb2051f
Update CHANGELOG.md
plun1331 Apr 26, 2024
1d6151f
Update CHANGELOG.md
plun1331 Apr 26, 2024
1ebcbf1
Merge branch 'master' into upd-monetization
plun1331 Apr 26, 2024
6d3a736
Merge branch 'master' into upd-monetization
plun1331 Apr 26, 2024
ab80811
Update http.py
plun1331 Apr 26, 2024
ea727a2
Update monetization.py
plun1331 Apr 26, 2024
b258a10
Update iterators.py
plun1331 Apr 26, 2024
6662f33
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 26, 2024
e0b1bad
Update client.py
plun1331 Apr 26, 2024
4a94647
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 26, 2024
f68e4ad
Update iterators.py
plun1331 Apr 26, 2024
1cfdf27
Update iterators.py
plun1331 Apr 26, 2024
98287eb
Update iterators.py
plun1331 Apr 26, 2024
ef403b8
Update client.py
plun1331 Apr 26, 2024
84af33d
Update guild.py
plun1331 Apr 26, 2024
c9299bd
Update user.py
plun1331 Apr 26, 2024
4a2ad7c
Update guild.py
plun1331 Apr 26, 2024
3ba1937
Update client.py
plun1331 Apr 26, 2024
5459de7
Update user.py
plun1331 Apr 26, 2024
c5da6e2
Update user.py
plun1331 Apr 26, 2024
9a74aa8
Merge branch 'master' into upd-monetization
Lulalaby Apr 26, 2024
e0c3760
Merge branch 'master' into upd-monetization
plun1331 Apr 27, 2024
4d14087
Merge branch 'master' into upd-monetization
plun1331 Apr 30, 2024
323ca29
Update interactions.py
plun1331 May 16, 2024
842c208
Update components.py
plun1331 May 16, 2024
d179f69
Update components.py
plun1331 May 16, 2024
e0d8975
Update components.py
plun1331 May 16, 2024
707507b
Update enums.py
plun1331 May 16, 2024
0d8a812
Update button.py
plun1331 May 16, 2024
3940579
Update enums.rst
plun1331 May 16, 2024
d22db63
Update button.py
plun1331 May 17, 2024
9110129
Merge branch 'master' into upd-monetization
plun1331 May 29, 2024
f67d614
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2024
2085cb0
Merge branch 'master' into upd-monetization
plun1331 Jun 6, 2024
4909dae
feat: add urls
plun1331 Jun 26, 2024
e1401bd
Merge branch 'master' into upd-monetization
plun1331 Jun 26, 2024
eee3671
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
2e74bd9
Apply suggestions from code review
plun1331 Jun 26, 2024
c9e7dd0
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
2d888fb
Apply suggestions from code review
Dorukyum Jun 28, 2024
9be4fae
Add spacing
Dorukyum Jun 28, 2024
94e9bfc
Add spacing
Dorukyum Jun 28, 2024
a63f008
Apply suggestions from code review
plun1331 Jun 28, 2024
df1bbdb
Merge branch 'master' into upd-monetization
plun1331 Jun 28, 2024
cd1c70a
button.py aktualisieren
Dorukyum Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2418](https://github.com/Pycord-Development/pycord/pull/2418))
- Added `member` data to the `raw_reaction_remove` event.
([#2412](https://github.com/Pycord-Development/pycord/pull/2412))
- Added support for one-time purchases for Discord monetization.
([#2438](https://github.com/Pycord-Development/pycord/pull/2438))

### Fixed

Expand All @@ -42,6 +44,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2411](https://github.com/Pycord-Development/pycord/pull/2411))
- Fixed option typehints being ignored when using `parameter_name`.
([#2417](https://github.com/Pycord-Development/pycord/pull/2417))
- Fixed `Entitlement.delete` not passing all needed parameters to its HTTP method.
plun1331 marked this conversation as resolved.
Show resolved Hide resolved
([#2438](https://github.com/Pycord-Development/pycord/pull/2438))

### Changed

Expand Down
9 changes: 9 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,13 +1003,22 @@ class ReactionType(Enum):
class SKUType(Enum):
"""The SKU type"""

durable = 2
consumable = 3
subscription = 5
subscription_group = 6


class EntitlementType(Enum):
"""The entitlement type"""

purchase = 1
premium_subscription = 2
developer_gift = 3
test_mode_purchase = 4
free_purchase = 5
user_gift = 6
premium_purchase = 7
application_subscription = 8


Expand Down
39 changes: 38 additions & 1 deletion discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2936,13 +2936,50 @@ def list_skus(
def list_entitlements(
self,
application_id: Snowflake,
*,
user_id: Snowflake | None = None,
sku_ids: list[Snowflake] | None = None,
before: Snowflake | None = None,
after: Snowflake | None = None,
limit: int | None = None,
guild_id: Snowflake | None = None,
exclude_ended: bool | None = None,
) -> Response[list[monetization.Entitlement]]:
params: dict[str, Any] = {}
if user_id is not None:
params["user_id"] = user_id
if sku_ids is not None:
params["sku_ids"] = ",".join(sku_ids)
if before is not None:
params["before"] = before
if after is not None:
params["after"] = after
if limit is not None:
params["limit"] = limit
if guild_id is not None:
params["guild_id"] = guild_id
if exclude_ended is not None:
params["exclude_ended"] = exclude_ended

r = Route(
"GET",
"/applications/{application_id}/entitlements",
application_id=application_id,
)
return self.request(r)
return self.request(r, params=params)

def consume_entitlement(
self,
application_id: Snowflake,
entitlement_id: Snowflake,
) -> Response[None]:
r = Route(
"POST",
"/applications/{application_id}/entitlements/{entitlement_id}/consume",
application_id=application_id,
entitlement_id=entitlement_id,
)
return self.request(r, json=payload)

def create_test_entitlement(
self,
Expand Down
30 changes: 28 additions & 2 deletions discord/monetization.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class Entitlement(Hashable):
When the entitlement expires.
guild_id: Union[:class:`int`, :class:`MISSING`]
The ID of the guild that owns this entitlement.
consumed: :class:`bool`
Whether or not this entitlement has been consumed.
This will always be ``False`` for entitlements that are not
of type :attr:`EntitlementType.consumable`.
"""

__slots__ = (
Expand All @@ -135,6 +139,7 @@ class Entitlement(Hashable):
"starts_at",
"ends_at",
"guild_id",
"consumed",
)

def __init__(self, *, data: EntitlementPayload, state: ConnectionState) -> None:
Expand All @@ -150,17 +155,36 @@ def __init__(self, *, data: EntitlementPayload, state: ConnectionState) -> None:
)
self.ends_at: datetime | MISSING = parse_time(data.get("ends_at")) or MISSING
self.guild_id: int | MISSING = _get_as_snowflake(data, "guild_id") or MISSING
self.consumed: bool = data.get("consumed", False)

def __repr__(self) -> str:
return (
f"<Entitlement id={self.id} sku_id={self.sku_id} application_id={self.application_id} "
f"user_id={self.user_id} type={self.type} deleted={self.deleted} "
f"starts_at={self.starts_at} ends_at={self.ends_at} guild_id={self.guild_id}>"
f"starts_at={self.starts_at} ends_at={self.ends_at} guild_id={self.guild_id} consumed={self.consumed}>"
)

def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__) and other.id == self.id

async def consume(self) -> None:
"""|coro|

Consumes this entitlement.

This can only be done on entitlements of type :attr:`EntitlementType.consumable`.

Raises
------
TypeError
The entitlement is not consumable.
HTTPException
Consuming the entitlement failed.
"""
if self.type is not EntitlementType.consumable:
raise TypeError("Cannot consume non-consumable entitlement")
await self._state.http.consume_entitlement(self._state.application_id, self.id)
plun1331 marked this conversation as resolved.
Show resolved Hide resolved

async def delete(self) -> None:
"""|coro|

Expand All @@ -173,4 +197,6 @@ async def delete(self) -> None:
HTTPException
Deleting the entitlement failed.
"""
await self._state.http.delete_test_entitlement(self.id)
await self._state.http.delete_test_entitlement(
self._state.application_id, self.id
)
38 changes: 37 additions & 1 deletion docs/api/enums.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,14 @@ of :class:`enum.Enum`.

.. versionadded:: 2.5

.. attribute:: durable

Represents a durable one-time purchase.
plun1331 marked this conversation as resolved.
Show resolved Hide resolved

.. attribute:: consumable

Represents a consumable one-time purchase.
plun1331 marked this conversation as resolved.
Show resolved Hide resolved

Dorukyum marked this conversation as resolved.
Show resolved Hide resolved
.. attribute:: subscription

Represents a recurring subscription.
Expand All @@ -2384,7 +2392,35 @@ of :class:`enum.Enum`.

.. versionadded:: 2.5

.. attribute:: app_subscription
.. attribute:: purchase

Entitlement was purchased by the user.

.. attribute:: premium_subscription

Entitlement is for a Discord Nitro subscription.

.. attribute:: developer_gift

Entitlement was gifted by the developer.

.. attribute:: test_mode_purchase

Entitlement was purchased by a developer in the application's test mode.

.. attribute:: free_purchase

Entitlement was granted when the SKU was free.

.. attribute:: user_gift

Entitlement was gifted by another user.

.. attribute:: premium_purchase

Entitlement was claimed by a user for free as a Nitro subscriber.

.. attribute:: application_subscription

Entitlement was purchased as an app subscription.

Expand Down
Loading