Skip to content

Commit

Permalink
Merge branch 'master' into slash-group-hooks
Browse files Browse the repository at this point in the history
Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>
  • Loading branch information
OmLanke committed Jun 25, 2023
2 parents 563430e + 27d7782 commit 97b6641
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 27 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down Expand Up @@ -141,6 +144,10 @@ These changes are available on the `master` branch, but have not yet been releas
interacted with. ([#2104](https://github.com/Pycord-Development/pycord/pull/2104))
- Fixed `before_invoke` being run twice for slash subcommands.
([#2139](https://github.com/Pycord-Development/pycord/pull/2139))
- 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))

## [2.4.1] - 2023-03-20

Expand Down
6 changes: 3 additions & 3 deletions discord/colour.py
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
24 changes: 10 additions & 14 deletions discord/guild.py
Expand Up @@ -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"<Guild {inner}>"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
39 changes: 39 additions & 0 deletions discord/interactions.py
Expand Up @@ -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
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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
-------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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
------
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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
-------
Expand All @@ -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,
Expand All @@ -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:
Expand Down
8 changes: 2 additions & 6 deletions discord/state.py
Expand Up @@ -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)

Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions discord/threads.py
Expand Up @@ -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)

Expand Down
18 changes: 16 additions & 2 deletions discord/webhook/async_.py
Expand Up @@ -47,6 +47,7 @@
InvalidArgument,
NotFound,
)
from ..flags import MessageFlags
from ..http import Route
from ..message import Attachment, Message
from ..mixins import Hashable
Expand Down Expand Up @@ -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.")
Expand All @@ -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:
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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
-------
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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
-------
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 97b6641

Please sign in to comment.