|
|
@ -51,7 +51,7 @@ from .reaction import Reaction |
|
|
|
from .emoji import Emoji |
|
|
|
from .partial_emoji import PartialEmoji |
|
|
|
from .calls import CallMessage |
|
|
|
from .enums import MessageType, ChannelType, ApplicationCommandType, try_enum |
|
|
|
from .enums import MessageType, ChannelType, ApplicationCommandType, PurchaseNotificationType, try_enum |
|
|
|
from .errors import HTTPException |
|
|
|
from .components import _component_factory |
|
|
|
from .embeds import Embed |
|
|
@ -83,6 +83,8 @@ if TYPE_CHECKING: |
|
|
|
MessageActivity as MessageActivityPayload, |
|
|
|
RoleSubscriptionData as RoleSubscriptionDataPayload, |
|
|
|
MessageSearchResult as MessageSearchResultPayload, |
|
|
|
PurchaseNotificationResponse as PurchaseNotificationResponsePayload, |
|
|
|
GuildProductPurchase as GuildProductPurchasePayload, |
|
|
|
) |
|
|
|
|
|
|
|
from .types.interactions import MessageInteraction as MessageInteractionPayload |
|
|
@ -116,6 +118,8 @@ __all__ = ( |
|
|
|
'MessageReference', |
|
|
|
'DeletedReferencedMessage', |
|
|
|
'RoleSubscriptionInfo', |
|
|
|
'GuildProductPurchase', |
|
|
|
'PurchaseNotification', |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
@ -627,6 +631,64 @@ class RoleSubscriptionInfo: |
|
|
|
self.is_renewal: bool = data['is_renewal'] |
|
|
|
|
|
|
|
|
|
|
|
class GuildProductPurchase: |
|
|
|
"""Represents a message's guild product that the user has purchased. |
|
|
|
|
|
|
|
.. versionadded:: 2.5 |
|
|
|
|
|
|
|
Attributes |
|
|
|
----------- |
|
|
|
listing_id: :class:`int` |
|
|
|
The ID of the listing that the user has purchased. |
|
|
|
product_name: :class:`str` |
|
|
|
The name of the product that the user has purchased. |
|
|
|
""" |
|
|
|
|
|
|
|
__slots__ = ('listing_id', 'product_name') |
|
|
|
|
|
|
|
def __init__(self, data: GuildProductPurchasePayload) -> None: |
|
|
|
self.listing_id: int = int(data['listing_id']) |
|
|
|
self.product_name: str = data['product_name'] |
|
|
|
|
|
|
|
def __hash__(self) -> int: |
|
|
|
return self.listing_id >> 22 |
|
|
|
|
|
|
|
def __eq__(self, other: object) -> bool: |
|
|
|
return isinstance(other, GuildProductPurchase) and other.listing_id == self.listing_id |
|
|
|
|
|
|
|
def __ne__(self, other: object) -> bool: |
|
|
|
return not self.__eq__(other) |
|
|
|
|
|
|
|
|
|
|
|
class PurchaseNotification: |
|
|
|
"""Represents a message's purchase notification data. |
|
|
|
|
|
|
|
This is currently only attached to messages of type :attr:`MessageType.purchase_notification`. |
|
|
|
|
|
|
|
.. versionadded:: 2.5 |
|
|
|
|
|
|
|
Attributes |
|
|
|
----------- |
|
|
|
guild_product_purchase: Optional[:class:`GuildProductPurchase`] |
|
|
|
The guild product purchase that prompted the message. |
|
|
|
""" |
|
|
|
|
|
|
|
__slots__ = ('_type', 'guild_product_purchase') |
|
|
|
|
|
|
|
def __init__(self, data: PurchaseNotificationResponsePayload) -> None: |
|
|
|
self._type: int = data['type'] |
|
|
|
|
|
|
|
self.guild_product_purchase: Optional[GuildProductPurchase] = None |
|
|
|
guild_product_purchase = data.get('guild_product_purchase') |
|
|
|
if guild_product_purchase is not None: |
|
|
|
self.guild_product_purchase = GuildProductPurchase(guild_product_purchase) |
|
|
|
|
|
|
|
@property |
|
|
|
def type(self) -> PurchaseNotificationType: |
|
|
|
""":class:`PurchaseNotificationType`: The type of purchase notification.""" |
|
|
|
return try_enum(PurchaseNotificationType, self._type) |
|
|
|
|
|
|
|
|
|
|
|
class PartialMessage(Hashable): |
|
|
|
"""Represents a partial message to aid with working messages when only |
|
|
|
a message and channel ID are present. |
|
|
@ -1595,6 +1657,10 @@ class Message(PartialMessage, Hashable): |
|
|
|
The poll attached to this message. |
|
|
|
|
|
|
|
.. versionadded:: 2.4 |
|
|
|
purchase_notification: Optional[:class:`PurchaseNotification`] |
|
|
|
The data of the purchase notification that prompted this :attr:`MessageType.purchase_notification` message. |
|
|
|
|
|
|
|
.. versionadded:: 2.5 |
|
|
|
hit: :class:`bool` |
|
|
|
Whether the message was a hit in a search result. As surrounding messages |
|
|
|
are no longer returned in search results, this is always ``True`` for search results. |
|
|
@ -1649,6 +1715,7 @@ class Message(PartialMessage, Hashable): |
|
|
|
'application_id', |
|
|
|
'position', |
|
|
|
'poll', |
|
|
|
'purchase_notification', |
|
|
|
'hit', |
|
|
|
'total_results', |
|
|
|
'analytics_id', |
|
|
@ -1769,6 +1836,14 @@ class Message(PartialMessage, Hashable): |
|
|
|
else: |
|
|
|
self.role_subscription = RoleSubscriptionInfo(role_subscription) |
|
|
|
|
|
|
|
self.purchase_notification: Optional[PurchaseNotification] = None |
|
|
|
try: |
|
|
|
purchase_notification = data['purchase_notification'] |
|
|
|
except KeyError: |
|
|
|
pass |
|
|
|
else: |
|
|
|
self.purchase_notification = PurchaseNotification(purchase_notification) |
|
|
|
|
|
|
|
search_payload = search_result or {} |
|
|
|
self.hit: bool = data.get('hit', False) |
|
|
|
self.total_results: Optional[int] = search_payload.get('total_results') |
|
|
@ -2295,6 +2370,11 @@ class Message(PartialMessage, Hashable): |
|
|
|
if self.type is MessageType.guild_incident_report_false_alarm: |
|
|
|
return f'{self.author.name} reported a false alarm in {self.guild}.' |
|
|
|
|
|
|
|
if self.type is MessageType.purchase_notification and self.purchase_notification is not None: |
|
|
|
guild_product_purchase = self.purchase_notification.guild_product_purchase |
|
|
|
if guild_product_purchase is not None: |
|
|
|
return f'{self.author.name} has purchased {guild_product_purchase.product_name}!' |
|
|
|
|
|
|
|
# Fallback for unknown message types |
|
|
|
return self.content |
|
|
|
|
|
|
|