Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions interactions/api/http/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from ...api.cache import Cache
from ..models.attrs_utils import MISSING
from ..models.message import Embed, Message, MessageInteraction, Sticker
from ..models.misc import File, Snowflake
from ..models.message import Embed, Message, Sticker
from ..models.misc import AllowedMentions, File, Snowflake
from .request import _Request
from .route import Route

Expand All @@ -26,7 +26,7 @@ async def send_message(
tts: bool = False,
embeds: Optional[List[Embed]] = None,
nonce: Union[int, str] = None,
allowed_mentions: Optional[MessageInteraction] = None, # don't know type
allowed_mentions: Optional[Union[AllowedMentions, dict]] = None,
message_reference: Optional[Message] = None,
stickers: Optional[List[Sticker]] = None,
) -> dict:
Expand All @@ -49,7 +49,11 @@ async def send_message(
payload["nonce"] = nonce

if allowed_mentions:
payload["allowed_mentions"] = allowed_mentions
payload["allowed_mentions"] = (
allowed_mentions._json
if isinstance(allowed_mentions, AllowedMentions)
else allowed_mentions
)

if message_reference:
payload["message_reference"] = message_reference
Expand Down
18 changes: 12 additions & 6 deletions interactions/api/models/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
field,
)
from .flags import Permissions
from .misc import File, IDMixin, Overwrite, Snowflake
from .misc import AllowedMentions, File, IDMixin, Overwrite, Snowflake
from .user import User
from .webhook import Webhook

if TYPE_CHECKING:
from ...client.models.component import ActionRow, Button, SelectMenu
from .guild import Invite, InviteTargetType
from .member import Member
from .message import Attachment, Embed, Message, MessageInteraction, Sticker
from .message import Attachment, Embed, Message, Sticker

