Skip to content

Commit

Permalink
Merge branch 'master' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorukyum authored Jan 24, 2024
2 parents c459927 + 33d6543 commit 87e978e
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ These changes are available on the `master` branch, but have not yet been releas
- Added `default_reaction_emoji` parameter to `Guild.create_forum_channel()` and
`ForumChannel.edit()` methods.
([#2178](https://github.com/Pycord-Development/pycord/pull/2178))
- Added `applied_tags` parameter to `Webhook.send()` method.
([#2322](https://github.com/Pycord-Development/pycord/pull/2322))

### Changed

Expand Down Expand Up @@ -207,6 +209,10 @@ These changes are available on the `master` branch, but have not yet been releas
([#2301](https://github.com/Pycord-Development/pycord/pull/2301))
- Fixed `AttributeError` caused by `command.cog` being `MISSING`.
([#2303](https://github.com/Pycord-Development/pycord/issues/2303))
- Fixed `self.use_default_buttons` being assumed truthy by `Paginator.update`.
([#2319](https://github.com/Pycord-Development/pycord/pull/2319))
- Fixed `AttributeError` when comparing application commands with non-command objects.
([#2299](https://github.com/Pycord-Development/pycord/issues/2299))

## [2.4.1] - 2023-03-20

Expand Down
3 changes: 0 additions & 3 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ def add_application_command(self, command: ApplicationCommand) -> None:
if isinstance(command, SlashCommand) and command.is_subcommand:
raise TypeError("The provided command is a sub-command of group")

if command.cog is MISSING:
command._set_cog(None)

if self._bot.debug_guilds and command.guild_ids is None:
command.guild_ids = self._bot.debug_guilds

Expand Down
31 changes: 18 additions & 13 deletions discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,10 @@ def __repr__(self) -> str:
return f"<discord.commands.{self.__class__.__name__} name={self.name}>"

def __eq__(self, other) -> bool:
if (
getattr(self, "id", None) is not None
and getattr(other, "id", None) is not None
):
check = self.id == other.id
else:
check = self.name == other.name and self.guild_ids == other.guild_ids
return (
isinstance(other, self.__class__) and self.parent == other.parent and check
isinstance(other, self.__class__)
and self.qualified_name == other.qualified_name
and self.guild_ids == other.guild_ids
)

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

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

try:
checks = func.__commands_checks__
Expand All @@ -709,9 +705,9 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
def _validate_parameters(self):
params = self._get_signature_parameters()
if kwop := self.options:
self.options: list[Option] = self._match_option_param_names(params, kwop)
self.options = self._match_option_param_names(params, kwop)
else:
self.options: list[Option] = self._parse_options(params)
self.options = self._parse_options(params)

def _check_required_params(self, params):
params = iter(params.items())
Expand Down Expand Up @@ -849,9 +845,18 @@ def cog(self):
return getattr(self, "_cog", None)

@cog.setter
def cog(self, val):
self._cog = val
self._validate_parameters()
def cog(self, value):
old_cog = self.cog
self._cog = value

if (
old_cog is None
and value is not None
or value is None
and old_cog is not None
):
params = self._get_signature_parameters()
self.options = self._parse_options(params)

@property
def is_subcommand(self) -> bool:
Expand Down
32 changes: 20 additions & 12 deletions discord/ext/pages/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,18 +560,20 @@ async def update(
self.loop_pages = loop_pages if loop_pages is not None else self.loop_pages
self.custom_view: discord.ui.View = None if custom_view is None else custom_view
self.timeout: float = timeout if timeout is not None else self.timeout
self.custom_buttons = (
custom_buttons if custom_buttons is not None else self.custom_buttons
)
self.trigger_on_display = (
trigger_on_display
if trigger_on_display is not None
else self.trigger_on_display
)
if custom_buttons and not self.use_default_buttons:
self.buttons = {}
for button in custom_buttons:
self.add_button(button)
else:
self.buttons = {}
self.buttons = {}
if self.use_default_buttons:
self.add_default_buttons()
elif self.custom_buttons:
for button in self.custom_buttons:
self.add_button(button)

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

Expand Down Expand Up @@ -679,9 +681,12 @@ async def goto_page(
self.update_buttons()
self.current_page = page_number
if self.show_indicator:
self.buttons["page_indicator"][
"object"
].label = f"{self.current_page + 1}/{self.page_count + 1}"
try:
self.buttons["page_indicator"][
"object"
].label = f"{self.current_page + 1}/{self.page_count + 1}"
except KeyError:
pass

page = self.pages[page_number]
page = self.get_page_content(page)
Expand Down Expand Up @@ -843,9 +848,12 @@ def update_buttons(self) -> dict:
button["object"].label = button["label"]
self.clear_items()
if self.show_indicator:
self.buttons["page_indicator"][
"object"
].label = f"{self.current_page + 1}/{self.page_count + 1}"
try:
self.buttons["page_indicator"][
"object"
].label = f"{self.current_page + 1}/{self.page_count + 1}"
except KeyError:
pass
for key, button in self.buttons.items():
if key != "page_indicator":
if button["hidden"]:
Expand Down
18 changes: 17 additions & 1 deletion discord/webhook/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ def handle_message_parameters(
embed: Embed | None = MISSING,
embeds: list[Embed] = MISSING,
view: View | None = MISSING,
applied_tags: list[Snowflake] = MISSING,
allowed_mentions: AllowedMentions | None = MISSING,
previous_allowed_mentions: AllowedMentions | None = None,
suppress: bool = False,
Expand Down Expand Up @@ -654,6 +655,9 @@ def handle_message_parameters(
flags = MessageFlags(suppress_embeds=suppress, ephemeral=ephemeral)
payload["flags"] = flags.value

if applied_tags is not MISSING:
payload["applied_tags"] = applied_tags

if allowed_mentions:
if previous_allowed_mentions is not None:
payload["allowed_mentions"] = previous_allowed_mentions.merge(
Expand Down Expand Up @@ -1566,6 +1570,7 @@ async def send(
view: View = MISSING,
thread: Snowflake = MISSING,
thread_name: str | None = None,
applied_tags: list[Snowflake] = MISSING,
wait: Literal[True],
delete_after: float = None,
) -> WebhookMessage:
Expand All @@ -1588,6 +1593,7 @@ async def send(
view: View = MISSING,
thread: Snowflake = MISSING,
thread_name: str | None = None,
applied_tags: list[Snowflake] = MISSING,
wait: Literal[False] = ...,
delete_after: float = None,
) -> None:
Expand All @@ -1609,6 +1615,7 @@ async def send(
view: View = MISSING,
thread: Snowflake = MISSING,
thread_name: str | None = None,
applied_tags: list[Snowflake] = MISSING,
wait: bool = False,
delete_after: float = None,
) -> WebhookMessage | None:
Expand Down Expand Up @@ -1680,6 +1687,10 @@ async def send(
The name of the thread to create. Only works for forum channels.
.. versionadded:: 2.0
applied_tags: List[:class:`Snowflake`]
A list of tags to apply to the message. Only works for threads.
.. versionadded:: 2.5
delete_after: :class:`float`
If provided, the number of seconds to wait in the background
before deleting the message we just sent.
Expand All @@ -1704,7 +1715,8 @@ async def send(
InvalidArgument
Either there was no token associated with this webhook, ``ephemeral`` was passed
with the improper webhook type, there was no state attached with this webhook when
giving it a view, or you specified both ``thread_name`` and ``thread``.
giving it a view, you specified both ``thread_name`` and ``thread``, or ``applied_tags``
was passed with neither ``thread_name`` nor ``thread`` specified.
"""

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

if applied_tags and not (thread or thread_name):
raise InvalidArgument("You cannot specify applied_tags without a thread")

application_webhook = self.type is WebhookType.application
if ephemeral and not application_webhook:
raise InvalidArgument(
Expand Down Expand Up @@ -1749,6 +1764,7 @@ async def send(
embeds=embeds,
ephemeral=ephemeral,
view=view,
applied_tags=applied_tags,
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions,
)
Expand Down
2 changes: 1 addition & 1 deletion requirements/_.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
aiohttp>=3.6.0,<3.10.0
aiohttp>=3.6.0,<4.0
typing_extensions>=4,<5; python_version < "3.11"
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ mypy~=1.8.0
coverage~=7.4
pre-commit==3.5.0
codespell==2.2.6
bandit==1.7.6
bandit==1.7.7
flake8==7.0.0
2 changes: 1 addition & 1 deletion requirements/speed.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
msgspec~=0.18.5
msgspec~=0.18.6
aiohttp[speedups]

0 comments on commit 87e978e

Please sign in to comment.