From 0c68e5f592e356f8251faff0ec8dd9f8cacfea2e Mon Sep 17 00:00:00 2001 From: Revnoplex <62947003+Revnoplex@users.noreply.github.com> Date: Sun, 17 Mar 2024 12:56:29 +1100 Subject: [PATCH 1/3] fix: Replace deprecated pkg_resources with importlib.metadata to clear DeprecationWarning (#2392) Signed-off-by: Lala Sabathil Signed-off-by: Revnoplex <62947003+Revnoplex@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lala Sabathil Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> --- CHANGELOG.md | 3 +++ discord/__main__.py | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8b74b924c..ac49862f6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ These changes are available on the `master` branch, but have not yet been releas - 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)) ### Changed diff --git a/discord/__main__.py b/discord/__main__.py index 12b5b5a1c3..ed34bdf42a 100644 --- a/discord/__main__.py +++ b/discord/__main__.py @@ -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 @@ -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() From 530f3d45956e037d3d5bea0a02153887abfafe2f Mon Sep 17 00:00:00 2001 From: Brandon Date: Sun, 17 Mar 2024 08:55:15 +0100 Subject: [PATCH 2/3] feat: add `banner` to `ClientUser.edit` (#2396) Signed-off-by: Brandon Signed-off-by: plun1331 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: plun1331 --- CHANGELOG.md | 5 +++++ discord/user.py | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac49862f6b..ea978f2d25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,11 @@ 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)) + ### Fixed - Fixed the type-hinting of `Member.move_to` and `Member.edit` to reflect actual diff --git a/discord/user.py b/discord/user.py index 1f11574a1c..5cd0352df3 100644 --- a/discord/user.py +++ b/discord/user.py @@ -422,7 +422,11 @@ 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| @@ -430,16 +434,19 @@ async def edit( .. 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` @@ -447,6 +454,9 @@ async def edit( 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 ------- @@ -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: @@ -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) From bfe7827ddda96b07af5f8d5fbdf7a808338b6795 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 17:10:02 +0000 Subject: [PATCH 3/3] chore(pre-commit): pre-commit autoupdate (#2398) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/PyCQA/autoflake: v2.3.0 → v2.3.1](https://github.com/PyCQA/autoflake/compare/v2.3.0...v2.3.1) - [github.com/psf/black: 24.2.0 → 24.3.0](https://github.com/psf/black/compare/24.2.0...24.3.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2660004bbf..81e9a64c72 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: @@ -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]