Skip to content

Commit e61f568

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master' into feat-guild-user-activity-flag
# Conflicts: # CHANGELOG.md
2 parents 9cb74b2 + f0c8e53 commit e61f568

38 files changed

+310
-130
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ These changes are available on the `master` branch, but have not yet been releas
3636
`Permissions.use_external_sounds`, and
3737
`Permissions.view_creator_monetization_analytics`.
3838
([#2620](https://github.com/Pycord-Development/pycord/pull/2620))
39+
- Added `Message._raw_data` attribute.
40+
([#2670](https://github.com/Pycord-Development/pycord/pull/2670))
41+
- Added helper methods to determine the authorizing party of an `Interaction`.
42+
([#2659](https://github.com/Pycord-Development/pycord/pull/2659))
43+
- Added `VoiceMessage` subclass of `File` to allow voice messages to be sent.
44+
([#2579](https://github.com/Pycord-Development/pycord/pull/2579))
3945
- Add missing `Guild` feature flags and `Guild.edit` parameters.
4046
([#2672](https://github.com/Pycord-Development/pycord/pull/2672))
4147

@@ -66,6 +72,12 @@ These changes are available on the `master` branch, but have not yet been releas
6672
apps. ([#2650](https://github.com/Pycord-Development/pycord/pull/2650))
6773
- Fixed type annotations of cached properties.
6874
([#2635](https://github.com/Pycord-Development/pycord/issues/2635))
75+
- Fixed an error when responding non-ephemerally with a `Paginator` to an ephemerally
76+
deferred interaction.
77+
([#2661](https://github.com/Pycord-Development/pycord/pull/2661))
78+
- Fixed attachment metadata being set incorrectly in interaction responses causing the
79+
metadata to be ignored by Discord.
80+
([#2679](https://github.com/Pycord-Development/pycord/pull/2679))
6981

7082
### Changed
7183

@@ -79,7 +91,7 @@ These changes are available on the `master` branch, but have not yet been releas
7991
- Replaced audioop (deprecated module) implementation of `PCMVolumeTransformer.read`
8092
method with a pure Python equivalent.
8193
([#2176](https://github.com/Pycord-Development/pycord/pull/2176))
82-
- Updated `Guild.filesize_limit` to 10 Mb instead of 25 Mb following Discord's API
94+
- Updated `Guild.filesize_limit` to 10 MB instead of 25 MB following Discord's API
8395
changes. ([#2671](https://github.com/Pycord-Development/pycord/pull/2671))
8496

8597
### Deprecated

discord/_typed_dict.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

discord/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import warnings
3131
from importlib.metadata import PackageNotFoundError, version
3232

33-
from ._typed_dict import TypedDict
33+
from typing_extensions import TypedDict
3434

3535
__all__ = ("__version__", "VersionInfo", "version_info")
3636

discord/abc.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from .context_managers import Typing
4646
from .enums import ChannelType
4747
from .errors import ClientException, InvalidArgument
48-
from .file import File
48+
from .file import File, VoiceMessage
4949
from .flags import MessageFlags
5050
from .invite import Invite
5151
from .iterators import HistoryIterator
@@ -1569,7 +1569,7 @@ async def send(
15691569
flags = MessageFlags(
15701570
suppress_embeds=bool(suppress),
15711571
suppress_notifications=bool(silent),
1572-
).value
1572+
)
15731573

15741574
if stickers is not None:
15751575
stickers = [sticker.id for sticker in stickers]
@@ -1615,27 +1615,7 @@ async def send(
16151615
if file is not None:
16161616
if not isinstance(file, File):
16171617
raise InvalidArgument("file parameter must be File")
1618-
1619-
try:
1620-
data = await state.http.send_files(
1621-
channel.id,
1622-
files=[file],
1623-
allowed_mentions=allowed_mentions,
1624-
content=content,
1625-
tts=tts,
1626-
embed=embed,
1627-
embeds=embeds,
1628-
nonce=nonce,
1629-
enforce_nonce=enforce_nonce,
1630-
message_reference=reference,
1631-
stickers=stickers,
1632-
components=components,
1633-
flags=flags,
1634-
poll=poll,
1635-
)
1636-
finally:
1637-
file.close()
1638-
1618+
files = [file]
16391619
elif files is not None:
16401620
if len(files) > 10:
16411621
raise InvalidArgument(
@@ -1644,6 +1624,10 @@ async def send(
16441624
elif not all(isinstance(file, File) for file in files):
16451625
raise InvalidArgument("files parameter must be a list of File")
16461626

1627+
if files is not None:
1628+
flags = flags + MessageFlags(
1629+
is_voice_message=any(isinstance(f, VoiceMessage) for f in files)
1630+
)
16471631
try:
16481632
data = await state.http.send_files(
16491633
channel.id,
@@ -1658,7 +1642,7 @@ async def send(
16581642
message_reference=reference,
16591643
stickers=stickers,
16601644
components=components,
1661-
flags=flags,
1645+
flags=flags.value,
16621646
poll=poll,
16631647
)
16641648
finally:
@@ -1677,7 +1661,7 @@ async def send(
16771661
message_reference=reference,
16781662
stickers=stickers,
16791663
components=components,
1680-
flags=flags,
1664+
flags=flags.value,
16811665
poll=poll,
16821666
)
16831667

discord/commands/context.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,40 @@ def cog(self) -> Cog | None:
345345

346346
return self.command.cog
347347

348+
def is_guild_authorised(self) -> bool:
349+
""":class:`bool`: Checks if the invoked command is guild-installed.
350+
This is a shortcut for :meth:`Interaction.is_guild_authorised`.
351+
352+
There is an alias for this called :meth:`.is_guild_authorized`.
353+
354+
.. versionadded:: 2.7
355+
"""
356+
return self.interaction.is_guild_authorised()
357+
358+
def is_user_authorised(self) -> bool:
359+
""":class:`bool`: Checks if the invoked command is user-installed.
360+
This is a shortcut for :meth:`Interaction.is_user_authorised`.
361+
362+
There is an alias for this called :meth:`.is_user_authorized`.
363+
364+
.. versionadded:: 2.7
365+
"""
366+
return self.interaction.is_user_authorised()
367+
368+
def is_guild_authorized(self) -> bool:
369+
""":class:`bool`: An alias for :meth:`.is_guild_authorised`.
370+
371+
.. versionadded:: 2.7
372+
"""
373+
return self.is_guild_authorised()
374+
375+
def is_user_authorized(self) -> bool:
376+
""":class:`bool`: An alias for :meth:`.is_user_authorised`.
377+
378+
.. versionadded:: 2.7
379+
"""
380+
return self.is_user_authorised()
381+
348382

349383
class AutocompleteContext:
350384
"""Represents context for a slash command's option autocomplete.

discord/ext/pages/pagination.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ async def respond(
12021202
)
12031203
# convert from WebhookMessage to Message reference to bypass
12041204
# 15min webhook token timeout (non-ephemeral messages only)
1205-
if not ephemeral:
1205+
if not ephemeral and not msg.flags.ephemeral:
12061206
msg = await msg.channel.fetch_message(msg.id)
12071207
else:
12081208
msg = await interaction.response.send_message(

discord/file.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
import os
3030
from typing import TYPE_CHECKING
3131

32-
__all__ = ("File",)
32+
__all__ = (
33+
"File",
34+
"VoiceMessage",
35+
)
3336

3437

3538
class File:
@@ -89,6 +92,7 @@ def __init__(
8992
description: str | None = None,
9093
spoiler: bool = False,
9194
):
95+
9296
if isinstance(fp, io.IOBase):
9397
if not (fp.seekable() and fp.readable()):
9498
raise ValueError(f"File buffer {fp!r} must be seekable and readable")
@@ -143,3 +147,60 @@ def close(self) -> None:
143147
self.fp.close = self._closer
144148
if self._owner:
145149
self._closer()
150+
151+
152+
class VoiceMessage(File):
153+
"""A special case of the File class that represents a voice message.
154+
155+
.. versionadded:: 2.7
156+
157+
.. note::
158+
159+
Similar to File objects, VoiceMessage objects are single use and are not meant to be reused in
160+
multiple requests.
161+
162+
Attributes
163+
----------
164+
fp: Union[:class:`os.PathLike`, :class:`io.BufferedIOBase`]
165+
A audio file-like object opened in binary mode and read mode
166+
or a filename representing a file in the hard drive to
167+
open.
168+
169+
.. note::
170+
171+
If the file-like object passed is opened via ``open`` then the
172+
modes 'rb' should be used.
173+
174+
To pass binary data, consider usage of ``io.BytesIO``.
175+
176+
filename: Optional[:class:`str`]
177+
The filename to display when uploading to Discord.
178+
If this is not given then it defaults to ``fp.name`` or if ``fp`` is
179+
a string then the ``filename`` will default to the string given.
180+
description: Optional[:class:`str`]
181+
The description of a file, used by Discord to display alternative text on images.
182+
spoiler: :class:`bool`
183+
Whether the attachment is a spoiler.
184+
waveform: Optional[:class:`str`]
185+
The base64 encoded bytearray representing a sampled waveform.
186+
duration_secs: Optional[:class:`float`]
187+
The duration of the voice message.
188+
"""
189+
190+
__slots__ = (
191+
"waveform",
192+
"duration_secs",
193+
)
194+
195+
def __init__(
196+
self,
197+
fp: str | bytes | os.PathLike | io.BufferedIOBase,
198+
filename: str | None = None,
199+
*,
200+
waveform: str = "",
201+
duration_secs: float = 0.0,
202+
**kwargs,
203+
):
204+
super().__init__(fp, filename, **kwargs)
205+
self.waveform = waveform
206+
self.duration_secs = duration_secs

discord/http.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
LoginFailure,
4545
NotFound,
4646
)
47+
from .file import VoiceMessage
4748
from .gateway import DiscordClientWebSocketResponse
4849
from .utils import MISSING, warn_deprecated
4950

@@ -567,13 +568,17 @@ def send_multipart_helper(
567568
attachments = []
568569
form.append({"name": "payload_json"})
569570
for index, file in enumerate(files):
570-
attachments.append(
571-
{
572-
"id": index,
573-
"filename": file.filename,
574-
"description": file.description,
575-
}
576-
)
571+
attachment_info = {
572+
"id": index,
573+
"filename": file.filename,
574+
"description": file.description,
575+
}
576+
if isinstance(file, VoiceMessage):
577+
attachment_info.update(
578+
waveform=file.waveform,
579+
duration_secs=file.duration_secs,
580+
)
581+
attachments.append(attachment_info)
577582
form.append(
578583
{
579584
"name": f"files[{index}]",
@@ -633,13 +638,17 @@ def edit_multipart_helper(
633638
attachments = []
634639
form.append({"name": "payload_json"})
635640
for index, file in enumerate(files):
636-
attachments.append(
637-
{
638-
"id": index,
639-
"filename": file.filename,
640-
"description": file.description,
641-
}
642-
)
641+
attachment_info = {
642+
"id": index,
643+
"filename": file.filename,
644+
"description": file.description,
645+
}
646+
if isinstance(file, VoiceMessage):
647+
attachment_info.update(
648+
waveform=file.waveform,
649+
duration_secs=file.duration_secs,
650+
)
651+
attachments.append(attachment_info)
643652
form.append(
644653
{
645654
"name": f"files[{index}]",

0 commit comments

Comments
 (0)