Skip to content

Commit

Permalink
Merge branch 'master' into invokable
Browse files Browse the repository at this point in the history
Signed-off-by: Middledot <[email protected]>
  • Loading branch information
Middledot authored Jan 16, 2024
2 parents d899980 + fc7b104 commit 4621811
Show file tree
Hide file tree
Showing 29 changed files with 265 additions and 79 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ 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"
python-version: "3.12"
cache: "pip"
cache-dependency-path: "requirements/dev.txt"
- name: Install dependencies
Expand All @@ -26,9 +26,9 @@ 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"
python-version: "3.12"
cache: "pip"
cache-dependency-path: "requirements/dev.txt"
- name: Install dependencies
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
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ 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"
python-version: "3.12"
cache: "pip"
cache-dependency-path: "requirements/dev.txt"
- name: Install dependencies
Expand All @@ -32,9 +32,9 @@ 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"
python-version: "3.12"
cache: "pip"
cache-dependency-path: "requirements/dev.txt"
- name: Install dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
env:
OS: ${{ matrix.os }}
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
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,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 @@ -206,6 +213,26 @@ 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))
- Fixed `AuditLogIterator` not respecting the `after` parameter.
([#2295](https://github.com/Pycord-Development/pycord/issues/2295))
- Fixed `AttributeError` when failing to establish initial websocket connection.
([#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))

## [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 @@ -782,8 +782,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
2 changes: 2 additions & 0 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ async def connect(self, *, reconnect: bool = True) -> None:
# Always try to RESUME the connection
# If the connection is not RESUME-able then the gateway will invalidate the session.
# This is apparently what the official Discord client does.
if self.ws is None:
continue
ws_params.update(
sequence=self.ws.sequence, resume=True, session=self.ws.session_id
)
Expand Down
Loading

0 comments on commit 4621811

Please sign in to comment.