From e2925d928d1c852b8b0ccad66b10d8aba7c6de94 Mon Sep 17 00:00:00 2001 From: Sengolda <79252176+Sengolda@users.noreply.github.com> Date: Sat, 24 Jun 2023 12:46:59 +0530 Subject: [PATCH 1/6] docs: Change color to colour (#2132) Signed-off-by: Sengolda <79252176+Sengolda@users.noreply.github.com> Co-authored-by: Lala Sabathil --- discord/colour.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/discord/colour.py b/discord/colour.py index c202351859..a8dbf7236a 100644 --- a/discord/colour.py +++ b/discord/colour.py @@ -335,8 +335,8 @@ def nitro_pink(cls: type[CT]) -> CT: @classmethod def embed_background(cls: type[CT], theme: str = "dark") -> CT: - """A factory method that returns a :class:`Color` corresponding to the - embed colors on discord clients, with a value of: + """A factory method that returns a :class:`Colour` corresponding to the + embed colours on discord clients, with a value of: - ``0x2B2D31`` (dark) - ``0xEEEFF1`` (light) @@ -347,7 +347,7 @@ def embed_background(cls: type[CT], theme: str = "dark") -> CT: Parameters ---------- theme: :class:`str` - The theme color to apply, must be one of "dark", "light", or "amoled". + The theme colour to apply, must be one of "dark", "light", or "amoled". """ themes_cls = { "dark": 0x2B2D31, From b8d19a5e922d40ae854b1a85803bdd12fb6d2ca2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 24 Jun 2023 08:13:41 +0000 Subject: [PATCH 2/6] chore(deps-dev): Update pytest requirement from ~=7.3.2 to ~=7.4.0 (#2140) Updates the requirements on [pytest](https://github.com/pytest-dev/pytest) to permit the latest version. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.3.2...7.4.0) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Lala Sabathil --- requirements/dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index b51e52c143..af4ec2cd25 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,6 +1,6 @@ -r _.txt pylint~=2.17.4 -pytest~=7.3.2 +pytest~=7.4.0 pytest-asyncio~=0.21.0 # pytest-order~=1.0.1 mypy~=1.3.0 From b10130272fda3e42b75bfcfceb6818e30dd00923 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 24 Jun 2023 08:21:10 +0000 Subject: [PATCH 3/6] chore(deps-dev): Update mypy requirement from ~=1.3.0 to ~=1.4.0 (#2135) Updates the requirements on [mypy](https://github.com/python/mypy) to permit the latest version. - [Commits](https://github.com/python/mypy/compare/v1.3.0...v1.4.0) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Lala Sabathil --- requirements/dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index af4ec2cd25..a62ccb7f74 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -3,7 +3,7 @@ pylint~=2.17.4 pytest~=7.4.0 pytest-asyncio~=0.21.0 # pytest-order~=1.0.1 -mypy~=1.3.0 +mypy~=1.4.0 coverage~=7.2 pre-commit==3.3.3 codespell==2.2.5 From b076bd3125baf60a0f626256ba897f0800e02631 Mon Sep 17 00:00:00 2001 From: Om <92863779+Om1609@users.noreply.github.com> Date: Sun, 25 Jun 2023 00:37:15 +0530 Subject: [PATCH 4/6] feat: add `suppress` and `allowed_mentions` parameters (#2138) * add undocmented parameters * docs and improved logic * style(pre-commit): auto fixes from pre-commit.com hooks * Changelog * style(pre-commit): auto fixes from pre-commit.com hooks --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- CHANGELOG.md | 3 +++ discord/interactions.py | 39 +++++++++++++++++++++++++++++++++++++++ discord/webhook/async_.py | 18 ++++++++++++++++-- discord/webhook/sync.py | 14 ++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb7bb88942..7e42278642 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,9 @@ These changes are available on the `master` branch, but have not yet been releas ([#2106](https://github.com/Pycord-Development/pycord/pull/2106)) - Added Annotated forms support for typehinting slash command options. ([#2124](https://github.com/Pycord-Development/pycord/pull/2124)) +- Added `suppress` and `allowed_mentions` parameters to `Webhook` and + `InteractionResponse` edit methods. + ([#2138](https://github.com/Pycord-Development/pycord/pull/2138)) ### Changed diff --git a/discord/interactions.py b/discord/interactions.py index 4a74edf201..83ca14f128 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -33,6 +33,7 @@ from .enums import InteractionResponseType, InteractionType, try_enum from .errors import ClientException, InteractionResponded, InvalidArgument from .file import File +from .flags import MessageFlags from .member import Member from .message import Attachment, Message from .object import Object @@ -386,6 +387,7 @@ async def edit_original_response( view: View | None = MISSING, allowed_mentions: AllowedMentions | None = None, delete_after: float | None = None, + suppress: bool = False, ) -> InteractionMessage: """|coro| @@ -424,6 +426,8 @@ async def edit_original_response( If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored. + suppress: :class:`bool` + Whether to suppress embeds for the message. Returns ------- @@ -453,6 +457,7 @@ async def edit_original_response( view=view, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, + suppress=suppress, ) adapter = async_context.get() http = self._state.http @@ -936,6 +941,8 @@ async def edit_message( attachments: list[Attachment] = MISSING, view: View | None = MISSING, delete_after: float | None = None, + suppress: bool | None = MISSING, + allowed_mentions: AllowedMentions | None = None, ) -> None: """|coro| @@ -966,6 +973,15 @@ async def edit_message( If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored. + suppress: Optional[:class:`bool`] + Whether to suppress embeds for the message. + allowed_mentions: Optional[:class:`~discord.AllowedMentions`] + Controls the mentions being processed in this message. If this is + passed, then the object is merged with :attr:`~discord.Client.allowed_mentions`. + The merging behaviour only overrides attributes that have been explicitly passed + to the object, otherwise it uses the attributes set in :attr:`~discord.Client.allowed_mentions`. + If no object is passed at all then the defaults given by :attr:`~discord.Client.allowed_mentions` + are used instead. Raises ------ @@ -1029,6 +1045,23 @@ async def edit_message( # we keep previous attachments when adding new files payload["attachments"] = [a.to_dict() for a in msg.attachments] + if suppress is not MISSING: + flags = MessageFlags._from_value(self._parent.message.flags.value) + flags.suppress_embeds = suppress + payload["flags"] = flags.value + + if allowed_mentions is None: + payload["allowed_mentions"] = ( + state.allowed_mentions and state.allowed_mentions.to_dict() + ) + + elif state.allowed_mentions is not None: + payload["allowed_mentions"] = state.allowed_mentions.merge( + allowed_mentions + ).to_dict() + else: + payload["allowed_mentions"] = allowed_mentions.to_dict() + adapter = async_context.get() http = parent._state.http try: @@ -1215,6 +1248,7 @@ async def edit( view: View | None = MISSING, allowed_mentions: AllowedMentions | None = None, delete_after: float | None = None, + suppress: bool | None = MISSING, ) -> InteractionMessage: """|coro| @@ -1247,6 +1281,8 @@ async def edit( If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored. + suppress: Optional[:class:`bool`] + Whether to suppress embeds for the message. Returns ------- @@ -1266,6 +1302,8 @@ async def edit( """ if attachments is MISSING: attachments = self.attachments or MISSING + if suppress is MISSING: + suppress = self.flags.suppress_embeds return await self._state._interaction.edit_original_response( content=content, embeds=embeds, @@ -1276,6 +1314,7 @@ async def edit( view=view, allowed_mentions=allowed_mentions, delete_after=delete_after, + suppress=suppress, ) async def delete(self, *, delay: float | None = None) -> None: diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index f7d98f80a9..3a98c4baca 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -47,6 +47,7 @@ InvalidArgument, NotFound, ) +from ..flags import MessageFlags from ..http import Route from ..message import Attachment, Message from ..mixins import Hashable @@ -622,6 +623,7 @@ def handle_message_parameters( view: View | None = MISSING, allowed_mentions: AllowedMentions | None = MISSING, previous_allowed_mentions: AllowedMentions | None = None, + suppress: bool = False, ) -> ExecuteWebhookParameters: if files is not MISSING and file is not MISSING: raise TypeError("Cannot mix file and files keyword arguments.") @@ -648,8 +650,9 @@ def handle_message_parameters( payload["avatar_url"] = str(avatar_url) if username: payload["username"] = username - if ephemeral: - payload["flags"] = 64 + + flags = MessageFlags(suppress_embeds=suppress, ephemeral=ephemeral) + payload["flags"] = flags.value if allowed_mentions: if previous_allowed_mentions is not None: @@ -827,6 +830,7 @@ async def edit( attachments: list[Attachment] = MISSING, view: View | None = MISSING, allowed_mentions: AllowedMentions | None = None, + suppress: bool | None = MISSING, ) -> WebhookMessage: """|coro| @@ -868,6 +872,8 @@ async def edit( the view is removed. .. versionadded:: 2.0 + suppress: Optional[:class:`bool`] + Whether to suppress embeds for the message. Returns ------- @@ -898,6 +904,9 @@ async def edit( if attachments is MISSING: attachments = self.attachments or MISSING + if suppress is MISSING: + suppress = self.flags.suppress_embeds + return await self._state._webhook.edit_message( self.id, content=content, @@ -909,6 +918,7 @@ async def edit( view=view, allowed_mentions=allowed_mentions, thread=thread, + suppress=suppress, ) async def delete(self, *, delay: float | None = None) -> None: @@ -1845,6 +1855,7 @@ async def edit_message( view: View | None = MISSING, allowed_mentions: AllowedMentions | None = None, thread: Snowflake | None = MISSING, + suppress: bool = False, ) -> WebhookMessage: """|coro| @@ -1892,6 +1903,8 @@ async def edit_message( .. versionadded:: 2.0 thread: Optional[:class:`~discord.abc.Snowflake`] The thread that contains the message. + suppress: :class:`bool` + Whether to suppress embeds for the message. Returns ------- @@ -1939,6 +1952,7 @@ async def edit_message( view=view, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, + suppress=suppress, ) thread_id: int | None = None diff --git a/discord/webhook/sync.py b/discord/webhook/sync.py index 042130ac25..9e812b5709 100644 --- a/discord/webhook/sync.py +++ b/discord/webhook/sync.py @@ -472,6 +472,7 @@ def edit( file: File = MISSING, files: list[File] = MISSING, allowed_mentions: AllowedMentions | None = None, + suppress: bool | None = MISSING, ) -> SyncWebhookMessage: """Edits the message. @@ -492,6 +493,8 @@ def edit( allowed_mentions: :class:`AllowedMentions` Controls the mentions being processed in this message. See :meth:`.abc.Messageable.send` for more information. + suppress: Optional[:class:`bool`] + Whether to suppress embeds for the message. Returns ------- @@ -517,6 +520,9 @@ def edit( elif isinstance(self.channel, Thread): thread = Object(self.channel.id) + if suppress is MISSING: + suppress = self.flags.suppress_embeds + return self._state._webhook.edit_message( self.id, content=content, @@ -526,6 +532,7 @@ def edit( files=files, allowed_mentions=allowed_mentions, thread=thread, + suppress=suppress, ) def delete(self, *, delay: float | None = None) -> None: @@ -952,6 +959,7 @@ def send( thread: Snowflake = MISSING, thread_name: str | None = None, wait: Literal[False] = ..., + suppress: bool = MISSING, ) -> None: ... @@ -970,6 +978,7 @@ def send( thread: Snowflake = MISSING, thread_name: str | None = None, wait: bool = False, + suppress: bool = False, ) -> SyncWebhookMessage | None: """Sends a message using the webhook. @@ -1022,6 +1031,8 @@ def send( The name of the thread to create. Only works for forum channels. .. versionadded:: 2.0 + suppress: :class:`bool` + Whether to suppress embeds for the message. Returns ------- @@ -1070,6 +1081,7 @@ def send( embeds=embeds, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, + suppress=suppress, ) adapter: WebhookAdapter = _get_webhook_adapter() thread_id: int | None = None @@ -1151,6 +1163,7 @@ def edit_message( files: list[File] = MISSING, allowed_mentions: AllowedMentions | None = None, thread: Snowflake | None = MISSING, + suppress: bool = False, ) -> SyncWebhookMessage: """Edits a message owned by this webhook. @@ -1211,6 +1224,7 @@ def edit_message( embeds=embeds, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, + suppress=suppress, ) adapter: WebhookAdapter = _get_webhook_adapter() From c5345d8b660d196c7b97522b58394bd457bc487e Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Sat, 24 Jun 2023 21:13:17 +0200 Subject: [PATCH 5/6] fix: update thread applied tags (#2146) * fix: update thread applied tags * chore: add changelog entry --------- Co-authored-by: Lala Sabathil --- CHANGELOG.md | 2 ++ discord/threads.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e42278642..aa6cbc5342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -142,6 +142,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2091](https://github.com/Pycord-Development/pycord/pull/2091)) - Fixed `AttributeError` when accessing a `Select`'s values when it hasn't been interacted with. ([#2104](https://github.com/Pycord-Development/pycord/pull/2104)) +- Fixed `Thread.applied_tags` not being updated. + ([#2146](https://github.com/Pycord-Development/pycord/pull/2146)) ## [2.4.1] - 2023-03-20 diff --git a/discord/threads.py b/discord/threads.py index 232fdbb66f..9a65997e52 100644 --- a/discord/threads.py +++ b/discord/threads.py @@ -247,6 +247,9 @@ def _update(self, data): except KeyError: pass + self._applied_tags: list[int] = [ + int(tag_id) for tag_id in data.get("applied_tags", []) + ] self.flags: ChannelFlags = ChannelFlags._from_value(data.get("flags", 0)) self.slowmode_delay = data.get("rate_limit_per_user", 0) From 27d7782cd750a34317a9813a5cef8e8b063ecade Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Sun, 25 Jun 2023 03:45:38 +0100 Subject: [PATCH 6/6] fix: always set Guild._member_count (#2145) * always set Guild._member_count * change set process * changelog --------- Co-authored-by: Lala Sabathil --- CHANGELOG.md | 2 ++ discord/guild.py | 24 ++++++++++-------------- discord/state.py | 8 ++------ 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa6cbc5342..ad1afa4959 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -142,6 +142,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2091](https://github.com/Pycord-Development/pycord/pull/2091)) - Fixed `AttributeError` when accessing a `Select`'s values when it hasn't been interacted with. ([#2104](https://github.com/Pycord-Development/pycord/pull/2104)) +- Fixed `Guild._member_count` sometimes not being set. + ([#2145](https://github.com/Pycord-Development/pycord/pull/2145)) - Fixed `Thread.applied_tags` not being updated. ([#2146](https://github.com/Pycord-Development/pycord/pull/2146)) diff --git a/discord/guild.py b/discord/guild.py index 9f1aae0c2b..2bd77b2dd5 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -383,7 +383,7 @@ def __repr__(self) -> str: ("name", self.name), ("shard_id", self.shard_id), ("chunked", self.chunked), - ("member_count", getattr(self, "_member_count", None)), + ("member_count", self._member_count), ) inner = " ".join("%s=%r" % t for t in attrs) return f"" @@ -441,11 +441,11 @@ def _remove_role(self, role_id: int, /) -> Role: return role def _from_data(self, guild: GuildPayload) -> None: - # according to Stan, this is always available even if the guild is unavailable - # I don't have this guarantee when someone updates the guild. - member_count = guild.get("member_count", None) - if member_count is not None: - self._member_count: int = member_count + member_count = guild.get("member_count") + # Either the payload includes member_count, or it hasn't been set yet. + # Prevents valid _member_count from suddenly changing to None + if member_count is not None or not hasattr(self, "_member_count"): + self._member_count: int | None = member_count self.name: str = guild.get("name") self.verification_level: VerificationLevel = try_enum( @@ -532,7 +532,7 @@ def _from_data(self, guild: GuildPayload) -> None: self._sync(guild) self._large: bool | None = ( - None if member_count is None else self._member_count >= 250 + None if self._member_count is None else self._member_count >= 250 ) self.owner_id: int | None = utils._get_as_snowflake(guild, "owner_id") @@ -598,10 +598,7 @@ def large(self) -> bool: members, which for this library is set to the maximum of 250. """ if self._large is None: - try: - return self._member_count >= 250 - except AttributeError: - return len(self._members) >= 250 + return (self._member_count or len(self._members)) >= 250 return self._large @property @@ -1002,10 +999,9 @@ def chunked(self) -> bool: If this value returns ``False``, then you should request for offline members. """ - count = getattr(self, "_member_count", None) - if count is None: + if self._member_count is None: return False - return count == len(self._members) + return self._member_count == len(self._members) @property def shard_id(self) -> int: diff --git a/discord/state.py b/discord/state.py index 4ae5c30b5a..d222ba4518 100644 --- a/discord/state.py +++ b/discord/state.py @@ -1139,10 +1139,8 @@ def parse_guild_member_add(self, data) -> None: if self.member_cache_flags.joined: guild._add_member(member) - try: + if guild._member_count is not None: guild._member_count += 1 - except AttributeError: - pass self.dispatch("member_join", member) @@ -1152,10 +1150,8 @@ def parse_guild_member_remove(self, data) -> None: guild = self._get_guild(int(data["guild_id"])) if guild is not None: - try: + if guild._member_count is not None: guild._member_count -= 1 - except AttributeError: - pass member = guild.get_member(user.id) if member is not None: