Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 interactions/models/discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ class Permissions(DiscordIntFlag): # type: ignore
"""Allows for creating emojis, stickers, and soundboard sounds"""
USE_EXTERNAL_SOUNDS = 1 << 45
"""Allows the usage of custom sounds from other servers"""
SEND_VOICE_MESSAGES = 1 << 46
"""Allows for sending audio messages"""

# Shortcuts/grouping/aliases
REQUIRES_MFA = (
Expand Down
18 changes: 18 additions & 0 deletions interactions/models/discord/message.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import base64
import re
from dataclasses import dataclass
from typing import (
Expand Down Expand Up @@ -89,12 +90,22 @@ class Attachment(DiscordObject):
"""width of file (if image)"""
ephemeral: bool = attrs.field(repr=False, default=False)
"""whether this attachment is ephemeral"""
duration_secs: Optional[int] = attrs.field(repr=False, default=None)
"""the duration of the audio file (currently for voice messages)"""
waveform: bytearray = attrs.field(repr=False, default=None)
"""base64 encoded bytearray representing a sampled waveform (currently for voice messages)"""

@property
def resolution(self) -> tuple[Optional[int], Optional[int]]:
"""Returns the image resolution of the attachment file"""
return self.height, self.width

@classmethod
def _process_dict(cls, data: Dict[str, Any], _) -> Dict[str, Any]:
if waveform := data.pop("waveform", None):
data["waveform"] = bytearray(base64.b64decode(waveform))
return data


@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class ChannelMention(DiscordObject):
Expand Down Expand Up @@ -369,6 +380,13 @@ def thread(self) -> "models.TYPE_THREAD_CHANNEL":
"""The thread that was started from this message, if any"""
return self._client.cache.get_channel(self.id)

@property
def editable(self) -> bool:
"""Whether this message can be edited by the current user"""
if self.author.id == self._client.user.id:
return MessageFlags.VOICE_MESSAGE not in self.flags
return False

async def fetch_referenced_message(self, *, force: bool = False) -> Optional["Message"]:
"""
Fetch the message this message is referencing, if any.
Expand Down