From c7ab387e834e79f4f72d1d68d4ab83bdc8a91b61 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Sun, 30 Jun 2024 22:00:32 +0100 Subject: [PATCH 1/6] implement messagecalls --- discord/message.py | 41 +++++++++++++++++++++++++++++++++++++++ discord/types/message.py | 5 +++++ docs/api/data_classes.rst | 5 +++++ 3 files changed, 51 insertions(+) diff --git a/discord/message.py b/discord/message.py index 109bef02c8..189d1a914e 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 @@ -81,8 +82,10 @@ from .types.message import MessageActivity as MessageActivityPayload from .types.message import MessageApplication as MessageApplicationPayload from .types.message import MessageReference as MessageReferencePayload + from .types.message import MessageCall as MessageCallPayload 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 @@ -593,6 +596,33 @@ 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 + + Attributes + ---------- + ended_timestamp: Optional[:class:`datetime.datetime`] + An aware timestamp of when the call ended. + """ + + 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] + def flatten_handlers(cls): prefix = len("_handle_") handlers = [ @@ -740,6 +770,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 """ @@ -778,6 +812,7 @@ class Message(Hashable): "interaction_metadata", "thread", "_poll", + "call", ) if TYPE_CHECKING: @@ -888,6 +923,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 8988891efa..8ec0ea6694 100644 --- a/discord/types/message.py +++ b/discord/types/message.py @@ -153,3 +153,8 @@ class AllowedMentions(TypedDict): roles: SnowflakeList users: SnowflakeList replied_user: bool + +class MessageCall(TypedDict): + participants: SnowflakeList + ended_timestamp: NotRequired[str] + \ No newline at end of file diff --git a/docs/api/data_classes.rst b/docs/api/data_classes.rst index f0508ac09b..7b93247288 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 From 1db95f8e1710ba61e81a8fdcfc9c858c679cc708 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 30 Jun 2024 21:05:13 +0000 Subject: [PATCH 2/6] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/message.py | 5 +++-- discord/types/message.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/discord/message.py b/discord/message.py index 189d1a914e..489cef9cbb 100644 --- a/discord/message.py +++ b/discord/message.py @@ -81,8 +81,8 @@ 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 MessageReference as MessageReferencePayload 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 @@ -618,11 +618,12 @@ def __init__(self, state: ConnectionState, data: MessageCallPayload): 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, + 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] + def flatten_handlers(cls): prefix = len("_handle_") handlers = [ diff --git a/discord/types/message.py b/discord/types/message.py index 8ec0ea6694..5d4a1a60fc 100644 --- a/discord/types/message.py +++ b/discord/types/message.py @@ -154,7 +154,7 @@ class AllowedMentions(TypedDict): users: SnowflakeList replied_user: bool + class MessageCall(TypedDict): participants: SnowflakeList ended_timestamp: NotRequired[str] - \ No newline at end of file From 6466841824e43d2d3cd7c55a1725d3f6675215e2 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Sun, 30 Jun 2024 22:05:54 +0100 Subject: [PATCH 3/6] adjust design + cl --- CHANGELOG.md | 2 ++ discord/message.py | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04e709d410..58668307a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2409](https://github.com/Pycord-Development/pycord/pull/2409) - Added support for one-time purchases for Discord monetization. ([#2438](https://github.com/Pycord-Development/pycord/pull/2438)) +- Added `MessageCall` information. + ([#2488](https://github.com/Pycord-Development/pycord/pull/2488)) ### Fixed diff --git a/discord/message.py b/discord/message.py index 489cef9cbb..c102c6672b 100644 --- a/discord/message.py +++ b/discord/message.py @@ -600,17 +600,12 @@ class MessageCall: """Represents information about a call in a private channel. .. versionadded:: 2.6 - - Attributes - ---------- - ended_timestamp: Optional[:class:`datetime.datetime`] - An aware timestamp of when the call ended. """ 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( + self._ended_timestamp: datetime.datetime | None = utils.parse_time( data["ended_timestamp"] ) @@ -623,6 +618,11 @@ def participants(self) -> list[User | 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_") From 94403a95e0f0dd0b69904d508d4db0250b0238dd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 30 Jun 2024 21:06:14 +0000 Subject: [PATCH 4/6] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/message.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/message.py b/discord/message.py index c102c6672b..bdccafb808 100644 --- a/discord/message.py +++ b/discord/message.py @@ -620,10 +620,10 @@ def participants(self) -> list[User | Object]: @property def ended_at(self) -> datetime.datetime | None: - """An aware timestamp of when the call ended. - """ + """An aware timestamp of when the call ended.""" return self._ended_timestamp + def flatten_handlers(cls): prefix = len("_handle_") handlers = [ From 468dff39a4421913a46fc526b49ac2b36acef48a Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Sun, 30 Jun 2024 22:09:23 +0100 Subject: [PATCH 5/6] __all__ --- discord/message.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/message.py b/discord/message.py index bdccafb808..1a76bb7937 100644 --- a/discord/message.py +++ b/discord/message.py @@ -99,6 +99,7 @@ "Message", "PartialMessage", "MessageReference", + "MessageCall", "DeletedReferencedMessage", ) From 99e1e333d8cd7491112b1463101ac2d4bb766b1b Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Mon, 1 Jul 2024 14:58:36 +0300 Subject: [PATCH 6/6] message.py aktualisieren Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- discord/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/message.py b/discord/message.py index 0e6379c0f2..37ffd86f53 100644 --- a/discord/message.py +++ b/discord/message.py @@ -622,7 +622,7 @@ 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` + then it will be returned as an :class:`Object`. """ return [self._state.get_user(int(i)) or Object(i) for i in self._participants]