Skip to content

Commit bcf43c5

Browse files
NeloBlivionpre-commit-ci[bot]Dorukyum
authored andcommitted
feat: implement MessageCall (Pycord-Development#2488)
* implement messagecalls * style(pre-commit): auto fixes from pre-commit.com hooks * adjust design + cl * style(pre-commit): auto fixes from pre-commit.com hooks * __all__ * message.py aktualisieren Signed-off-by: Dorukyum <[email protected]> --------- Signed-off-by: UK <[email protected]> Signed-off-by: Dorukyum <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dorukyum <[email protected]>
1 parent 6934fd7 commit bcf43c5

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ These changes are available on the `master` branch, but have not yet been releas
3838
- Added `bypass_verification` parameter to `Member.edit`.
3939
([#2489](https://github.com/Pycord-Development/pycord/pull/2489))
4040
- Added `RoleFlags`. ([#2487](https://github.com/Pycord-Development/pycord/pull/2487))
41+
- Added `MessageCall` information.
42+
([#2488](https://github.com/Pycord-Development/pycord/pull/2488))
4143

4244
### Fixed
4345

discord/message.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from .guild import Guild
5353
from .member import Member
5454
from .mixins import Hashable
55+
from .object import Object
5556
from .partial_emoji import PartialEmoji
5657
from .poll import Poll
5758
from .reaction import Reaction
@@ -80,9 +81,11 @@
8081
from .types.message import Message as MessagePayload
8182
from .types.message import MessageActivity as MessageActivityPayload
8283
from .types.message import MessageApplication as MessageApplicationPayload
84+
from .types.message import MessageCall as MessageCallPayload
8385
from .types.message import MessageReference as MessageReferencePayload
8486
from .types.message import Reaction as ReactionPayload
8587
from .types.poll import Poll as PollPayload
88+
from .types.snowflake import SnowflakeList
8689
from .types.threads import ThreadArchiveDuration
8790
from .types.user import User as UserPayload
8891
from .ui.view import View
@@ -96,6 +99,7 @@
9699
"Message",
97100
"PartialMessage",
98101
"MessageReference",
102+
"MessageCall",
99103
"DeletedReferencedMessage",
100104
)
101105

@@ -600,6 +604,34 @@ def to_dict(self) -> MessageReferencePayload:
600604
to_message_reference_dict = to_dict
601605

602606

607+
class MessageCall:
608+
"""Represents information about a call in a private channel.
609+
610+
.. versionadded:: 2.6
611+
"""
612+
613+
def __init__(self, state: ConnectionState, data: MessageCallPayload):
614+
self._state: ConnectionState = state
615+
self._participants: SnowflakeList = data.get("participants", [])
616+
self._ended_timestamp: datetime.datetime | None = utils.parse_time(
617+
data["ended_timestamp"]
618+
)
619+
620+
@property
621+
def participants(self) -> list[User | Object]:
622+
"""A list of :class:`User` that participated in this call.
623+
624+
If a user is not found in the client's cache,
625+
then it will be returned as an :class:`Object`.
626+
"""
627+
return [self._state.get_user(int(i)) or Object(i) for i in self._participants]
628+
629+
@property
630+
def ended_at(self) -> datetime.datetime | None:
631+
"""An aware timestamp of when the call ended."""
632+
return self._ended_timestamp
633+
634+
603635
def flatten_handlers(cls):
604636
prefix = len("_handle_")
605637
handlers = [
@@ -747,6 +779,10 @@ class Message(Hashable):
747779
poll: Optional[:class:`Poll`]
748780
The poll associated with this message, if applicable.
749781
782+
.. versionadded:: 2.6
783+
call: Optional[:class:`MessageCall`]
784+
The call information associated with this message, if applicable.
785+
750786
.. versionadded:: 2.6
751787
"""
752788

@@ -785,6 +821,7 @@ class Message(Hashable):
785821
"interaction_metadata",
786822
"thread",
787823
"_poll",
824+
"call",
788825
)
789826

790827
if TYPE_CHECKING:
@@ -895,6 +932,12 @@ def __init__(
895932
except KeyError:
896933
self.thread = None
897934

935+
self.call: MessageCall | None
936+
try:
937+
self.call = MessageCall(state=self._state, data=data["call"])
938+
except KeyError:
939+
self.call = None
940+
898941
for handler in ("author", "member", "mentions", "mention_roles"):
899942
try:
900943
getattr(self, f"_handle_{handler}")(data[handler])

discord/types/message.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,8 @@ class AllowedMentions(TypedDict):
154154
roles: SnowflakeList
155155
users: SnowflakeList
156156
replied_user: bool
157+
158+
159+
class MessageCall(TypedDict):
160+
participants: SnowflakeList
161+
ended_timestamp: NotRequired[str]

docs/api/data_classes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ Message
4949
.. autoclass:: MessageReference
5050
:members:
5151

52+
.. attributetable:: MessageCall
53+
54+
.. autoclass:: MessageCall
55+
:members:
56+
5257
.. attributetable:: PartialMessage
5358

5459
.. autoclass:: PartialMessage

0 commit comments

Comments
 (0)