Repository: Rapptz/discord.py
File: discord/message.py (Python)

Code before:


class MessageCall:
    """Represents a message's call data in a private channel from a :class:`~discord.Message`.

    .. versionadded:: 2.5

    Attributes
    -----------
    ended_timestamp: Optional[:class:`datetime.datetime`]
        The timestamp the call has ended.
    participants: List[Optional[:class:`User`]]
        A list of users that participated in the call.
    """

    __slots__ = ('ended_timestamp', 'participants')

    def __repr__(self) -> str:
        return f'<MessageCall participants={self.participants!r}>'

    def __init__(self, *, state: ConnectionState, data: MessageCallPayload):
        self.ended_timestamp: Optional[datetime.datetime] = utils.parse_time(data.get('ended_timestamp'))
        self.participants: List[Optional[User]] = []

        for user_id in data['participants']:
            self.participants.append(state.get_user(int(user_id)))


class RoleSubscriptionInfo:
    """Represents a message's role subscription information.

    This is currently only attached to messages of type :attr:`MessageType.role_subscription_purchase`.

    .. versionadded:: 2.0

    Attributes
    -----------
    role_subscription_listing_id: :class:`int`
        The ID of the SKU and listing that the user is subscribed to.
    tier_name: :class:`str`
        The name of the tier that the user is subscribed to.
    total_months_subscribed: :class:`int`
        The cumulative number of months that the user has been subscribed for.
    is_renewal: :class:`bool`
        Whether this notification is for a renewal rather than a new purchase.
    """

    __slots__ = (
        'role_subscription_listing_id',
        'tier_name',
        'total_months_subscribed',

Review comment (suggestion):
I think it should be ``List[:class:`User`]`` (or ``List[Union[:class:`User`, :class:`Object`]]``) instead. The participants user objects exist in `Message.mentions`.

Code after:
        """Optional[:class:`Asset`]: The application's cover image, if any."""
        if self._cover_image:
            return Asset._from_app_icon(
                state=self._state, object_id=self.id, icon_hash=self._cover_image, asset_type='cover_image'
            )
        return None


class CallMessage:
    """Represents a message's call data in a private channel from a :class:`~discord.Message`.

    .. versionadded:: 2.5

    Attributes
    -----------
    ended_timestamp: Optional[:class:`datetime.datetime`]
        The timestamp the call has ended.
    participants: List[:class:`User`]
        A list of users that participated in the call.
    """

    __slots__ = ('_message', 'ended_timestamp', 'participants')

    def __repr__(self) -> str:
        return f'<CallMessage participants={self.participants!r}>'

    def __init__(self, *, state: ConnectionState, message: Message, data: CallMessagePayload):
        self._message: Message = message
        self.ended_timestamp: Optional[datetime.datetime] = utils.parse_time(data.get('ended_timestamp'))
        self.participants: List[User] = []

        for user_id in data['participants']:
            user_id = int(user_id)
            if user_id == self._message.author.id:
                self.participants.append(self._message.author)  # type: ignore # can't be a Member here
            else:
                user = state.get_user(user_id)
                if user is not None:
                    self.participants.append(user)

    @property
    def duration(self) -> datetime.timedelta:
        """:class:`datetime.timedelta`: The duration the call has lasted or is already ongoing."""
        if self.ended_timestamp is None:
            return utils.utcnow() - self._message.created_at
        else:
            return self.ended_timestamp - self._message.created_at

    def is_ended(self) -> bool:
        """:class:`bool`: Whether the call is ended or not."""
        return self.ended_timestamp is not None