diff --git a/CHANGELOG.md b/CHANGELOG.md index 09d02c6438..911ebd6480 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,8 @@ These changes are available on the `master` branch, but have not yet been releas - Added `bypass_verification` parameter to `Member.edit`. ([#2489](https://github.com/Pycord-Development/pycord/pull/2489)) - Added `RoleFlags`. ([#2487](https://github.com/Pycord-Development/pycord/pull/2487)) +- Added `MessageCall` information. + ([#2488](https://github.com/Pycord-Development/pycord/pull/2488)) ### Fixed diff --git a/discord/message.py b/discord/message.py index 23a81bbd96..37ffd86f53 100644 --- a/discord/message.py +++ b/discord/message.py @@ -52,6 +52,7 @@ from .guild import Guild from .member import Member from .mixins import Hashable +from .object import Object from .partial_emoji import PartialEmoji from .poll import Poll from .reaction import Reaction @@ -80,9 +81,11 @@ from .types.message import Message as MessagePayload from .types.message import MessageActivity as MessageActivityPayload from .types.message import MessageApplication as MessageApplicationPayload + from .types.message import MessageCall as MessageCallPayload from .types.message import MessageReference as MessageReferencePayload from .types.message import Reaction as ReactionPayload from .types.poll import Poll as PollPayload + from .types.snowflake import SnowflakeList from .types.threads import ThreadArchiveDuration from .types.user import User as UserPayload from .ui.view import View @@ -96,6 +99,7 @@ "Message", "PartialMessage", "MessageReference", + "MessageCall", "DeletedReferencedMessage", ) @@ -600,6 +604,34 @@ def to_dict(self) -> MessageReferencePayload: to_message_reference_dict = to_dict +class MessageCall: + """Represents information about a call in a private channel. + + .. versionadded:: 2.6 + """ + + def __init__(self, state: ConnectionState, data: MessageCallPayload): + self._state: ConnectionState = state + self._participants: SnowflakeList = data.get("participants", []) + self._ended_timestamp: datetime.datetime | None = utils.parse_time( + data["ended_timestamp"] + ) + + @property + def participants(self) -> list[User | Object]: + """A list of :class:`User` that participated in this call. + + If a user is not found in the client's cache, + then it will be returned as an :class:`Object`. + """ + return [self._state.get_user(int(i)) or Object(i) for i in self._participants] + + @property + def ended_at(self) -> datetime.datetime | None: + """An aware timestamp of when the call ended.""" + return self._ended_timestamp + + def flatten_handlers(cls): prefix = len("_handle_") handlers = [ @@ -747,6 +779,10 @@ class Message(Hashable): poll: Optional[:class:`Poll`] The poll associated with this message, if applicable. + .. versionadded:: 2.6 + call: Optional[:class:`MessageCall`] + The call information associated with this message, if applicable. + .. versionadded:: 2.6 """ @@ -785,6 +821,7 @@ class Message(Hashable): "interaction_metadata", "thread", "_poll", + "call", ) if TYPE_CHECKING: @@ -895,6 +932,12 @@ def __init__( except KeyError: self.thread = None + self.call: MessageCall | None + try: + self.call = MessageCall(state=self._state, data=data["call"]) + except KeyError: + self.call = None + for handler in ("author", "member", "mentions", "mention_roles"): try: getattr(self, f"_handle_{handler}")(data[handler]) diff --git a/discord/types/message.py b/discord/types/message.py index a29d1487a4..f138609d1b 100644 --- a/discord/types/message.py +++ b/discord/types/message.py @@ -154,3 +154,8 @@ class AllowedMentions(TypedDict): roles: SnowflakeList users: SnowflakeList replied_user: bool + + +class MessageCall(TypedDict): + participants: SnowflakeList + ended_timestamp: NotRequired[str] diff --git a/docs/api/data_classes.rst b/docs/api/data_classes.rst index 272b21e74b..1d891b90cd 100644 --- a/docs/api/data_classes.rst +++ b/docs/api/data_classes.rst @@ -49,6 +49,11 @@ Message .. autoclass:: MessageReference :members: +.. attributetable:: MessageCall + +.. autoclass:: MessageCall + :members: + .. attributetable:: PartialMessage .. autoclass:: PartialMessage