Skip to content

Commit

Permalink
Merge branch 'Pycord-Development:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
plun1331 authored Dec 19, 2023
2 parents 7b11fba + 510a44b commit 66ef705
Show file tree
Hide file tree
Showing 24 changed files with 237 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
Expand All @@ -26,7 +26,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -56,7 +56,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -70,4 +70,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
Expand All @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: "pip"
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -19,16 +19,16 @@ repos:
# - --remove-duplicate-keys
# - --remove-unused-variables
- repo: https://github.com/asottile/pyupgrade
rev: v3.13.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.11.0
hooks:
- id: black
args: [--safe, --quiet]
Expand Down Expand Up @@ -77,7 +77,7 @@ repos:
# - id: mypy

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
rev: v4.0.0-alpha.4
hooks:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ These changes are available on the `master` branch, but have not yet been releas
([#2206](https://github.com/Pycord-Development/pycord/pull/2206))
- Added function `Guild.delete_auto_moderation_rule`.
([#2153](https://github.com/Pycord-Development/pycord/pull/2153))
- Added `VoiceChannel.slowmode_delay`.
([#2112](https://github.com/Pycord-Development/pycord/pull/2112))
- Added `ForumChannel.default_reaction_emoji` attribute.
([#2178](https://github.com/Pycord-Development/pycord/pull/2178))
- Added `default_reaction_emoji` parameter to `Guild.create_forum_channel()` and
`ForumChannel.edit()` methods.
([#2178](https://github.com/Pycord-Development/pycord/pull/2178))

### Changed

Expand Down Expand Up @@ -180,6 +187,20 @@ These changes are available on the `master` branch, but have not yet been releas
([#2192](https://github.com/Pycord-Development/pycord/pull/2192))
- Fixed `DMChannel.recipient` being `None` and consequently `User.dm_channel` also being
`None`. ([#2219](https://github.com/Pycord-Development/pycord/pull/2219))
- Fixed ffmpeg being terminated prematurely when piping audio stream.
([#2240](https://github.com/Pycord-Development/pycord/pull/2240))
- Fixed tasks looping infinitely when `tzinfo` is neither `None` nor UTC.
([#2196](https://github.com/Pycord-Development/pycord/pull/2196))
- Fixed `AttributeError` when running permission checks without the `bot` scope.
([#2113](https://github.com/Pycord-Development/pycord/issues/2113))
- Fixed `Option` not working on bridge commands because `ext.commands.Command` doesn't
recognize them. ([#2256](https://github.com/Pycord-Development/pycord/pull/2256))
- Fixed offset-aware tasks causing `TypeError` when being prepared.
([#2271](https://github.com/Pycord-Development/pycord/pull/2271))
- Fixed `AttributeError` when serializing commands with `Annotated` type hints.
([#2243](https://github.com/Pycord-Development/pycord/pull/2243))
- Fixed `Intents.all()` returning the wrong value.
([#2257](https://github.com/Pycord-Development/pycord/issues/2257))

## [2.4.1] - 2023-03-20

Expand Down
25 changes: 24 additions & 1 deletion discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from .invite import Invite
from .iterators import HistoryIterator
from .mentions import AllowedMentions
from .partial_emoji import PartialEmoji, _EmojiTag
from .permissions import PermissionOverwrite, Permissions
from .role import Role
from .scheduled_events import ScheduledEvent
Expand Down Expand Up @@ -507,6 +508,28 @@ async def _edit(
raise InvalidArgument("type field must be of type ChannelType")
options["type"] = ch_type.value

try:
default_reaction_emoji = options["default_reaction_emoji"]
except KeyError:
pass
else:
if isinstance(default_reaction_emoji, _EmojiTag): # Emoji, PartialEmoji
default_reaction_emoji = default_reaction_emoji._to_partial()
elif isinstance(default_reaction_emoji, int):
default_reaction_emoji = PartialEmoji(
name=None, id=default_reaction_emoji
)
elif isinstance(default_reaction_emoji, str):
default_reaction_emoji = PartialEmoji.from_str(default_reaction_emoji)
else:
raise InvalidArgument(
"default_reaction_emoji must be of type: Emoji | int | str"
)

options[
"default_reaction_emoji"
] = default_reaction_emoji._to_forum_reaction_payload()

if options:
return await self._state.http.edit_channel(
self.id, reason=reason, **options
Expand Down Expand Up @@ -712,7 +735,7 @@ def permissions_for(self, obj: Member | Role, /) -> Permissions:
return Permissions.all()

default = self.guild.default_role
base = Permissions(default.permissions.value)
base = Permissions(default.permissions.value if default else 0)

# Handle the role case first
if isinstance(obj, Role):
Expand Down
4 changes: 2 additions & 2 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ async def on_connect():
lambda cmd: cmd.name == i["name"]
and cmd.type == i.get("type")
and cmd.guild_ids is not None
# TODO: fix this type error (guild_id is not defined in ApplicationCommand Typed Dict)
and int(i["guild_id"]) in cmd.guild_ids, # type: ignore
and (guild_id := i.get("guild_id"))
and guild_id in cmd.guild_ids,
self.pending_application_commands,
)
if not cmd:
Expand Down
35 changes: 33 additions & 2 deletions discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

from . import utils
from .asset import Asset
from .emoji import Emoji
from .enums import (
ChannelType,
EmbeddedActivity,
Expand Down Expand Up @@ -171,7 +172,7 @@ def to_dict(self) -> dict[str, Any]:
payload: dict[str, Any] = {
"name": self.name,
"moderated": self.moderated,
} | self.emoji._to_forum_tag_payload()
} | self.emoji._to_forum_reaction_payload()

if self.id:
payload["id"] = self.id
Expand All @@ -195,6 +196,7 @@ class _TextChannel(discord.abc.GuildChannel, Hashable):
"last_message_id",
"default_auto_archive_duration",
"default_thread_slowmode_delay",
"default_reaction_emoji",
"default_sort_order",
"available_tags",
"flags",
Expand Down Expand Up @@ -228,7 +230,6 @@ def _update(
self.name: str = data["name"]
self.category_id: int | None = utils._get_as_snowflake(data, "parent_id")
self._type: int = data["type"]

# This data may be missing depending on how this object is being created/updated
if not data.pop("_invoke_flag", False):
self.topic: str | None = data.get("topic")
Expand Down Expand Up @@ -1008,6 +1009,10 @@ class ForumChannel(_TextChannel):
The initial slowmode delay to set on newly created threads in this channel.
.. versionadded:: 2.3
default_reaction_emoji: Optional[:class:`str` | :class:`discord.Emoji`]
The default forum reaction emoji.
.. versionadded:: 2.5
"""

def __init__(
Expand All @@ -1022,6 +1027,15 @@ def _update(self, guild: Guild, data: ForumChannelPayload) -> None:
for tag in (data.get("available_tags") or [])
]
self.default_sort_order: SortOrder | None = data.get("default_sort_order", None)
reaction_emoji_ctx: dict = data.get("default_reaction_emoji")
if reaction_emoji_ctx is not None:
emoji_name = reaction_emoji_ctx.get("emoji_name")
if emoji_name is not None:
self.default_reaction_emoji = reaction_emoji_ctx["emoji_name"]
else:
self.default_reaction_emoji = self._state.get_emoji(
utils._get_as_snowflake(reaction_emoji_ctx, "emoji_id")
)

@property
def guidelines(self) -> str | None:
Expand Down Expand Up @@ -1061,6 +1075,7 @@ async def edit(
default_auto_archive_duration: ThreadArchiveDuration = ...,
default_thread_slowmode_delay: int = ...,
default_sort_order: SortOrder = ...,
default_reaction_emoji: Emoji | int | str | None = ...,
available_tags: list[ForumTag] = ...,
require_tag: bool = ...,
overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ...,
Expand Down Expand Up @@ -1113,6 +1128,12 @@ async def edit(self, *, reason=None, **options):
The default sort order type to use to order posts in this channel.
.. versionadded:: 2.3
default_reaction_emoji: Optional[:class:`discord.Emoji` | :class:`int` | :class:`str`]
The default reaction emoji.
Can be a unicode emoji or a custom emoji in the forms:
:class:`Emoji`, snowflake ID, string representation (eg. '<a:emoji_name:emoji_id>').
.. versionadded:: 2.5
available_tags: List[:class:`ForumTag`]
The set of tags that can be used in this channel. Must be less than `20`.
Expand Down Expand Up @@ -1329,6 +1350,7 @@ class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hasha
"user_limit",
"_state",
"position",
"slowmode_delay",
"_overwrites",
"category_id",
"rtc_region",
Expand Down Expand Up @@ -1376,6 +1398,7 @@ def _update(
data, "last_message_id"
)
self.position: int = data.get("position")
self.slowmode_delay = data.get("rate_limit_per_user", 0)
self.bitrate: int = data.get("bitrate")
self.user_limit: int = data.get("user_limit")
self.flags: ChannelFlags = ChannelFlags._from_value(data.get("flags", 0))
Expand Down Expand Up @@ -1483,6 +1506,13 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
The ID of the last message sent to this channel. It may not always point to an existing or valid message.
.. versionadded:: 2.0
slowmode_delay: :class:`int`
The number of seconds a member must wait between sending messages
in this channel. A value of `0` denotes that it is disabled.
Bots and users with :attr:`~Permissions.manage_channels` or
:attr:`~Permissions.manage_messages` bypass slowmode.
.. versionadded:: 2.5
flags: :class:`ChannelFlags`
Extra features of the channel.
Expand Down Expand Up @@ -1791,6 +1821,7 @@ async def edit(
overwrites: Mapping[Role | Member, PermissionOverwrite] = ...,
rtc_region: VoiceRegion | None = ...,
video_quality_mode: VideoQualityMode = ...,
slowmode_delay: int = ...,
reason: str | None = ...,
) -> VoiceChannel | None:
...
Expand Down
6 changes: 4 additions & 2 deletions discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,12 @@ def _parse_options(self, params, *, check_params: bool = True) -> list[Option]:
option = next(option_gen, Option())
# Handle Optional
if self._is_typing_optional(type_hint):
option.input_type = get_args(type_hint)[0]
option.input_type = SlashCommandOptionType.from_datatype(
get_args(type_hint)[0]
)
option.default = None
else:
option.input_type = type_hint
option.input_type = SlashCommandOptionType.from_datatype(type_hint)

if self._is_typing_union(option):
if self._is_typing_optional(option):
Expand Down
11 changes: 9 additions & 2 deletions discord/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

from ...commands import (
ApplicationCommand,
Option,
_BaseCommand,
message_command,
slash_command,
Expand Down Expand Up @@ -562,7 +563,13 @@ async def dispatch_error(self, ctx: Context, error: Exception) -> None:
ctx.bot.dispatch("command_error", ctx, error)

async def transform(self, ctx: Context, param: inspect.Parameter) -> Any:
required = param.default is param.empty
if isinstance(param.annotation, Option):
default = param.annotation.default
required = param.annotation.required
else:
default = param.default
required = default is param.empty

converter = get_converter(param)
consume_rest_is_special = (
param.kind == param.KEYWORD_ONLY and not self.rest_is_raw
Expand Down Expand Up @@ -599,7 +606,7 @@ async def transform(self, ctx: Context, param: inspect.Parameter) -> Any:
):
return await converter._construct_default(ctx)
raise MissingRequiredArgument(param)
return param.default
return default

previous = view.index
if consume_rest_is_special:
Expand Down
Loading

0 comments on commit 66ef705

Please sign in to comment.