Skip to content

Commit 5610dd8

Browse files
authored
Merge branch 'Pycord-Development:master' into master
2 parents 9cda058 + 60097c5 commit 5610dd8

File tree

11 files changed

+88
-40
lines changed

11 files changed

+88
-40
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ repos:
2424
- id: pyupgrade
2525
args: [--py38-plus]
2626
- repo: https://github.com/PyCQA/isort
27-
rev: 5.13.0
27+
rev: 5.13.2
2828
hooks:
2929
- id: isort
3030
- repo: https://github.com/psf/black
31-
rev: 23.11.0
31+
rev: 23.12.1
3232
hooks:
3333
- id: black
3434
args: [--safe, --quiet]
@@ -77,7 +77,7 @@ repos:
7777
# - id: mypy
7878

7979
- repo: https://github.com/pre-commit/mirrors-prettier
80-
rev: v4.0.0-alpha.4
80+
rev: v4.0.0-alpha.8
8181
hooks:
8282
- id: prettier
8383
args: [--prose-wrap=always, --print-width=88]

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ These changes are available on the `master` branch, but have not yet been releas
8282
- Added `default_reaction_emoji` parameter to `Guild.create_forum_channel()` and
8383
`ForumChannel.edit()` methods.
8484
([#2178](https://github.com/Pycord-Development/pycord/pull/2178))
85+
- Added `applied_tags` parameter to `Webhook.send()` method.
86+
([#2322](https://github.com/Pycord-Development/pycord/pull/2322))
8587

8688
### Changed
8789

@@ -113,6 +115,8 @@ These changes are available on the `master` branch, but have not yet been releas
113115
([#2099](https://github.com/Pycord-Development/pycord/pull/2099))
114116
- Changed the support from `orjson` to `msgspec` in the codebase.
115117
([#2170](https://github.com/Pycord-Development/pycord/pull/2170))
118+
- `BridgeOption` must now be used for arguments in bridge commands.
119+
([#2252](https://github.com/Pycord-Development/pycord/pull/2252))
116120

117121
### Removed
118122

@@ -207,6 +211,12 @@ These changes are available on the `master` branch, but have not yet been releas
207211
([#2301](https://github.com/Pycord-Development/pycord/pull/2301))
208212
- Fixed `AttributeError` caused by `command.cog` being `MISSING`.
209213
([#2303](https://github.com/Pycord-Development/pycord/issues/2303))
214+
- Fixed `self.use_default_buttons` being assumed truthy by `Paginator.update`.
215+
([#2319](https://github.com/Pycord-Development/pycord/pull/2319))
216+
- Fixed `AttributeError` when comparing application commands with non-command objects.
217+
([#2299](https://github.com/Pycord-Development/pycord/issues/2299))
218+
- Fixed `AttributeError` when copying groups on startup.
219+
([#2331](https://github.com/Pycord-Development/pycord/issues/2331))
210220

211221
## [2.4.1] - 2023-03-20
212222

discord/bot.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ def add_application_command(self, command: ApplicationCommand) -> None:
123123
if isinstance(command, SlashCommand) and command.is_subcommand:
124124
raise TypeError("The provided command is a sub-command of group")
125125

126-
if command.cog is MISSING:
127-
command._set_cog(None)
128-
129126
if self._bot.debug_guilds and command.guild_ids is None:
130127
command.guild_ids = self._bot.debug_guilds
131128

discord/commands/core.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,10 @@ def __repr__(self) -> str:
235235
return f"<discord.commands.{self.__class__.__name__} name={self.name}>"
236236

237237
def __eq__(self, other) -> bool:
238-
if (
239-
getattr(self, "id", None) is not None
240-
and getattr(other, "id", None) is not None
241-
):
242-
check = self.id == other.id
243-
else:
244-
check = self.name == other.name and self.guild_ids == other.guild_ids
245238
return (
246-
isinstance(other, self.__class__) and self.parent == other.parent and check
239+
isinstance(other, self.__class__)
240+
and self.qualified_name == other.qualified_name
241+
and self.guild_ids == other.guild_ids
247242
)
248243

249244
async def __call__(self, ctx, *args, **kwargs):
@@ -694,6 +689,7 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
694689
self.attached_to_group: bool = False
695690

696691
self.options: list[Option] = kwargs.get("options", [])
692+
self._validate_parameters()
697693

698694
try:
699695
checks = func.__commands_checks__
@@ -709,9 +705,9 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
709705
def _validate_parameters(self):
710706
params = self._get_signature_parameters()
711707
if kwop := self.options:
712-
self.options: list[Option] = self._match_option_param_names(params, kwop)
708+
self.options = self._match_option_param_names(params, kwop)
713709
else:
714-
self.options: list[Option] = self._parse_options(params)
710+
self.options = self._parse_options(params)
715711

716712
def _check_required_params(self, params):
717713
params = iter(params.items())
@@ -849,9 +845,18 @@ def cog(self):
849845
return getattr(self, "_cog", None)
850846

851847
@cog.setter
852-
def cog(self, val):
853-
self._cog = val
854-
self._validate_parameters()
848+
def cog(self, value):
849+
old_cog = self.cog
850+
self._cog = value
851+
852+
if (
853+
old_cog is None
854+
and value is not None
855+
or value is None
856+
and old_cog is not None
857+
):
858+
params = self._get_signature_parameters()
859+
self.options = self._parse_options(params)
855860

856861
@property
857862
def is_subcommand(self) -> bool:
@@ -1439,7 +1444,7 @@ def _update_copy(self, kwargs: dict[str, Any]):
14391444
if kwargs:
14401445
kw = kwargs.copy()
14411446
kw.update(self.__original_kwargs__)
1442-
copy = self.__class__(self.callback, **kw)
1447+
copy = self.__class__(**kw)
14431448
return self._ensure_assignment_on_copy(copy)
14441449
else:
14451450
return self.copy()

discord/ext/bridge/core.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"BridgeSlashCommand",
6767
"BridgeExtGroup",
6868
"BridgeSlashGroup",
69+
"BridgeOption",
6970
"map_to",
7071
"guild_only",
7172
"has_permissions",
@@ -591,6 +592,10 @@ async def convert(self, ctx, arg: bool):
591592

592593

593594
class BridgeOption(Option, Converter):
595+
"""A subclass of :class:`discord.Option` which represents a selectable slash
596+
command option and a prefixed command argument for bridge commands.
597+
"""
598+
594599
async def convert(self, ctx, argument: str) -> Any:
595600
try:
596601
if self.converter is not None:
@@ -621,7 +626,3 @@ async def convert(self, ctx, argument: str) -> Any:
621626
return converted
622627
except ValueError as exc:
623628
raise BadArgument() from exc
624-
625-
626-
discord.commands.options.Option = BridgeOption
627-
discord.Option = BridgeOption

discord/ext/pages/pagination.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -560,18 +560,20 @@ async def update(
560560
self.loop_pages = loop_pages if loop_pages is not None else self.loop_pages
561561
self.custom_view: discord.ui.View = None if custom_view is None else custom_view
562562
self.timeout: float = timeout if timeout is not None else self.timeout
563+
self.custom_buttons = (
564+
custom_buttons if custom_buttons is not None else self.custom_buttons
565+
)
563566
self.trigger_on_display = (
564567
trigger_on_display
565568
if trigger_on_display is not None
566569
else self.trigger_on_display
567570
)
568-
if custom_buttons and not self.use_default_buttons:
569-
self.buttons = {}
570-
for button in custom_buttons:
571-
self.add_button(button)
572-
else:
573-
self.buttons = {}
571+
self.buttons = {}
572+
if self.use_default_buttons:
574573
self.add_default_buttons()
574+
elif self.custom_buttons:
575+
for button in self.custom_buttons:
576+
self.add_button(button)
575577

576578
await self.goto_page(self.current_page, interaction=interaction)
577579

@@ -679,9 +681,12 @@ async def goto_page(
679681
self.update_buttons()
680682
self.current_page = page_number
681683
if self.show_indicator:
682-
self.buttons["page_indicator"][
683-
"object"
684-
].label = f"{self.current_page + 1}/{self.page_count + 1}"
684+
try:
685+
self.buttons["page_indicator"][
686+
"object"
687+
].label = f"{self.current_page + 1}/{self.page_count + 1}"
688+
except KeyError:
689+
pass
685690

686691
page = self.pages[page_number]
687692
page = self.get_page_content(page)
@@ -843,9 +848,12 @@ def update_buttons(self) -> dict:
843848
button["object"].label = button["label"]
844849
self.clear_items()
845850
if self.show_indicator:
846-
self.buttons["page_indicator"][
847-
"object"
848-
].label = f"{self.current_page + 1}/{self.page_count + 1}"
851+
try:
852+
self.buttons["page_indicator"][
853+
"object"
854+
].label = f"{self.current_page + 1}/{self.page_count + 1}"
855+
except KeyError:
856+
pass
849857
for key, button in self.buttons.items():
850858
if key != "page_indicator":
851859
if button["hidden"]:

discord/webhook/async_.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ def handle_message_parameters(
621621
embed: Embed | None = MISSING,
622622
embeds: list[Embed] = MISSING,
623623
view: View | None = MISSING,
624+
applied_tags: list[Snowflake] = MISSING,
624625
allowed_mentions: AllowedMentions | None = MISSING,
625626
previous_allowed_mentions: AllowedMentions | None = None,
626627
suppress: bool = False,
@@ -654,6 +655,9 @@ def handle_message_parameters(
654655
flags = MessageFlags(suppress_embeds=suppress, ephemeral=ephemeral)
655656
payload["flags"] = flags.value
656657

658+
if applied_tags is not MISSING:
659+
payload["applied_tags"] = applied_tags
660+
657661
if allowed_mentions:
658662
if previous_allowed_mentions is not None:
659663
payload["allowed_mentions"] = previous_allowed_mentions.merge(
@@ -1566,6 +1570,7 @@ async def send(
15661570
view: View = MISSING,
15671571
thread: Snowflake = MISSING,
15681572
thread_name: str | None = None,
1573+
applied_tags: list[Snowflake] = MISSING,
15691574
wait: Literal[True],
15701575
delete_after: float = None,
15711576
) -> WebhookMessage:
@@ -1588,6 +1593,7 @@ async def send(
15881593
view: View = MISSING,
15891594
thread: Snowflake = MISSING,
15901595
thread_name: str | None = None,
1596+
applied_tags: list[Snowflake] = MISSING,
15911597
wait: Literal[False] = ...,
15921598
delete_after: float = None,
15931599
) -> None:
@@ -1609,6 +1615,7 @@ async def send(
16091615
view: View = MISSING,
16101616
thread: Snowflake = MISSING,
16111617
thread_name: str | None = None,
1618+
applied_tags: list[Snowflake] = MISSING,
16121619
wait: bool = False,
16131620
delete_after: float = None,
16141621
) -> WebhookMessage | None:
@@ -1680,6 +1687,10 @@ async def send(
16801687
The name of the thread to create. Only works for forum channels.
16811688
16821689
.. versionadded:: 2.0
1690+
applied_tags: List[:class:`Snowflake`]
1691+
A list of tags to apply to the message. Only works for threads.
1692+
1693+
.. versionadded:: 2.5
16831694
delete_after: :class:`float`
16841695
If provided, the number of seconds to wait in the background
16851696
before deleting the message we just sent.
@@ -1704,7 +1715,8 @@ async def send(
17041715
InvalidArgument
17051716
Either there was no token associated with this webhook, ``ephemeral`` was passed
17061717
with the improper webhook type, there was no state attached with this webhook when
1707-
giving it a view, or you specified both ``thread_name`` and ``thread``.
1718+
giving it a view, you specified both ``thread_name`` and ``thread``, or ``applied_tags``
1719+
was passed with neither ``thread_name`` nor ``thread`` specified.
17081720
"""
17091721

17101722
if self.token is None:
@@ -1721,6 +1733,9 @@ async def send(
17211733
if thread and thread_name:
17221734
raise InvalidArgument("You cannot specify both a thread and thread_name")
17231735

1736+
if applied_tags and not (thread or thread_name):
1737+
raise InvalidArgument("You cannot specify applied_tags without a thread")
1738+
17241739
application_webhook = self.type is WebhookType.application
17251740
if ephemeral and not application_webhook:
17261741
raise InvalidArgument(
@@ -1749,6 +1764,7 @@ async def send(
17491764
embeds=embeds,
17501765
ephemeral=ephemeral,
17511766
view=view,
1767+
applied_tags=applied_tags,
17521768
allowed_mentions=allowed_mentions,
17531769
previous_allowed_mentions=previous_mentions,
17541770
)

docs/ext/bridge/api.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,14 @@ BridgeContext Subclasses
157157
.. data:: discord.ext.bridge.Context
158158

159159
Alias of :data:`typing.Union` [ :class:`.BridgeExtContext`, :class:`.BridgeApplicationContext` ] for typing convenience.
160+
161+
Option
162+
------
163+
164+
BridgeOption
165+
~~~~~~~~~~~~
166+
167+
.. attributetable:: discord.ext.bridge.BridgeOption
168+
169+
.. autoclass:: discord.ext.bridge.BridgeOption
170+
:members:

requirements/_.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
aiohttp>=3.6.0,<3.10.0
1+
aiohttp>=3.6.0,<4.0
22
typing_extensions>=4,<5; python_version < "3.11"

requirements/dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ mypy~=1.8.0
77
coverage~=7.4
88
pre-commit==3.5.0
99
codespell==2.2.6
10-
bandit==1.7.6
10+
bandit==1.7.7
1111
flake8==7.0.0

0 commit comments

Comments
 (0)