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 Mar 24, 2024
2 parents fe80915 + 548ca85 commit c1ec0b1
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.0
rev: v2.3.1
hooks:
- id: autoflake
# args:
Expand All @@ -28,7 +28,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 24.2.0
rev: 24.3.0
hooks:
- id: black
args: [--safe, --quiet]
Expand Down
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,36 @@ possible (see our [Version Guarantees] for more info).

These changes are available on the `master` branch, but have not yet been released.

### Added

- Added `banner` parameter to `ClientUser.edit`.
([#2396](https://github.com/Pycord-Development/pycord/pull/2396))
- Added `user` argument to `Paginator.edit`.
([#2390](https://github.com/Pycord-Development/pycord/pull/2390))

### Fixed

- Fixed the type-hinting of `Member.move_to` and `Member.edit` to reflect actual
behavior. ([#2386](https://github.com/Pycord-Development/pycord/pull/2386))
- Fixed a deprecation warning from being displayed when running `python -m discord -v`
by replacing the deprecated module.
([#2392](https://github.com/Pycord-Development/pycord/pull/2392))
- Fixed `Paginator.edit` to no longer set user to the bot.
([#2390](https://github.com/Pycord-Development/pycord/pull/2390))
- Fixed `NameError` in some instances of `Interaction`.
([#2402](https://github.com/Pycord-Development/pycord/pull/2402))
- Fixed the type-hinting of `ScheduledEvent.subscribers` to reflect actual behavior.
([#2400](https://github.com/Pycord-Development/pycord/pull/2400))
- Fixed `ScheduledEvent.subscribers` behavior with `limit=None`.
([#2407](https://github.com/Pycord-Development/pycord/pull/2407))

### Changed

- Changed the type of `Guild.bitrate_limit` to `int`.
([#2387](https://github.com/Pycord-Development/pycord/pull/2387))
- HTTP requests that fail with a 503 status are now re-tried.
([#2395](https://github.com/Pycord-Development/pycord/pull/2395))

## [2.5.0] - 2024-03-02

### Added
Expand Down
8 changes: 4 additions & 4 deletions discord/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
"""

import argparse
import importlib.metadata
import platform
import sys
from pathlib import Path
from typing import Tuple

import aiohttp
import pkg_resources

import discord

Expand All @@ -47,9 +47,9 @@ def show_version() -> None:
"- py-cord v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}".format(version_info)
)
if version_info.releaselevel != "final":
pkg = pkg_resources.get_distribution("py-cord")
if pkg:
entries.append(f" - py-cord pkg_resources: v{pkg.version}")
version = importlib.metadata.version("py-cord")
if version:
entries.append(f" - py-cord importlib.metadata: v{version}")

entries.append(f"- aiohttp v{aiohttp.__version__}")
uname = platform.uname()
Expand Down
2 changes: 1 addition & 1 deletion discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ async def sync_commands(
register all commands.
By default, this coroutine is called inside the :func:`.on_connect` event. If you choose to override the
:func:`.on_connect` event, then you should invoke this coroutine as well such as the follwing:
:func:`.on_connect` event, then you should invoke this coroutine as well such as the following:
.. code-block:: python
Expand Down
7 changes: 6 additions & 1 deletion discord/ext/pages/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import discord
from discord.ext.bridge import BridgeContext
from discord.ext.commands import Context
from discord.member import Member
from discord.user import User

__all__ = (
"PaginatorButton",
Expand Down Expand Up @@ -1035,6 +1037,7 @@ async def edit(
suppress: bool | None = None,
allowed_mentions: discord.AllowedMentions | None = None,
delete_after: float | None = None,
user: User | Member | None = None,
) -> discord.Message | None:
"""Edits an existing message to replace it with the paginator contents.
Expand All @@ -1060,6 +1063,8 @@ async def edit(
are used instead.
delete_after: Optional[:class:`float`]
If set, deletes the paginator after the specified time.
user: Optional[Union[:class:`~discord.User`, :class:`~discord.Member`]]
If set, changes the user that this paginator belongs to.
Returns
-------
Expand All @@ -1079,7 +1084,7 @@ async def edit(
if page_content.custom_view:
self.update_custom_view(page_content.custom_view)

self.user = message.author
self.user = user or self.user

try:
self.message = await message.edit(
Expand Down
5 changes: 5 additions & 0 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,11 @@ def voice_states(self):
- :attr:`VoiceChannel.members`
- :attr:`VoiceChannel.voice_states`
- :attr:`StageChannel.members`
- :attr:`StageChannel.speakers`
- :attr:`StageChannel.listeners`
- :attr:`StageChannel.moderators`
- :attr:`StageChannel.voice_states`
- :attr:`Member.voice`
.. note::
Expand Down
10 changes: 6 additions & 4 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def _from_data(self, guild: GuildPayload) -> None:
)

self.owner_id: int | None = utils._get_as_snowflake(guild, "owner_id")
self.afk_channel: VocalGuildChannel | None = self.get_channel(
self.afk_channel: VoiceChannel | None = self.get_channel(
utils._get_as_snowflake(guild, "afk_channel_id")
) # type: ignore

Expand Down Expand Up @@ -823,14 +823,16 @@ def sticker_limit(self) -> int:
)

@property
def bitrate_limit(self) -> float:
def bitrate_limit(self) -> int:
"""The maximum bitrate for voice channels this guild can have."""
vip_guild = (
self._PREMIUM_GUILD_LIMITS[1].bitrate
if "VIP_REGIONS" in self.features
else 96e3
)
return max(vip_guild, self._PREMIUM_GUILD_LIMITS[self.premium_tier].bitrate)
return int(
max(vip_guild, self._PREMIUM_GUILD_LIMITS[self.premium_tier].bitrate)
)

@property
def filesize_limit(self) -> int:
Expand Down Expand Up @@ -3443,7 +3445,7 @@ async def change_voice_state(
Parameters
----------
channel: Optional[:class:`VoiceChannel`]
channel: Optional[Union[:class:`VoiceChannel`, :class:`StageChannel`]]
Channel the client wants to join. Use ``None`` to disconnect.
self_mute: :class:`bool`
Indicates if the client should be self-muted.
Expand Down
4 changes: 2 additions & 2 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ async def request(

continue

# we've received a 500, 502, or 504, unconditional retry
if response.status in {500, 502, 504}:
# we've received a 500, 502, 503, or 504, unconditional retry
if response.status in {500, 502, 503, 504}:
await asyncio.sleep(1 + tries * 2)
continue

Expand Down
2 changes: 1 addition & 1 deletion discord/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from .errors import ClientException, InteractionResponded, InvalidArgument
from .file import File
from .flags import MessageFlags
from .guild import Guild
from .member import Member
from .message import Attachment, Message
from .monetization import Entitlement
Expand Down Expand Up @@ -69,7 +70,6 @@
from .client import Client
from .commands import OptionChoice
from .embeds import Embed
from .guild import Guild
from .mentions import AllowedMentions
from .state import ConnectionState
from .threads import Thread
Expand Down
16 changes: 11 additions & 5 deletions discord/iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,10 @@ class ScheduledEventSubscribersIterator(_AsyncIterator[Union["User", "Member"]])
def __init__(
self,
event: ScheduledEvent,
limit: int,
limit: int | None,
with_member: bool = False,
before: datetime.datetime | int = None,
after: datetime.datetime | int = None,
before: datetime.datetime | int | None = None,
after: datetime.datetime | int | None = None,
):
if isinstance(before, datetime.datetime):
before = Object(id=time_snowflake(before, high=False))
Expand Down Expand Up @@ -919,8 +919,14 @@ async def fill_subs(self):
before=before,
after=after,
)
if data:
self.limit -= self.retrieve

data_length = len(data)
if data_length < self.retrieve:
self.limit = 0
elif data_length > 0:
if self.limit:
self.limit -= self.retrieve
self.after = Object(id=int(data[-1]["user_id"]))

for element in reversed(data):
if "member" in element:
Expand Down
6 changes: 3 additions & 3 deletions discord/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ async def edit(
roles: List[:class:`Role`]
The member's new list of roles. This *replaces* the roles.
voice_channel: Optional[:class:`VoiceChannel`]
voice_channel: Optional[Union[:class:`VoiceChannel`, :class:`StageChannel`]]
The voice channel to move the member to.
Pass ``None`` to kick them from voice.
reason: Optional[:class:`str`]
Expand Down Expand Up @@ -958,7 +958,7 @@ async def request_to_speak(self) -> None:
await self._state.http.edit_my_voice_state(self.guild.id, payload)

async def move_to(
self, channel: VocalGuildChannel, *, reason: str | None = None
self, channel: VocalGuildChannel | None, *, reason: str | None = None
) -> None:
"""|coro|
Expand All @@ -974,7 +974,7 @@ async def move_to(
Parameters
----------
channel: Optional[:class:`VoiceChannel`]
channel: Optional[Union[:class:`VoiceChannel`, :class:`StageChannel`]]
The new voice channel to move the member to.
Pass ``None`` to kick them from voice.
reason: Optional[:class:`str`]
Expand Down
2 changes: 1 addition & 1 deletion discord/raw_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ class AutoModActionExecutionEvent:
The member that triggered the action, if cached.
channel_id: Optional[:class:`int`]
The ID of the channel in which the member's content was posted.
channel: Optional[Union[:class:`TextChannel`, :class:`Thread`, :class:`VoiceChannel`]]
channel: Optional[Union[:class:`TextChannel`, :class:`Thread`, :class:`VoiceChannel`, :class:`StageChannel`]]
The channel in which the member's content was posted, if cached.
message_id: Optional[:class:`int`]
The ID of the message that triggered the action. This is only available if the
Expand Down
4 changes: 2 additions & 2 deletions discord/scheduled_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,11 @@ async def cancel(self, *, reason: str | None = None) -> None:
def subscribers(
self,
*,
limit: int = 100,
limit: int | None = 100,
as_member: bool = False,
before: Snowflake | datetime.datetime | None = None,
after: Snowflake | datetime.datetime | None = None,
) -> AsyncIterator:
) -> ScheduledEventSubscribersIterator:
"""Returns an :class:`AsyncIterator` representing the users or members subscribed to the event.
The ``after`` and ``before`` parameters must represent member
Expand Down
1 change: 1 addition & 0 deletions discord/types/scheduled_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ class ScheduledEventEntityMetadata(TypedDict):

class ScheduledEventSubscriber(TypedDict):
guild_scheduled_event_id: Snowflake
user_id: Snowflake
user: User
member: Member | None
23 changes: 19 additions & 4 deletions discord/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,31 +422,41 @@ def _update(self, data: UserPayload) -> None:

# TODO: Username might not be able to edit anymore.
async def edit(
self, *, username: str = MISSING, avatar: bytes = MISSING
self,
*,
username: str = MISSING,
avatar: bytes = MISSING,
banner: bytes = MISSING,
) -> ClientUser:
"""|coro|
Edits the current profile of the client.
.. note::
To upload an avatar, a :term:`py:bytes-like object` must be passed in that
To upload an avatar or banner, a :term:`py:bytes-like object` must be passed in that
represents the image being uploaded. If this is done through a file
then the file must be opened via ``open('some_filename', 'rb')`` and
the :term:`py:bytes-like object` is given through the use of ``fp.read()``.
The only image formats supported for uploading is JPEG and PNG.
The only image formats supported for uploading are JPEG, PNG, and GIF.
.. versionchanged:: 2.0
The edit is no longer in-place, instead the newly edited client user is returned.
.. versionchanged:: 2.6
The ``banner`` keyword-only parameter was added.
Parameters
----------
username: :class:`str`
The new username you wish to change to.
avatar: :class:`bytes`
A :term:`py:bytes-like object` representing the image to upload.
Could be ``None`` to denote no avatar.
banner: :class:`bytes`
A :term:`py:bytes-like object` representing the image to upload.
Could be ``None`` to denote no banner.
Returns
-------
Expand All @@ -458,7 +468,7 @@ async def edit(
HTTPException
Editing your profile failed.
InvalidArgument
Wrong image format passed for ``avatar``.
Wrong image format passed for ``avatar`` or ``banner``.
"""
payload: dict[str, Any] = {}
if username is not MISSING:
Expand All @@ -469,6 +479,11 @@ async def edit(
elif avatar is not MISSING:
payload["avatar"] = _bytes_to_base64_data(avatar)

if banner is None:
payload["banner"] = None
elif banner is not MISSING:
payload["banner"] = _bytes_to_base64_data(banner)

data: UserPayload = await self._state.http.edit_profile(payload)
return ClientUser(state=self._state, data=data)

Expand Down
6 changes: 3 additions & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-r _.txt
pylint~=3.1.0
pytest~=8.0.2
pytest~=8.1.1
pytest-asyncio~=0.23.3
# pytest-order~=1.0.1
mypy~=1.8.0
mypy~=1.9.0
coverage~=7.4
pre-commit==3.5.0
codespell==2.2.6
bandit==1.7.7
bandit==1.7.8
flake8==7.0.0

0 comments on commit c1ec0b1

Please sign in to comment.