From 52e3cdebacdab5ce25d0e69b2521823e1b8b8b77 Mon Sep 17 00:00:00 2001 From: MattyTheHacker <18513864+MattyTheHacker@users.noreply.github.com> Date: Mon, 19 Aug 2024 23:15:23 +0100 Subject: [PATCH 01/14] feat: Member.display_banner --- discord/asset.py | 11 +++++++++++ discord/member.py | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/discord/asset.py b/discord/asset.py index c8a33e61e3..16f4d459aa 100644 --- a/discord/asset.py +++ b/discord/asset.py @@ -212,6 +212,17 @@ def _from_guild_avatar( animated=animated, ) + @classmethod + def _from_guild_banner(cls, state, guild_id: int, member_id: int, banner: str) -> Asset: + animated: bool = banner.startswith("a_") + format: str = "gif" if animated else "png" + return cls( + state, + url=f"{cls.BASE}/guilds/{guild_id}/users/{member_id}/banners/{banner}.{format}?size=1024", + key=banner, + animated=animated, + ) + @classmethod def _from_icon(cls, state, object_id: int, icon_hash: str, path: str) -> Asset: return cls( diff --git a/discord/member.py b/discord/member.py index 18ebf1267f..164f1fe732 100644 --- a/discord/member.py +++ b/discord/member.py @@ -306,6 +306,7 @@ class Member(discord.abc.Messageable, _UserTag): mutual_guilds: list[Guild] public_flags: PublicUserFlags banner: Asset | None + display_banner: Asset | None accent_color: Colour | None accent_colour: Colour | None communication_disabled_until: datetime.datetime | None @@ -603,6 +604,31 @@ def guild_avatar(self) -> Asset | None: self._state, self.guild.id, self.id, self._avatar ) + @property + def display_banner(self) -> Asset | None: + """Returns the member's display banner. + + For regular members this is just their banner, but + if they have a guild specific banner then that + is returned instead. + + .. versionadded:: 2.7 + """ + return self.guild_banner or self._user.banner + + @property + def guild_banner(self) -> Asset | None: + """Returns an :class:`Asset` for the guild banner + the member has. If unavailable, ``None`` is returned. + + .. versionadded:: 2.7 + """ + if self._user.banner is None: + return None + return Asset._from_guild_banner( + self._state, self.guild.id, self.id, self._user.banner + ) + @property def activity(self) -> ActivityTypes | None: """Returns the primary From ccfa1997d47311c6b974041b3f7f5e751f78aece Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 22:20:20 +0000 Subject: [PATCH 02/14] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/asset.py | 4 +++- discord/member.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/discord/asset.py b/discord/asset.py index 16f4d459aa..6bb6797761 100644 --- a/discord/asset.py +++ b/discord/asset.py @@ -213,7 +213,9 @@ def _from_guild_avatar( ) @classmethod - def _from_guild_banner(cls, state, guild_id: int, member_id: int, banner: str) -> Asset: + def _from_guild_banner( + cls, state, guild_id: int, member_id: int, banner: str + ) -> Asset: animated: bool = banner.startswith("a_") format: str = "gif" if animated else "png" return cls( diff --git a/discord/member.py b/discord/member.py index 164f1fe732..b424bdac12 100644 --- a/discord/member.py +++ b/discord/member.py @@ -620,7 +620,7 @@ def display_banner(self) -> Asset | None: def guild_banner(self) -> Asset | None: """Returns an :class:`Asset` for the guild banner the member has. If unavailable, ``None`` is returned. - + .. versionadded:: 2.7 """ if self._user.banner is None: From 885ac5bd4cfd77229ecaa688e3cafaa08102144c Mon Sep 17 00:00:00 2001 From: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:55:42 +0100 Subject: [PATCH 03/14] Update CHANGELOG.md Signed-off-by: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ceaa298b18..38b0c46cfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ These changes are available on the `master` branch, but have not yet been releas ### Added +- Added `Member.display_banner` method. + ([#2556](https://github.com/Pycord-Development/pycord/pull/2556)) + - Added `Guild.fetch_role` method. ([#2528](https://github.com/Pycord-Development/pycord/pull/2528)) From cf9f2f2e323e2b82fb7821fd5780e1356c4e8948 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Tue, 20 Aug 2024 15:45:57 +0200 Subject: [PATCH 04/14] Update CHANGELOG.md Signed-off-by: Lala Sabathil --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b0c46cfb..6fca638484 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,6 @@ These changes are available on the `master` branch, but have not yet been releas - Added `Member.display_banner` method. ([#2556](https://github.com/Pycord-Development/pycord/pull/2556)) - - Added `Guild.fetch_role` method. ([#2528](https://github.com/Pycord-Development/pycord/pull/2528)) From 28500ce7a7cccc364f183aaa1540405512c5a6cc Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:38:38 +0300 Subject: [PATCH 05/14] chore: remove type hints for consistency Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- discord/asset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/asset.py b/discord/asset.py index 6bb6797761..46b564cbe2 100644 --- a/discord/asset.py +++ b/discord/asset.py @@ -216,8 +216,8 @@ def _from_guild_avatar( def _from_guild_banner( cls, state, guild_id: int, member_id: int, banner: str ) -> Asset: - animated: bool = banner.startswith("a_") - format: str = "gif" if animated else "png" + animated = banner.startswith("a_") + format = "gif" if animated else "png" return cls( state, url=f"{cls.BASE}/guilds/{guild_id}/users/{member_id}/banners/{banner}.{format}?size=1024", From 3aeee34e931d00818e3aae20c73663800c777063 Mon Sep 17 00:00:00 2001 From: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:07:34 +0100 Subject: [PATCH 06/14] fix: set size to `1024` for `_from_user_banner` Signed-off-by: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> --- discord/asset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/asset.py b/discord/asset.py index 46b564cbe2..18897fc6ed 100644 --- a/discord/asset.py +++ b/discord/asset.py @@ -284,7 +284,7 @@ def _from_user_banner(cls, state, user_id: int, banner_hash: str) -> Asset: format = "gif" if animated else "png" return cls( state, - url=f"{cls.BASE}/banners/{user_id}/{banner_hash}.{format}?size=512", + url=f"{cls.BASE}/banners/{user_id}/{banner_hash}.{format}?size=1024", key=banner_hash, animated=animated, ) From 43b11aa598da79fd26d77239c27ba52447f3b55f Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:15:35 +0300 Subject: [PATCH 07/14] refactor: revert size to 512 Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- discord/asset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/asset.py b/discord/asset.py index 18897fc6ed..07c7ca8e7b 100644 --- a/discord/asset.py +++ b/discord/asset.py @@ -220,7 +220,7 @@ def _from_guild_banner( format = "gif" if animated else "png" return cls( state, - url=f"{cls.BASE}/guilds/{guild_id}/users/{member_id}/banners/{banner}.{format}?size=1024", + url=f"{cls.BASE}/guilds/{guild_id}/users/{member_id}/banners/{banner}.{format}?size=512", key=banner, animated=animated, ) @@ -284,7 +284,7 @@ def _from_user_banner(cls, state, user_id: int, banner_hash: str) -> Asset: format = "gif" if animated else "png" return cls( state, - url=f"{cls.BASE}/banners/{user_id}/{banner_hash}.{format}?size=1024", + url=f"{cls.BASE}/banners/{user_id}/{banner_hash}.{format}?size=512", key=banner_hash, animated=animated, ) From 624b812d9d578206f69210aceebc3c70478e59e9 Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:19:57 +0300 Subject: [PATCH 08/14] chore: move changelog entry to bottom Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fca638484..5833f96f1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,10 +22,10 @@ These changes are available on the `master` branch, but have not yet been releas ### Added -- Added `Member.display_banner` method. - ([#2556](https://github.com/Pycord-Development/pycord/pull/2556)) - Added `Guild.fetch_role` method. ([#2528](https://github.com/Pycord-Development/pycord/pull/2528)) +- Added `Member.display_banner` method. + ([#2556](https://github.com/Pycord-Development/pycord/pull/2556)) ## [2.6.0] - 2024-07-09 From e23ed2548aa690430c402fd6c3940ede78f2aafe Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:23:22 +0300 Subject: [PATCH 09/14] refactor: remove property from changelog Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- discord/member.py | 1 - 1 file changed, 1 deletion(-) diff --git a/discord/member.py b/discord/member.py index b424bdac12..728d010b4b 100644 --- a/discord/member.py +++ b/discord/member.py @@ -306,7 +306,6 @@ class Member(discord.abc.Messageable, _UserTag): mutual_guilds: list[Guild] public_flags: PublicUserFlags banner: Asset | None - display_banner: Asset | None accent_color: Colour | None accent_colour: Colour | None communication_disabled_until: datetime.datetime | None From d8558e2ca000a32aa3f922e194c1717bd52c95fc Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:25:53 +0300 Subject: [PATCH 10/14] chore: adjust changelog Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5833f96f1c..012af784e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ These changes are available on the `master` branch, but have not yet been releas - Added `Guild.fetch_role` method. ([#2528](https://github.com/Pycord-Development/pycord/pull/2528)) -- Added `Member.display_banner` method. +- Added `Member.guild_banner` and `Member.display_banner` properties. ([#2556](https://github.com/Pycord-Development/pycord/pull/2556)) ## [2.6.0] - 2024-07-09 From 600ff2606822c11178cb08ab20466e5c321ea4b5 Mon Sep 17 00:00:00 2001 From: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> Date: Tue, 27 Aug 2024 23:55:51 +0100 Subject: [PATCH 11/14] fix: references to self._user.banner Co-authored-by: YoggieS <61660055+yoggys@users.noreply.github.com> Signed-off-by: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> --- discord/member.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/member.py b/discord/member.py index 728d010b4b..d3eb90be45 100644 --- a/discord/member.py +++ b/discord/member.py @@ -622,10 +622,10 @@ def guild_banner(self) -> Asset | None: .. versionadded:: 2.7 """ - if self._user.banner is None: + if self._banner is None: return None return Asset._from_guild_banner( - self._state, self.guild.id, self.id, self._user.banner + self._state, self.guild.id, self.id, self._banner ) @property From f70bd4e3f5395d7242065827ae4fbe942cbfbf98 Mon Sep 17 00:00:00 2001 From: MattyTheHacker <18513864+MattyTheHacker@users.noreply.github.com> Date: Wed, 28 Aug 2024 00:01:34 +0100 Subject: [PATCH 12/14] fix: add self._banner to member methods --- discord/member.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/discord/member.py b/discord/member.py index d3eb90be45..96b73a9724 100644 --- a/discord/member.py +++ b/discord/member.py @@ -328,6 +328,7 @@ def __init__( self.nick: str | None = data.get("nick", None) self.pending: bool = data.get("pending", False) self._avatar: str | None = data.get("avatar") + self._banner: str | None = data.get("banner") self.communication_disabled_until: datetime.datetime | None = utils.parse_time( data.get("communication_disabled_until") ) @@ -406,6 +407,7 @@ def _copy(cls: type[M], member: M) -> M: self.activities = member.activities self._state = member._state self._avatar = member._avatar + self._banner = member._banner self.communication_disabled_until = member.communication_disabled_until self.flags = member.flags @@ -434,6 +436,7 @@ def _update(self, data: MemberPayload) -> None: self.premium_since = utils.parse_time(data.get("premium_since")) self._roles = utils.SnowflakeList(map(int, data["roles"])) self._avatar = data.get("avatar") + self._banner = data.get("banner") self.communication_disabled_until = utils.parse_time( data.get("communication_disabled_until") ) From ecdf409f59e2fb2f13f0eb75504cad41c63a1cc5 Mon Sep 17 00:00:00 2001 From: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> Date: Tue, 27 Aug 2024 23:19:06 +0000 Subject: [PATCH 13/14] fix: add _banner slot --- discord/member.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/member.py b/discord/member.py index 96b73a9724..f1a546c918 100644 --- a/discord/member.py +++ b/discord/member.py @@ -288,6 +288,7 @@ class Member(discord.abc.Messageable, _UserTag): "_user", "_state", "_avatar", + "_banner", "communication_disabled_until", "flags", ) From 1494e91d0d0dc26fce69b332b57bc18dd6839274 Mon Sep 17 00:00:00 2001 From: MattyTheHacker <18513864+MattyTheHacker@users.noreply.github.com> Date: Thu, 29 Aug 2024 01:18:18 +0100 Subject: [PATCH 14/14] fix: add banner to Member TypedDict --- discord/types/member.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/types/member.py b/discord/types/member.py index 0bc1071fb1..618bb13efe 100644 --- a/discord/types/member.py +++ b/discord/types/member.py @@ -42,6 +42,7 @@ class PartialMember(TypedDict): class Member(PartialMember, total=False): avatar: str + banner: str user: User nick: str premium_since: str