Skip to content

Commit 3d2bb4b

Browse files
authored
Merge branch 'master' into typed-dict
2 parents 9e136be + 51b8dae commit 3d2bb4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4587
-4393
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
# - --remove-duplicate-keys
2222
# - --remove-unused-variables
2323
- repo: https://github.com/asottile/pyupgrade
24-
rev: v3.19.0
24+
rev: v3.19.1
2525
hooks:
2626
- id: pyupgrade
2727
exclude: \.(po|pot|yml|yaml)$

CHANGELOG.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ These changes are available on the `master` branch, but have not yet been releas
3232
([#2590](https://github.com/Pycord-Development/pycord/pull/2590))
3333
- Added missing `with_counts` parameter to `fetch_guilds` method.
3434
([#2615](https://github.com/Pycord-Development/pycord/pull/2615))
35-
- Added missing permissions: `Permissions.use_soundboard`,
36-
`Permissions.use_external_sounds` and
35+
- Added the following missing permissions: `Permissions.use_soundboard`,
36+
`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

4046
### Fixed
4147

@@ -54,14 +60,22 @@ These changes are available on the `master` branch, but have not yet been releas
5460
([#2595](https://github.com/Pycord-Development/pycord/pull/2595))
5561
- Fixed `BucketType.category` cooldown commands not functioning correctly in private
5662
channels. ([#2603](https://github.com/Pycord-Development/pycord/pull/2603))
57-
- Fixed `SlashCommand`'s `ctx` parameter couldn't be `Union` type.
63+
- Fixed `ctx` parameter of a `SlashCommand` not being `Union` type.
5864
([#2611](https://github.com/Pycord-Development/pycord/pull/2611))
5965
- Fixed `TypeError` when passing `skus` parameter in `Client.entitlements()`.
6066
([#2627](https://github.com/Pycord-Development/pycord/issues/2627))
6167
- Fixed `AttributeError` when sending polls with `PartialWebook`.
6268
([#2624](https://github.com/Pycord-Development/pycord/pull/2624))
6369
- Fixed `AttributeError` when accessing `Member.guild_permissions` for user installed
6470
apps. ([#2650](https://github.com/Pycord-Development/pycord/pull/2650))
71+
- Fixed type annotations of cached properties.
72+
([#2635](https://github.com/Pycord-Development/pycord/issues/2635))
73+
- Fixed an error when responding non-ephemerally with a `Paginator` to an ephemerally
74+
deferred interaction.
75+
([#2661](https://github.com/Pycord-Development/pycord/pull/2661))
76+
- Fixed attachment metadata being set incorrectly in interaction responses causing the
77+
metadata to be ignored by Discord.
78+
([#2679](https://github.com/Pycord-Development/pycord/pull/2679))
6579

6680
### Changed
6781

@@ -75,6 +89,8 @@ These changes are available on the `master` branch, but have not yet been releas
7589
- Replaced audioop (deprecated module) implementation of `PCMVolumeTransformer.read`
7690
method with a pure Python equivalent.
7791
([#2176](https://github.com/Pycord-Development/pycord/pull/2176))
92+
- Updated `Guild.filesize_limit` to 10 MB instead of 25 MB following Discord's API
93+
changes. ([#2671](https://github.com/Pycord-Development/pycord/pull/2671))
7894

7995
### Deprecated
8096

@@ -388,7 +404,7 @@ These changes are available on the `master` branch, but have not yet been releas
388404
([#2075](https://github.com/Pycord-Development/pycord/pull/2075))
389405
- Fixed `before_invoke` not being run for `SlashCommandGroup`.
390406
([#2091](https://github.com/Pycord-Development/pycord/pull/2091))
391-
- Fixed `AttributeError` when accessing a `Select` object's values when it hasn't been
407+
- Fixed `AttributeError` when accessing a `Select` object's values when it has not been
392408
interacted with. ([#2104](https://github.com/Pycord-Development/pycord/pull/2104))
393409
- Fixed `before_invoke` being run twice for slash subcommands.
394410
([#2139](https://github.com/Pycord-Development/pycord/pull/2139))
@@ -419,7 +435,7 @@ These changes are available on the `master` branch, but have not yet been releas
419435
([#2196](https://github.com/Pycord-Development/pycord/pull/2196))
420436
- Fixed `AttributeError` when running permission checks without the `bot` scope.
421437
([#2113](https://github.com/Pycord-Development/pycord/issues/2113))
422-
- Fixed `Option` not working on bridge commands because `ext.commands.Command` doesn't
438+
- Fixed `Option` not working on bridge commands because `ext.commands.Command` does not
423439
recognize them. ([#2256](https://github.com/Pycord-Development/pycord/pull/2256))
424440
- Fixed offset-aware tasks causing `TypeError` when being prepared.
425441
([#2271](https://github.com/Pycord-Development/pycord/pull/2271))
@@ -519,7 +535,7 @@ These changes are available on the `master` branch, but have not yet been releas
519535
### Fixed
520536

521537
- Fixed bugs in `Page.update_files` where file objects stored in memory were causing an
522-
`AttributeError`, and `io.BytesIO` files didn't send properly more than once.
538+
`AttributeError`, and `io.BytesIO` files did not send properly more than once.
523539
([#1869](https://github.com/Pycord-Development/pycord/pull/1869) &
524540
[#1881](https://github.com/Pycord-Development/pycord/pull/1881))
525541
- Fixed bridge groups missing the `parent` attribute.
@@ -874,9 +890,9 @@ These changes are available on the `master` branch, but have not yet been releas
874890
([#1453](https://github.com/Pycord-Development/pycord/pull/1453))
875891
- Update `thread.members` on `thread.fetch_members`.
876892
([#1464](https://github.com/Pycord-Development/pycord/pull/1464))
877-
- Fix the error when Discord doesn't send the `app_permissions` data in `Interaction`.
893+
- Fix the error when Discord does not send the `app_permissions` data in `Interaction`.
878894
([#1467](https://github.com/Pycord-Development/pycord/pull/1467))
879-
- Fix AttributeError when voice client `play()` function isn't completed yet.
895+
- Fix AttributeError when voice client `play()` function is not completed yet.
880896
([#1360](https://github.com/Pycord-Development/pycord/pull/1360))
881897

882898
## [2.0.0-rc.1] - 2022-05-17

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/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ def _handle_ready(self) -> None:
310310

311311
@property
312312
def latency(self) -> float:
313-
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds.
313+
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds. If no websocket
314+
is present, this returns ``nan``, and if no heartbeat has been received yet, this returns ``float('inf')``.
314315
315316
This could be referred to as the Discord WebSocket protocol latency.
316317
"""

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/gateway.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,9 @@ async def received_message(self, msg, /):
581581

582582
@property
583583
def latency(self) -> float:
584-
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds."""
584+
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds. If no heartbeat
585+
has been received yet this returns ``float('inf')``.
586+
"""
585587
heartbeat = self._keep_alive
586588
return float("inf") if heartbeat is None else heartbeat.latency
587589

discord/guild.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,11 @@ class Guild(Hashable):
289289
)
290290

291291
_PREMIUM_GUILD_LIMITS: ClassVar[dict[int | None, _GuildLimit]] = {
292-
None: _GuildLimit(emoji=50, stickers=5, bitrate=96e3, filesize=26214400),
293-
0: _GuildLimit(emoji=50, stickers=5, bitrate=96e3, filesize=26214400),
294-
1: _GuildLimit(emoji=100, stickers=15, bitrate=128e3, filesize=26214400),
295-
2: _GuildLimit(emoji=150, stickers=30, bitrate=256e3, filesize=52428800),
296-
3: _GuildLimit(emoji=250, stickers=60, bitrate=384e3, filesize=104857600),
292+
None: _GuildLimit(emoji=50, stickers=5, bitrate=96e3, filesize=10_485_760),
293+
0: _GuildLimit(emoji=50, stickers=5, bitrate=96e3, filesize=10_485_760),
294+
1: _GuildLimit(emoji=100, stickers=15, bitrate=128e3, filesize=10_485_760),
295+
2: _GuildLimit(emoji=150, stickers=30, bitrate=256e3, filesize=52_428_800),
296+
3: _GuildLimit(emoji=250, stickers=60, bitrate=384e3, filesize=104_857_600),
297297
}
298298

299299
def __init__(self, *, data: GuildPayload, state: ConnectionState):

0 commit comments

Comments
 (0)