Skip to content

Commit

Permalink
feat: voice message support (#2016)
Browse files Browse the repository at this point in the history
Co-authored-by: JustaSqu1d <overenchanted.gaming@gmail.com>
Signed-off-by: Lala Sabathil <aiko@aitsys.dev>
  • Loading branch information
Lulalaby and JustaSqu1d authored Apr 25, 2023
1 parent 3847a8c commit 3e534b7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ These changes are available on the `master` branch, but have not yet been releas
- Added new `application_auto_moderation_rule_create_badge` to `ApplicationFlags`.
([#1992](https://github.com/Pycord-Development/pycord/pull/1992))
- Added `custom_message` to AutoModActionMetadata.
- ([#2029](https://github.com/Pycord-Development/pycord/pull/2029))
([#2029](https://github.com/Pycord-Development/pycord/pull/2029))
- Added support for
[voice messages](https://github.com/discord/discord-api-docs/pull/6082).
([#2016](https://github.com/Pycord-Development/pycord/pull/2016))

### Changed

Expand Down
8 changes: 8 additions & 0 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@ def suppress_notifications(self):

return 4096

@flag_value
def is_voice_message(self):
""":class:`bool`: Returns ``True`` if this message is a voice message.
.. versionadded:: 2.5
"""
return 8192


@fill_with_flags()
class PublicUserFlags(BaseFlags):
Expand Down
16 changes: 15 additions & 1 deletion discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class Attachment(Hashable):
case of images. When the message is deleted, this URL might be valid for a few
minutes or not valid at all.
content_type: Optional[:class:`str`]
The attachment's `media type <https://en.wikipedia.org/wiki/Media_type>`_
The attachment's `media type <https://en.wikipedia.org/wiki/Media_type>`_.
ephemeral: :class:`bool`
Whether the attachment is ephemeral or not.
Expand All @@ -169,6 +169,16 @@ class Attachment(Hashable):
The attachment's description.
.. versionadded:: 2.0
duration_secs: Optional[:class:`float`]
The duration of the audio file (currently for voice messages).
.. versionadded:: 2.5
waveform: Optional[:class:`str`]
The base64 encoded bytearray representing a sampled waveform (currently for voice messages).
.. versionadded:: 2.5
"""

__slots__ = (
Expand All @@ -183,6 +193,8 @@ class Attachment(Hashable):
"content_type",
"ephemeral",
"description",
"duration_secs",
"waveform",
)

def __init__(self, *, data: AttachmentPayload, state: ConnectionState):
Expand All @@ -197,6 +209,8 @@ def __init__(self, *, data: AttachmentPayload, state: ConnectionState):
self.content_type: str | None = data.get("content_type")
self.ephemeral: bool = data.get("ephemeral", False)
self.description: str | None = data.get("description")
self.duration_secs: float | None = data.get("duration_secs")
self.waveform: str | None = data.get("waveform")

def is_spoiler(self) -> bool:
"""Whether this attachment contains a spoiler."""
Expand Down
9 changes: 9 additions & 0 deletions discord/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,14 @@ def moderate_members(self) -> int:
"""
return 1 << 40

@flag_value
def send_voice_messages(self) -> int:
""":class:`bool`: Returns ``True`` if a member can send voice messages.
.. versionadded:: 2.5
"""
return 1 << 46


PO = TypeVar("PO", bound="PermissionOverwrite")

Expand Down Expand Up @@ -727,6 +735,7 @@ class PermissionOverwrite:
use_external_stickers: bool | None
start_embedded_activities: bool | None
moderate_members: bool | None
send_voice_messages: bool | None

def __init__(self, **kwargs: bool | None):
self._values: dict[str, bool | None] = {}
Expand Down
2 changes: 2 additions & 0 deletions discord/types/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class Attachment(TypedDict):
size: int
url: str
proxy_url: str
duration_secs: NotRequired[float]
waveform: NotRequired[str]


MessageActivityType = Literal[1, 2, 3, 5]
Expand Down

0 comments on commit 3e534b7

Please sign in to comment.