__all__ = (
"ChannelType",
Expand Down Expand Up @@ -198,7 +198,7 @@ async def send(
attachments: Optional[List["Attachment"]] = MISSING,
files: Optional[Union[File, List[File]]] = MISSING,
embeds: Optional[Union["Embed", List["Embed"]]] = MISSING,
allowed_mentions: Optional["MessageInteraction"] = MISSING,
allowed_mentions: Optional[Union[AllowedMentions, dict]] = MISSING,
stickers: Optional[List["Sticker"]] = MISSING,
components: Optional[
Union[
Expand All @@ -224,8 +224,8 @@ async def send(
:type attachments?: Optional[List[Attachment]]
:param embeds?: An embed, or list of embeds for the message.
:type embeds?: Optional[Union[Embed, List[Embed]]]
:param allowed_mentions?: The message interactions/mention limits that the message can refer to.
:type allowed_mentions?: Optional[MessageInteraction]
:param allowed_mentions?: The allowed mentions for the message.
:type allowed_mentions?: Optional[Union[AllowedMentions, dict]]
:param stickers?: A list of stickers to send with your message. You can send up to 3 stickers per message.
:type stickers?: Optional[List[Sticker]]
:param components?: A component, or list of components for the message.
Expand All @@ -241,7 +241,13 @@ async def send(
_content: str = "" if content is MISSING else content
_tts: bool = False if tts is MISSING else tts
_attachments = [] if attachments is MISSING else [a._json for a in attachments]
_allowed_mentions: dict = {} if allowed_mentions is MISSING else allowed_mentions
_allowed_mentions: dict = (
{}
if allowed_mentions is MISSING
else allowed_mentions._json
if isinstance(allowed_mentions, AllowedMentions)
else allowed_mentions
)
_sticker_ids: list = (
[] if stickers is MISSING else [str(sticker.id) for sticker in stickers]
)
Expand Down
17 changes: 12 additions & 5 deletions interactions/api/models/gw.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
from .emoji import Emoji
from .guild import EventMetadata
from .member import Member
from .message import Embed, Message, MessageInteraction, Sticker
from .message import Embed, Message, Sticker
from .misc import (
AllowedMentions,
AutoModAction,
AutoModTriggerMetadata,
AutoModTriggerType,
Expand Down Expand Up @@ -417,7 +418,7 @@ async def send(
tts: Optional[bool] = MISSING,
files: Optional[Union[File, List[File]]] = MISSING,
embeds: Optional[Union[Embed, List[Embed]]] = MISSING,
allowed_mentions: Optional[MessageInteraction] = MISSING,
allowed_mentions: Optional[Union[AllowedMentions, dict]] = MISSING,
) -> Message:
"""
Sends a DM to the member.
Expand All @@ -432,8 +433,8 @@ async def send(
:type files?: Optional[Union[File, List[File]]]
:param embeds?: An embed, or list of embeds for the message.
:type embeds?: Optional[Union[Embed, List[Embed]]]
:param allowed_mentions?: The message interactions/mention limits that the message can refer to.
:type allowed_mentions?: Optional[MessageInteraction]
:param allowed_mentions?: The allowed mentions for the message.
:type allowed_mentions?: Optional[Union[AllowedMentions, dict]]
:return: The sent message as an object.
:rtype: Message
"""
Expand All @@ -449,7 +450,13 @@ async def send(
if not embeds or embeds is MISSING
else ([embed._json for embed in embeds] if isinstance(embeds, list) else [embeds._json])
)
_allowed_mentions: dict = {} if allowed_mentions is MISSING else allowed_mentions
_allowed_mentions: dict = (
{}
if allowed_mentions is MISSING
else allowed_mentions._json
if isinstance(allowed_mentions, AllowedMentions)
else allowed_mentions
)
if not components or components is MISSING:
_components = []
else:
Expand Down
18 changes: 12 additions & 6 deletions interactions/api/models/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from .attrs_utils import MISSING, ClientSerializerMixin, convert_int, convert_list, define, field
from .channel import Channel
from .flags import Permissions
from .misc import File, IDMixin, Snowflake
from .misc import AllowedMentions, File, IDMixin, Snowflake
from .role import Role
from .user import User

if TYPE_CHECKING:
from ...client.models.component import ActionRow, Button, SelectMenu
from .guild import Guild
from .message import Attachment, Embed, Message, MessageInteraction
from .message import Attachment, Embed, Message

__all__ = ("Member",)

Expand Down Expand Up @@ -222,7 +222,7 @@ async def send(
attachments: Optional[List["Attachment"]] = MISSING,
files: Optional[Union[File, List[File]]] = MISSING,
embeds: Optional[Union["Embed", List["Embed"]]] = MISSING,
allowed_mentions: Optional["MessageInteraction"] = MISSING,
allowed_mentions: Optional[Union[AllowedMentions, dict]] = MISSING,
) -> "Message":
"""
Sends a DM to the member.
Expand All @@ -239,8 +239,8 @@ async def send(
:type files?: Optional[Union[File, List[File]]]
:param embeds?: An embed, or list of embeds for the message.
:type embeds?: Optional[Union[Embed, List[Embed]]]
:param allowed_mentions?: The message interactions/mention limits that the message can refer to.
:type allowed_mentions?: Optional[MessageInteraction]
:param allowed_mentions?: The allowed mentions for the message.
:type allowed_mentions?: Optional[Union[AllowedMentions, dict]]
:return: The sent message as an object.
:rtype: Message
"""
Expand All @@ -257,7 +257,13 @@ async def send(
if not embeds or embeds is MISSING
else ([embed._json for embed in embeds] if isinstance(embeds, list) else [embeds._json])
)
_allowed_mentions: dict = {} if allowed_mentions is MISSING else allowed_mentions
_allowed_mentions: dict = (
{}
if allowed_mentions is MISSING
else allowed_mentions._json
if isinstance(allowed_mentions, AllowedMentions)
else allowed_mentions
)
if not components or components is MISSING:
_components = []
else:
Expand Down
31 changes: 21 additions & 10 deletions interactions/api/models/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .channel import Channel
from .emoji import Emoji
from .member import Member
from .misc import File, IDMixin, Snowflake
from .misc import AllowedMentions, File, IDMixin, Snowflake
from .team import Application
from .user import User

Expand Down Expand Up @@ -744,7 +744,6 @@ class Message(ClientSerializerMixin, IDMixin):
:ivar Optional[MessageActivity] activity?: Message activity object that's sent by Rich Presence
:ivar Optional[Application] application?: Application object that's sent by Rich Presence
:ivar Optional[MessageReference] message_reference?: Data showing the source of a message (crosspost, channel follow, add, pin, or replied message)
:ivar Optional[Any] allowed_mentions: The allowed mentions of roles attached in the message.
:ivar int flags: Message flags
:ivar Optional[MessageInteraction] interaction?: Message interaction object, if the message is sent by an interaction.
:ivar Optional[Channel] thread?: The thread that started from this message, if any, with a thread member object embedded.
Expand Down Expand Up @@ -846,7 +845,7 @@ async def edit(
files: Optional[Union[File, List[File]]] = MISSING,
embeds: Optional[Union["Embed", List["Embed"]]] = MISSING,
suppress_embeds: Optional[bool] = MISSING,
allowed_mentions: Optional["MessageInteraction"] = MISSING,
allowed_mentions: Optional[Union[AllowedMentions, dict]] = MISSING,
message_reference: Optional[MessageReference] = MISSING,
attachments: Optional[List["Attachment"]] = MISSING,
components: Optional[
Expand All @@ -873,8 +872,8 @@ async def edit(
:type embeds?: Optional[Union[Embed, List[Embed]]]
:param suppress_embeds?: Whether to suppress embeds in the message.
:type suppress_embeds?: Optional[bool]
:param allowed_mentions?: The message interactions/mention limits that the message can refer to.
:type allowed_mentions?: Optional[MessageInteraction]
:param allowed_mentions?: The allowed mentions for the message.
:type allowed_mentions?: Optional[Union[AllowedMentions, dict]]
:param attachments?: The attachments to attach to the message. Needs to be uploaded to the CDN first
:type attachments?: Optional[List[Attachment]]
:param components?: A component, or list of components for the message. If `[]` the components will be removed
Expand Down Expand Up @@ -922,7 +921,13 @@ async def edit(
else []
)

_allowed_mentions: dict = {} if allowed_mentions is MISSING else allowed_mentions
_allowed_mentions: dict = (
{}
if allowed_mentions is MISSING
else allowed_mentions._json
if isinstance(allowed_mentions, AllowedMentions)
else allowed_mentions
)
_message_reference: dict = {} if message_reference is MISSING else message_reference._json
if not components:
_components = []
Expand Down Expand Up @@ -961,7 +966,7 @@ async def reply(
embeds: Optional[Union["Embed", List["Embed"]]] = MISSING,
files: Optional[Union[File, List[File]]] = MISSING,
attachments: Optional[List["Attachment"]] = MISSING,
allowed_mentions: Optional["MessageInteraction"] = MISSING,
allowed_mentions: Optional[Union[AllowedMentions, dict]] = MISSING,
stickers: Optional[List["Sticker"]] = MISSING,
components: Optional[
Union[
Expand All @@ -987,8 +992,8 @@ async def reply(
:type files?: Optional[Union[File, List[File]]]
:param embeds?: An embed, or list of embeds for the message.
:type embeds?: Optional[Union[Embed, List[Embed]]]
:param allowed_mentions?: The message interactions/mention limits that the message can refer to.
:type allowed_mentions?: Optional[MessageInteraction]
:param allowed_mentions?: The allowed mentions for the message.
:type allowed_mentions?: Optional[Union[AllowedMentions, dict]]
:param components?: A component, or list of components for the message.
:type components?: Optional[Union[ActionRow, Button, SelectMenu, List[ActionRow], List[Button], List[SelectMenu]]]
:param stickers?: A list of stickers to send with your message. You can send up to 3 stickers per message.
Expand All @@ -1009,7 +1014,13 @@ async def reply(
if not embeds or embeds is MISSING
else ([embed._json for embed in embeds] if isinstance(embeds, list) else [embeds._json])
)
_allowed_mentions: dict = {} if allowed_mentions is MISSING else allowed_mentions
_allowed_mentions: dict = (
{}
if allowed_mentions is MISSING
else allowed_mentions._json
if isinstance(allowed_mentions, AllowedMentions)
else allowed_mentions
)
_message_reference = MessageReference(message_id=int(self.id))._json
_attachments = [] if attachments is MISSING else [a._json for a in attachments]
if not components or components is MISSING:
Expand Down
35 changes: 33 additions & 2 deletions interactions/api/models/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import datetime
from base64 import b64encode
from enum import IntEnum
from enum import Enum, IntEnum
from io import FileIO, IOBase
from logging import Logger
from math import floor
Expand All @@ -16,14 +16,16 @@

from ...base import get_logger
from ..error import LibraryException
from .attrs_utils import MISSING, DictSerializerMixin, define, field
from .attrs_utils import MISSING, DictSerializerMixin, convert_list, define, field

__all__ = (
"AutoModKeywordPresetTypes",
"AutoModTriggerType",
"AutoModMetaData",
"AutoModAction",
"AutoModTriggerMetadata",
"AllowedMentionType",
"AllowedMentions",
"Snowflake",
"Color",
"ClientStatus",
Expand Down Expand Up @@ -370,3 +372,32 @@ def filename(self) -> str:
Returns the name of the file.
"""
return self._name.split("/")[-1].split(".")[0]


class AllowedMentionType(str, Enum):
"""
An enumerable object representing the allowed mention types
"""

EVERYONE = "everyone"
USERS = "users"
ROLES = "roles"


@define()
class AllowedMentions(DictSerializerMixin):
"""
A class object representing the allowed mentions object

:ivar parse?: Optional[List[AllowedMentionType]]: An array of allowed mention types to parse from the content.
:ivar users?: Optional[List[int]]: An array of user ids to mention.
:ivar roles?: Optional[List[int]]: An array of role ids to mention.
:ivar replied_user?: Optional[bool]: For replies, whether to mention the author of the message being replied to.
"""

parse: Optional[List[AllowedMentionType]] = field(
converter=convert_list(AllowedMentionType), default=None
)
users: Optional[List[int]] = field(default=None)
roles: Optional[List[int]] = field(default=None)
replied_user: Optional[bool] = field(default=None)
16 changes: 11 additions & 5 deletions interactions/api/models/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from ..error import LibraryException
from .attrs_utils import MISSING, ClientSerializerMixin, define, field
from .misc import File, IDMixin, Image, Snowflake
from .misc import AllowedMentions, File, IDMixin, Image, Snowflake
from .user import User

if TYPE_CHECKING:
Expand Down Expand Up @@ -180,7 +180,7 @@ async def execute(
avatar_url: Optional[str] = MISSING,
tts: Optional[bool] = MISSING,
embeds: Optional[Union["Embed", List["Embed"]]] = MISSING,
allowed_mentions: Any = MISSING,
allowed_mentions: Optional[Union[AllowedMentions, dict]] = MISSING,
attachments: Optional[List["Attachment"]] = MISSING,
components: Optional[
Union[
Expand Down Expand Up @@ -213,8 +213,8 @@ async def execute(
:type attachments?: Optional[List[Attachment]]
:param embeds: embedded ``rich`` content
:type embeds: Union[Embed, List[Embed]]
:param allowed_mentions: allowed mentions for the message
:type allowed_mentions: dict
:param allowed_mentions?: The allowed mentions for the message.
:type allowed_mentions?: Optional[Union[AllowedMentions, dict]]
:param components: the components to include with the message
:type components: Union[ActionRow, Button, SelectMenu, List[ActionRow], List[Button], List[SelectMenu]]
:param files: The files to attach to the message
Expand All @@ -240,7 +240,13 @@ async def execute(
if not embeds or embeds is MISSING
else ([embed._json for embed in embeds] if isinstance(embeds, list) else [embeds._json])
)
_allowed_mentions: dict = {} if allowed_mentions is MISSING else allowed_mentions
_allowed_mentions: dict = (
{}
if allowed_mentions is MISSING
else allowed_mentions._json
if isinstance(allowed_mentions, AllowedMentions)
else allowed_mentions
)

if not components or components is MISSING:
_components = []
Expand Down
Loading