From 9bb2a57edb17dabc46c19bf22f93512e71573e36 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 17 Dec 2024 21:40:31 +0100 Subject: [PATCH 1/9] :sparkles: Add missing `Guild` feature flags --- discord/guild.py | 60 +++++++++++++++++++++++++++++++++++++----- discord/types/guild.py | 3 +++ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index b1e937d07b..bcb8ecfc7a 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1663,6 +1663,9 @@ async def edit( public_updates_channel: TextChannel | None = MISSING, premium_progress_bar_enabled: bool = MISSING, disable_invites: bool = MISSING, + discoverable: bool = MISSING, + raid_alerts: bool = MISSING, + enable_activity_feed: bool = MISSING, ) -> Guild: r"""|coro| @@ -1740,6 +1743,12 @@ async def edit( Whether the guild should have premium progress bar enabled. disable_invites: :class:`bool` Whether the guild should have server invites enabled or disabled. + discoverable: :class:`bool` + Whether the guild should be discoverable in the discord discover tab. + raid_alerts: :class:`bool` + Whether activity alerts for the guild should be enabled. + enable_activity_feed: Optional[:class:`bool`] + Whether the guild's user activity feed should be enabled. reason: Optional[:class:`str`] The reason for editing this guild. Shows up on the audit log. @@ -1861,8 +1870,13 @@ async def edit( fields["system_channel_flags"] = system_channel_flags.value + if premium_progress_bar_enabled is not MISSING: + fields["premium_progress_bar_enabled"] = premium_progress_bar_enabled + + # feature flags + if community is not MISSING: - features = self.features.copy() + features: list[str] = fields.get("features", self.features.copy()) if community: if ( "rules_channel_id" in fields @@ -1885,13 +1899,10 @@ async def edit( fields["features"] = features - if premium_progress_bar_enabled is not MISSING: - fields["premium_progress_bar_enabled"] = premium_progress_bar_enabled - if disable_invites is not MISSING: - features = self.features.copy() + features = fields.get("features", self.features.copy()) if disable_invites: - if not "INVITES_DISABLED" in features: + if "INVITES_DISABLED" not in features: features.append("INVITES_DISABLED") else: if "INVITES_DISABLED" in features: @@ -1899,6 +1910,43 @@ async def edit( fields["features"] = features + if discoverable is not MISSING: + features = fields.get("features", self.features.copy()) + if discoverable: + if "DISCOVERABLE" not in features: + features.append("DISCOVERABLE") + else: + if "DISCOVERABLE" in features: + features.remove("DISCOVERABLE") + + fields["features"] = features + + if raid_alerts is not MISSING: + features = fields.get("features", self.features.copy()) + if raid_alerts: + if "RAID_ALERTS_DISABLED" in features: + features.remove("RAID_ALERTS_DISABLED") + else: + if "RAID_ALERTS_DISABLED" not in features: + features.append("RAID_ALERTS_DISABLED") + + fields["features"] = features + + if enable_activity_feed is not MISSING: + features = fields.get("features", self.features.copy()) + if enable_activity_feed: + if "ACTIVITY_FEED_ENABLED_BY_USER" not in features: + features.append("ACTIVITY_FEED_ENABLED_BY_USER") + if "ACTIVITY_FEED_DISABLED_BY_USER" in features: + features.remove("ACTIVITY_FEED_DISABLED_BY_USER") + else: + if "ACTIVITY_FEED_ENABLED_BY_USER" in features: + features.remove("ACTIVITY_FEED_ENABLED_BY_USER") + if "ACTIVITY_FEED_DISABLED_BY_USER" not in features: + features.append("ACTIVITY_FEED_DISABLED_BY_USER") + + fields["features"] = features + data = await http.edit_guild(self.id, reason=reason, **fields) return Guild(data=data, state=self._state) diff --git a/discord/types/guild.py b/discord/types/guild.py index cac645b272..be54c4ca35 100644 --- a/discord/types/guild.py +++ b/discord/types/guild.py @@ -58,6 +58,8 @@ class UnavailableGuild(TypedDict): NSFWLevel = Literal[0, 1, 2, 3] PremiumTier = Literal[0, 1, 2, 3] GuildFeature = Literal[ + "ACTIVITY_FEED_DISABLED_BY_USER", + "ACTIVITY_FEED_ENABLED_BY_USER", "ANIMATED_BANNER", "ANIMATED_ICON", "APPLICATION_COMMAND_PERMISSIONS_V2", @@ -87,6 +89,7 @@ class UnavailableGuild(TypedDict): "PREVIEW_ENABLED", "ROLE_ICONS", "ROLE_SUBSCRIPTIONS_ENABLED", + "RAID_ALERTS_DISABLED", "SEVEN_DAY_THREAD_ARCHIVE", "TEXT_IN_VOICE_ENABLED", "THREAD_DEFAULT_AUTO_ARCHIVE_DURATION", From 58d5bebd1e9537e2728a4bf2a479b274b22b7f07 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 17 Dec 2024 21:48:16 +0100 Subject: [PATCH 2/9] :sparkles: Add `Guild.activity_feed_enabled` to know whether the activity feed is enabled for the guild. --- discord/guild.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/discord/guild.py b/discord/guild.py index bcb8ecfc7a..cef8efef4d 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -676,6 +676,11 @@ def categories(self) -> list[CategoryChannel]: r.sort(key=lambda c: (c.position or -1, c.id)) return r + @property + def activity_feed_enabled(self) -> bool: + """Returns ``True`` if the guild has the activity feed enabled.""" + return "ACTIVITY_FEED_DISABLED_BY_USER" not in self.features + def by_category(self) -> list[ByCategoryItem]: """Returns every :class:`CategoryChannel` and their associated channels. From 1632bce7620df5707912e6f5146351efb7424d44 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 17 Dec 2024 22:02:40 +0100 Subject: [PATCH 3/9] :memo: Docs --- discord/guild.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/discord/guild.py b/discord/guild.py index cef8efef4d..1a6f126bd4 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -681,6 +681,14 @@ def activity_feed_enabled(self) -> bool: """Returns ``True`` if the guild has the activity feed enabled.""" return "ACTIVITY_FEED_DISABLED_BY_USER" not in self.features + @property + def invites_disabled(self) -> bool: + """Returns ``True`` if the guild has invites disabled. + + This corresponds to the invites being paused under the server's Security Actions + """ + return "INVITES_DISABLED" in self.features + def by_category(self) -> list[ByCategoryItem]: """Returns every :class:`CategoryChannel` and their associated channels. @@ -1748,6 +1756,8 @@ async def edit( Whether the guild should have premium progress bar enabled. disable_invites: :class:`bool` Whether the guild should have server invites enabled or disabled. + + This corresponds to pausing the invites under the server's Security Actions discoverable: :class:`bool` Whether the guild should be discoverable in the discord discover tab. raid_alerts: :class:`bool` From 712b2383cc656e7068093078a53fba4e3ddf1501 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 17 Dec 2024 22:09:35 +0100 Subject: [PATCH 4/9] :memo: CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bda9a0ecc..d1e10a091a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ These changes are available on the `master` branch, but have not yet been releas `Permissions.use_external_sounds` and `Permissions.view_creator_monetization_analytics`. ([#2620](https://github.com/Pycord-Development/pycord/pull/2620)) +- Add missing `Guild` feature flags and `Guild.edit` parameters. + ([#2672](https://github.com/Pycord-Development/pycord/pull/2672)) ### Fixed From 8dd4b4feed460d5282147d1a82c6c56566e3f08d Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 18 Dec 2024 17:54:49 +0100 Subject: [PATCH 5/9] chore: :alien: Update base max filesize to `10` Mb (#2671) * :alien: Update base max filesize to `10` Mb * :memo: CHANGELOG.md --- CHANGELOG.md | 2 ++ discord/guild.py | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 861f66ec0f..3c8d779160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,8 @@ These changes are available on the `master` branch, but have not yet been releas - Replaced audioop (deprecated module) implementation of `PCMVolumeTransformer.read` method with a pure Python equivalent. ([#2176](https://github.com/Pycord-Development/pycord/pull/2176)) +- Updated `Guild.filesize_limit` to 10 Mb instead of 25 Mb following Discord's API + changes. ([#2671](https://github.com/Pycord-Development/pycord/pull/2671)) ### Deprecated diff --git a/discord/guild.py b/discord/guild.py index b1e937d07b..337abd31c0 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -289,11 +289,11 @@ class Guild(Hashable): ) _PREMIUM_GUILD_LIMITS: ClassVar[dict[int | None, _GuildLimit]] = { - None: _GuildLimit(emoji=50, stickers=5, bitrate=96e3, filesize=26214400), - 0: _GuildLimit(emoji=50, stickers=5, bitrate=96e3, filesize=26214400), - 1: _GuildLimit(emoji=100, stickers=15, bitrate=128e3, filesize=26214400), - 2: _GuildLimit(emoji=150, stickers=30, bitrate=256e3, filesize=52428800), - 3: _GuildLimit(emoji=250, stickers=60, bitrate=384e3, filesize=104857600), + None: _GuildLimit(emoji=50, stickers=5, bitrate=96e3, filesize=10_485_760), + 0: _GuildLimit(emoji=50, stickers=5, bitrate=96e3, filesize=10_485_760), + 1: _GuildLimit(emoji=100, stickers=15, bitrate=128e3, filesize=10_485_760), + 2: _GuildLimit(emoji=150, stickers=30, bitrate=256e3, filesize=52_428_800), + 3: _GuildLimit(emoji=250, stickers=60, bitrate=384e3, filesize=104_857_600), } def __init__(self, *, data: GuildPayload, state: ConnectionState): From e93112bce3e0af26efb5f7ffd5665009be0e0de4 Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 26 Dec 2024 23:18:03 +0100 Subject: [PATCH 6/9] :memo: Requested changes --- discord/guild.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 6efe6e2dac..62bb1cf5fe 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -676,19 +676,6 @@ def categories(self) -> list[CategoryChannel]: r.sort(key=lambda c: (c.position or -1, c.id)) return r - @property - def activity_feed_enabled(self) -> bool: - """Returns ``True`` if the guild has the activity feed enabled.""" - return "ACTIVITY_FEED_DISABLED_BY_USER" not in self.features - - @property - def invites_disabled(self) -> bool: - """Returns ``True`` if the guild has invites disabled. - - This corresponds to the invites being paused under the server's Security Actions - """ - return "INVITES_DISABLED" in self.features - def by_category(self) -> list[ByCategoryItem]: """Returns every :class:`CategoryChannel` and their associated channels. @@ -1756,13 +1743,11 @@ async def edit( Whether the guild should have premium progress bar enabled. disable_invites: :class:`bool` Whether the guild should have server invites enabled or disabled. - - This corresponds to pausing the invites under the server's Security Actions discoverable: :class:`bool` - Whether the guild should be discoverable in the discord discover tab. + Whether the guild should be discoverable in the discover tab. raid_alerts: :class:`bool` Whether activity alerts for the guild should be enabled. - enable_activity_feed: Optional[:class:`bool`] + enable_activity_feed: class:`bool` Whether the guild's user activity feed should be enabled. reason: Optional[:class:`str`] The reason for editing this guild. Shows up on the audit log. @@ -1888,8 +1873,6 @@ async def edit( if premium_progress_bar_enabled is not MISSING: fields["premium_progress_bar_enabled"] = premium_progress_bar_enabled - # feature flags - if community is not MISSING: features: list[str] = fields.get("features", self.features.copy()) if community: From 3ddbead68d15000008a716e031588ab0bdc5895f Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 2 Jan 2025 15:33:39 +0100 Subject: [PATCH 7/9] :zap: Compute `features` only once --- discord/guild.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 62bb1cf5fe..a08ed5abf2 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1873,8 +1873,11 @@ async def edit( if premium_progress_bar_enabled is not MISSING: fields["premium_progress_bar_enabled"] = premium_progress_bar_enabled + features: list[GuildFeature] = self.features.copy() + + features_modified: bool = False + if community is not MISSING: - features: list[str] = fields.get("features", self.features.copy()) if community: if ( "rules_channel_id" in fields @@ -1884,8 +1887,7 @@ async def edit( features.append("COMMUNITY") else: raise InvalidArgument( - "community field requires both rules_channel and" - " public_updates_channel fields to be provided" + "community field requires both rules_channel and public_updates_channel fields to be provided" ) else: if "COMMUNITY" in features: @@ -1894,44 +1896,36 @@ async def edit( if "public_updates_channel_id" in fields: fields["public_updates_channel_id"] = None features.remove("COMMUNITY") - - fields["features"] = features + features_modified = True if disable_invites is not MISSING: - features = fields.get("features", self.features.copy()) if disable_invites: if "INVITES_DISABLED" not in features: features.append("INVITES_DISABLED") else: if "INVITES_DISABLED" in features: features.remove("INVITES_DISABLED") - - fields["features"] = features + features_modified = True if discoverable is not MISSING: - features = fields.get("features", self.features.copy()) if discoverable: if "DISCOVERABLE" not in features: features.append("DISCOVERABLE") else: if "DISCOVERABLE" in features: features.remove("DISCOVERABLE") - - fields["features"] = features + features_modified = True if raid_alerts is not MISSING: - features = fields.get("features", self.features.copy()) if raid_alerts: if "RAID_ALERTS_DISABLED" in features: features.remove("RAID_ALERTS_DISABLED") else: if "RAID_ALERTS_DISABLED" not in features: features.append("RAID_ALERTS_DISABLED") - - fields["features"] = features + features_modified = True if enable_activity_feed is not MISSING: - features = fields.get("features", self.features.copy()) if enable_activity_feed: if "ACTIVITY_FEED_ENABLED_BY_USER" not in features: features.append("ACTIVITY_FEED_ENABLED_BY_USER") @@ -1942,7 +1936,9 @@ async def edit( features.remove("ACTIVITY_FEED_ENABLED_BY_USER") if "ACTIVITY_FEED_DISABLED_BY_USER" not in features: features.append("ACTIVITY_FEED_DISABLED_BY_USER") + features_modified = True + if features_modified: fields["features"] = features data = await http.edit_guild(self.id, reason=reason, **fields) From 9894c4e6d992a1269ef674f77e73d55248d901f0 Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:22:41 +0300 Subject: [PATCH 8/9] Remove variable --- discord/guild.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index a08ed5abf2..d74b0d900c 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1875,8 +1875,6 @@ async def edit( features: list[GuildFeature] = self.features.copy() - features_modified: bool = False - if community is not MISSING: if community: if ( @@ -1896,7 +1894,6 @@ async def edit( if "public_updates_channel_id" in fields: fields["public_updates_channel_id"] = None features.remove("COMMUNITY") - features_modified = True if disable_invites is not MISSING: if disable_invites: @@ -1905,7 +1902,6 @@ async def edit( else: if "INVITES_DISABLED" in features: features.remove("INVITES_DISABLED") - features_modified = True if discoverable is not MISSING: if discoverable: @@ -1914,7 +1910,6 @@ async def edit( else: if "DISCOVERABLE" in features: features.remove("DISCOVERABLE") - features_modified = True if raid_alerts is not MISSING: if raid_alerts: @@ -1923,7 +1918,6 @@ async def edit( else: if "RAID_ALERTS_DISABLED" not in features: features.append("RAID_ALERTS_DISABLED") - features_modified = True if enable_activity_feed is not MISSING: if enable_activity_feed: @@ -1936,9 +1930,8 @@ async def edit( features.remove("ACTIVITY_FEED_ENABLED_BY_USER") if "ACTIVITY_FEED_DISABLED_BY_USER" not in features: features.append("ACTIVITY_FEED_DISABLED_BY_USER") - features_modified = True - if features_modified: + if self.features != features: fields["features"] = features data = await http.edit_guild(self.id, reason=reason, **fields) From 9cb74b24d4b8467945feed3535c7b1172a8ba135 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 6 Jan 2025 08:46:34 +0100 Subject: [PATCH 9/9] :recycle: change `raid_alerts` to `enable_raid_alerts` --- discord/guild.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index d74b0d900c..58abfac6be 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1664,7 +1664,7 @@ async def edit( premium_progress_bar_enabled: bool = MISSING, disable_invites: bool = MISSING, discoverable: bool = MISSING, - raid_alerts: bool = MISSING, + enable_raid_alerts: bool = MISSING, enable_activity_feed: bool = MISSING, ) -> Guild: r"""|coro| @@ -1745,7 +1745,7 @@ async def edit( Whether the guild should have server invites enabled or disabled. discoverable: :class:`bool` Whether the guild should be discoverable in the discover tab. - raid_alerts: :class:`bool` + enable_raid_alerts: :class:`bool` Whether activity alerts for the guild should be enabled. enable_activity_feed: class:`bool` Whether the guild's user activity feed should be enabled.