|
1 | 1 | import asyncio
|
| 2 | +import base64 |
2 | 3 | import re
|
3 | 4 | from dataclasses import dataclass
|
4 | 5 | from typing import (
|
@@ -89,12 +90,22 @@ class Attachment(DiscordObject):
|
89 | 90 | """width of file (if image)"""
|
90 | 91 | ephemeral: bool = attrs.field(repr=False, default=False)
|
91 | 92 | """whether this attachment is ephemeral"""
|
| 93 | + duration_secs: Optional[int] = attrs.field(repr=False, default=None) |
| 94 | + """the duration of the audio file (currently for voice messages)""" |
| 95 | + waveform: bytearray = attrs.field(repr=False, default=None) |
| 96 | + """base64 encoded bytearray representing a sampled waveform (currently for voice messages)""" |
92 | 97 |
|
93 | 98 | @property
|
94 | 99 | def resolution(self) -> tuple[Optional[int], Optional[int]]:
|
95 | 100 | """Returns the image resolution of the attachment file"""
|
96 | 101 | return self.height, self.width
|
97 | 102 |
|
| 103 | + @classmethod |
| 104 | + def _process_dict(cls, data: Dict[str, Any], _) -> Dict[str, Any]: |
| 105 | + if waveform := data.pop("waveform", None): |
| 106 | + data["waveform"] = bytearray(base64.b64decode(waveform)) |
| 107 | + return data |
| 108 | + |
98 | 109 |
|
99 | 110 | @attrs.define(eq=False, order=False, hash=False, kw_only=True)
|
100 | 111 | class ChannelMention(DiscordObject):
|
@@ -369,6 +380,13 @@ def thread(self) -> "models.TYPE_THREAD_CHANNEL":
|
369 | 380 | """The thread that was started from this message, if any"""
|
370 | 381 | return self._client.cache.get_channel(self.id)
|
371 | 382 |
|
| 383 | + @property |
| 384 | + def editable(self) -> bool: |
| 385 | + """Whether this message can be edited by the current user""" |
| 386 | + if self.author.id == self._client.user.id: |
| 387 | + return MessageFlags.VOICE_MESSAGE not in self.flags |
| 388 | + return False |
| 389 | + |
372 | 390 | async def fetch_referenced_message(self, *, force: bool = False) -> Optional["Message"]:
|
373 | 391 | """
|
374 | 392 | Fetch the message this message is referencing, if any.
|
|
0 commit comments