Apply global allowed_mentions setting (#76)
Some checks failed
Deploy MkDocs / deploy (push) Has been cancelled

This commit is contained in:
Slipstream 2025-06-13 22:10:19 -06:00 committed by GitHub
parent ffdb922142
commit f58ffe8321
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 31 additions and 22 deletions

View File

@ -126,8 +126,8 @@ client = disagreement.Client(
)
```
This dictionary is used whenever ``send_message`` is called without an explicit
``allowed_mentions`` argument.
This dictionary is used whenever ``send_message`` or helpers like ``Message.reply``
are called without an explicit ``allowed_mentions`` argument.
### Defining Subcommands with `AppCommandGroup`

View File

@ -253,6 +253,8 @@ class AppCommandContext:
Optional[Message]: The sent message object if a new message was created and not ephemeral.
None if the response was ephemeral or an edit to a deferred message.
"""
if allowed_mentions is None:
allowed_mentions = getattr(self.bot, "allowed_mentions", None)
if not self._responded and self._deferred: # Editing a deferred response
# Use edit_original_interaction_response
payload: Dict[str, Any] = {}
@ -393,6 +395,9 @@ class AppCommandContext:
"Must acknowledge or defer the interaction before sending a followup."
)
if allowed_mentions is None:
allowed_mentions = getattr(self.bot, "allowed_mentions", None)
payload: Dict[str, Any] = {}
if content is not None:
payload["content"] = content
@ -473,6 +478,9 @@ class AppCommandContext:
"Cannot edit response if interaction hasn't been responded to or deferred."
)
if allowed_mentions is None:
allowed_mentions = getattr(self.bot, "allowed_mentions", None)
payload: Dict[str, Any] = {}
if content is not None:
payload["content"] = content # Use None to clear

View File

@ -250,15 +250,15 @@ class CommandContext:
client's :attr:`mention_replies` value is used.
"""
allowed_mentions = kwargs.pop("allowed_mentions", None)
if mention_author is None:
mention_author = getattr(self.bot, "mention_replies", False)
if allowed_mentions is None:
allowed_mentions = {"replied_user": mention_author}
else:
allowed_mentions = dict(allowed_mentions)
allowed_mentions.setdefault("replied_user", mention_author)
allowed_mentions = kwargs.pop("allowed_mentions", None)
if mention_author is None:
mention_author = getattr(self.bot, "mention_replies", False)
if allowed_mentions is None:
allowed_mentions = dict(getattr(self.bot, "allowed_mentions", {}) or {})
else:
allowed_mentions = dict(allowed_mentions)
allowed_mentions.setdefault("replied_user", mention_author)
return await self.bot.send_message(
channel_id=self.message.channel_id,

View File

@ -194,14 +194,14 @@ class Message:
ValueError: If both `embed` and `embeds` are provided.
"""
# Determine allowed mentions for the reply
if mention_author is None:
mention_author = getattr(self._client, "mention_replies", False)
if allowed_mentions is None:
allowed_mentions = {"replied_user": mention_author}
else:
allowed_mentions = dict(allowed_mentions)
allowed_mentions.setdefault("replied_user", mention_author)
if mention_author is None:
mention_author = getattr(self._client, "mention_replies", False)
if allowed_mentions is None:
allowed_mentions = dict(getattr(self._client, "allowed_mentions", {}) or {})
else:
allowed_mentions = dict(allowed_mentions)
allowed_mentions.setdefault("replied_user", mention_author)
# Client.send_message is already updated to handle these parameters
return await self._client.send_message(

View File

@ -125,8 +125,8 @@ client = disagreement.Client(
)
```
This dictionary is used whenever ``send_message`` is called without an explicit
``allowed_mentions`` argument.
This dictionary is used whenever ``send_message`` or helpers like ``Message.reply``
are called without an explicit ``allowed_mentions`` argument.
The :class:`AllowedMentions` class offers ``none()`` and ``all()`` helpers for
quickly generating these configurations.

View File

@ -15,7 +15,8 @@ client = disagreement.Client(
)
```
When ``Client.send_message`` is called without an explicit ``allowed_mentions``
When ``Client.send_message`` or convenience methods like ``Message.reply`` and
``CommandContext.reply`` are called without an explicit ``allowed_mentions``
argument this value will be used.
``AllowedMentions`` also provides the convenience methods