Skip to content

Commit

Permalink
docs: document classes properly
Browse files Browse the repository at this point in the history
  • Loading branch information
plun1331 authored Dec 2, 2023
1 parent b00cd91 commit 0b1f174
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ async def fetch_skus(self) -> list[SKU]:
The bot's SKUs.
"""
data = await self._connection.http.list_skus(self.application_id)
return [SKU(data=s, state=self._connection) for s in data]
return [SKU(data=s) for s in data]

async def fetch_entitlements(self) -> list[Entitlement]:
"""|coro|
Expand Down
55 changes: 52 additions & 3 deletions discord/monetization.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@


class SKU(Hashable):
"""Represents a Discord SKU (stock-keeping unit).
.. versionadded:: 2.6
Attributes
----------
id: :class:`int`
The SKU's ID.
type: :class:`SKUType`
The type of SKU.
application_id: :class:`int`
The ID of the application this SKU belongs to.
name: :class:`str`
The name of the SKU.
slug: :class:`str`
The SKU's slug.
flags: :class:`SKUFlags`
The SKU's flags.
"""
__slots__ = (
"id",
"type",
Expand All @@ -56,14 +75,13 @@ class SKU(Hashable):
"flags",
)

def __init__(self, *, data: SKUPayload, state: ConnectionState) -> None:
self._state = state
def __init__(self, *, data: SKUPayload) -> None:
self.id: int = int(data["id"])
self.type: SKUType = try_enum(SKUType, data["type"])
self.application_id: int = int(data["application_id"])
self.name: str = data["name"]
self.slug: str = data["slug"]
self.flags: SKUFlags = SKUFlags(data["flags"])
self.flags: SKUFlags = SKUFlags._from_value(data["flags"])

def __repr__(self) -> str:
return (
Expand All @@ -73,9 +91,35 @@ def __repr__(self) -> str:

def __str__(self) -> str:
return self.name

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


class Entitlement(Hashable):
"""Represents a Discord entitlement.
.. versionadded:: 2.6
Attributes
----------
id: :class:`int`
The entitlement's ID.
sku_id: :class:`int`
The ID of the SKU this entitlement is for.
application_id: :class:`int`
The ID of the application this entitlement belongs to.
user_id: Union[:class:`int`, :class:`MISSING`]
The ID of the user that owns this entitlement.
type: :class:`EntitlementType`
The type of entitlement.
deleted: :class:`bool`
Whether the entitlement has been deleted.
starts_at: Union[:class:`datetime.datetime`, :class:`MISSING`]
When the entitlement starts.
ends_at: Union[:class:`datetime.datetime`, :class:`MISSING`]
When the entitlement expires.
"""
__slots__ = (
"_state",
"id",
Expand Down Expand Up @@ -107,12 +151,17 @@ def __repr__(self) -> str:
f"user_id={self.user_id} type={self.type} deleted={self.deleted} "
f"starts_at={self.starts_at} ends_at={self.ends_at}>"
)

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

async def delete(self) -> None:
"""|coro|
Deletes a test entitlement.
A test entitlement is an entitlement that was created using :meth:`Guild.create_test_entitlement` or :meth:`User.create_test_entitlement`.
Raises
------
HTTPException
Expand Down

0 comments on commit 0b1f174

Please sign in to comment.