|
52 | 52 | from .guild import Guild
|
53 | 53 | from .member import Member
|
54 | 54 | from .mixins import Hashable
|
| 55 | +from .object import Object |
55 | 56 | from .partial_emoji import PartialEmoji
|
56 | 57 | from .poll import Poll
|
57 | 58 | from .reaction import Reaction
|
|
80 | 81 | from .types.message import Message as MessagePayload
|
81 | 82 | from .types.message import MessageActivity as MessageActivityPayload
|
82 | 83 | from .types.message import MessageApplication as MessageApplicationPayload
|
| 84 | + from .types.message import MessageCall as MessageCallPayload |
83 | 85 | from .types.message import MessageReference as MessageReferencePayload
|
84 | 86 | from .types.message import Reaction as ReactionPayload
|
85 | 87 | from .types.poll import Poll as PollPayload
|
| 88 | + from .types.snowflake import SnowflakeList |
86 | 89 | from .types.threads import ThreadArchiveDuration
|
87 | 90 | from .types.user import User as UserPayload
|
88 | 91 | from .ui.view import View
|
|
96 | 99 | "Message",
|
97 | 100 | "PartialMessage",
|
98 | 101 | "MessageReference",
|
| 102 | + "MessageCall", |
99 | 103 | "DeletedReferencedMessage",
|
100 | 104 | )
|
101 | 105 |
|
@@ -600,6 +604,34 @@ def to_dict(self) -> MessageReferencePayload:
|
600 | 604 | to_message_reference_dict = to_dict
|
601 | 605 |
|
602 | 606 |
|
| 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 | + |
603 | 635 | def flatten_handlers(cls):
|
604 | 636 | prefix = len("_handle_")
|
605 | 637 | handlers = [
|
@@ -747,6 +779,10 @@ class Message(Hashable):
|
747 | 779 | poll: Optional[:class:`Poll`]
|
748 | 780 | The poll associated with this message, if applicable.
|
749 | 781 |
|
| 782 | + .. versionadded:: 2.6 |
| 783 | + call: Optional[:class:`MessageCall`] |
| 784 | + The call information associated with this message, if applicable. |
| 785 | +
|
750 | 786 | .. versionadded:: 2.6
|
751 | 787 | """
|
752 | 788 |
|
@@ -785,6 +821,7 @@ class Message(Hashable):
|
785 | 821 | "interaction_metadata",
|
786 | 822 | "thread",
|
787 | 823 | "_poll",
|
| 824 | + "call", |
788 | 825 | )
|
789 | 826 |
|
790 | 827 | if TYPE_CHECKING:
|
@@ -895,6 +932,12 @@ def __init__(
|
895 | 932 | except KeyError:
|
896 | 933 | self.thread = None
|
897 | 934 |
|
| 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 | + |
898 | 941 | for handler in ("author", "member", "mentions", "mention_roles"):
|
899 | 942 | try:
|
900 | 943 | getattr(self, f"_handle_{handler}")(data[handler])
|
|
0 commit comments