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: role subscriptions #940

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,12 @@ of :class:`enum.Enum`.

.. versionadded:: 2.1

.. attribute:: role_subscription_purchase

The system message denoting that a role subscription was purchased.

.. versionadded:: 2.4

.. class:: UserFlags

Represents Discord User flags.
Expand Down
1 change: 1 addition & 0 deletions nextcord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class MessageType(IntEnum):
guild_invite_reminder = 22
context_menu_command = 23
auto_moderation_action = 24
role_subscription_purchase = 25


class VoiceRegion(StrEnum):
Expand Down
3 changes: 3 additions & 0 deletions nextcord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,9 @@ def system_content(self):
if self.type is MessageType.guild_invite_reminder:
return "Wondering who to invite?\nStart by inviting anyone who can help you build the server!"

if self.type is MessageType.role_subscription_purchase:
... # TODO: implement this
Soheab marked this conversation as resolved.
Show resolved Hide resolved

async def delete(self, *, delay: Optional[float] = None) -> None:
"""|coro|

Expand Down
17 changes: 17 additions & 0 deletions nextcord/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,32 @@ class RoleTags:
The bot's user ID that manages this role.
integration_id: Optional[:class:`int`]
The integration ID that manages the role.
subscription_listing_id: Optional[:class:`int`]
The id of this role's subscription sku and listing

.. versionadded:: 2.4
"""

__slots__ = (
"bot_id",
"integration_id",
"subscription_listing_id",
"_premium_subscriber",
"_available_for_purchase",
)

def __init__(self, data: RoleTagPayload):
self.bot_id: Optional[int] = get_as_snowflake(data, "bot_id")
self.integration_id: Optional[int] = get_as_snowflake(data, "integration_id")
self.subscription_listing_id: Optional[int] = get_as_snowflake(
data, "subscription_listing_id"
)
# NOTE: The API returns "null" for this if it's valid, which corresponds to None.
# This is different from other fields where "null" means "not there".
# So in this case, a value of None is the same as True.
# Which means we would need a different sentinel.
self._premium_subscriber: Optional[Any] = data.get("premium_subscriber", MISSING)
self._available_for_purchase: Optional[Any] = data.get("available_for_purchase", MISSING)
Soheab marked this conversation as resolved.
Show resolved Hide resolved

def is_bot_managed(self) -> bool:
""":class:`bool`: Whether the role is associated with a bot."""
Expand All @@ -72,6 +82,13 @@ def is_premium_subscriber(self) -> bool:
""":class:`bool`: Whether the role is the premium subscriber, AKA "boost", role for the guild."""
return self._premium_subscriber is None

def is_available_for_purchase(self) -> bool:
""":class:`bool`: Whether the role is available for purchase.

.. versionadded:: 2.4
"""
return self._available_for_purchase is None

def is_integration(self) -> bool:
""":class:`bool`: Whether the role is managed by an integration."""
return self.integration_id is not None
Expand Down
2 changes: 2 additions & 0 deletions nextcord/types/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class UnavailableGuild(TypedDict):
"VERIFIED",
"VIP_REGIONS",
"WELCOME_SCREEN_ENABLED",
"ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE",
"ROLE_SUBSCRIPTIONS_ENABLED",
Soheab marked this conversation as resolved.
Show resolved Hide resolved
]


Expand Down
2 changes: 2 additions & 0 deletions nextcord/types/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ class RoleTags(TypedDict, total=False):
bot_id: Snowflake
integration_id: Snowflake
premium_subscriber: None
subscription_listing_id: Snowflake
available_for_purchase: None