Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement MessageCall #2488

Merged
merged 8 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ These changes are available on the `master` branch, but have not yet been releas
- Added `MemberFlags`. ([#2489](https://github.com/Pycord-Development/pycord/pull/2489))
- Added `bypass_verification` parameter to `Member.edit`.
([#2489](https://github.com/Pycord-Development/pycord/pull/2489))
- Added `MessageCall` information.
([#2488](https://github.com/Pycord-Development/pycord/pull/2488))

### Fixed

Expand Down
43 changes: 43 additions & 0 deletions discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -96,6 +99,7 @@
"Message",
"PartialMessage",
"MessageReference",
"MessageCall",
"DeletedReferencedMessage",
)

Expand Down Expand Up @@ -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`
Dorukyum marked this conversation as resolved.
Show resolved Hide resolved
"""
Dorukyum marked this conversation as resolved.
Show resolved Hide resolved
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 = [
Expand Down Expand Up @@ -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
"""

Expand Down Expand Up @@ -785,6 +821,7 @@ class Message(Hashable):
"interaction_metadata",
"thread",
"_poll",
"call",
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -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])
Expand Down
5 changes: 5 additions & 0 deletions discord/types/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,8 @@ class AllowedMentions(TypedDict):
roles: SnowflakeList
users: SnowflakeList
replied_user: bool


class MessageCall(TypedDict):
participants: SnowflakeList
ended_timestamp: NotRequired[str]
5 changes: 5 additions & 0 deletions docs/api/data_classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ Message
.. autoclass:: MessageReference
:members:

.. attributetable:: MessageCall

.. autoclass:: MessageCall
:members:

.. attributetable:: PartialMessage

.. autoclass:: PartialMessage
Expand Down
Loading