Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for sending stickers #892

Merged
merged 11 commits into from
Jun 30, 2022
6 changes: 5 additions & 1 deletion interactions/api/http/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ...api.cache import Cache, Item
from ..models.attrs_utils import MISSING
from ..models.message import Embed, Message
from ..models.message import Embed, Message, Sticker
from ..models.misc import File, Snowflake
from .request import _Request
from .route import Route
Expand All @@ -29,6 +29,7 @@ async def send_message(
nonce: Union[int, str] = None,
allowed_mentions=None, # don't know type
message_reference: Optional[Message] = None,
stickers: Optional[List[Sticker]] = None,
) -> dict:
"""
A higher level implementation of :meth:`create_message()` that handles the payload dict internally.
Expand All @@ -54,6 +55,9 @@ async def send_message(
if message_reference:
payload["message_reference"] = message_reference

if stickers:
payload["sticker_ids"] = [str(sticker.id) for sticker in stickers]

# TODO: post-v4. add attachments to payload.

if isinstance(channel_id, Snowflake):
Expand Down
3 changes: 2 additions & 1 deletion interactions/api/http/message.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Optional, Union

from ...api.cache import Cache
from ..models.message import Embed, Message
from ..models.message import Embed, Message, Sticker
from ..models.attrs_utils import MISSING
from ..models.misc import File, Snowflake
from .request import _Request
Expand All @@ -21,6 +21,7 @@ class MessageRequest:
nonce: Union[int, str] = None,
allowed_mentions=None, # don't know type
message_reference: Optional[Message] = None,
stickers: Optional[List[Sticker]] = None,
) -> dict: ...
async def create_message(
self, payload: dict, channel_id: int, files: Optional[List[File]]
Expand Down
7 changes: 7 additions & 0 deletions interactions/api/models/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ async def send(
files: Optional[Union[File, List[File]]] = MISSING,
embeds: Optional[Union["Embed", List["Embed"]]] = MISSING, # noqa
allowed_mentions: Optional["MessageInteraction"] = MISSING, # noqa
stickers: Optional[List["Sticker"]] = MISSING, # noqa
components: Optional[
Union[
"ActionRow", # noqa
Expand All @@ -208,6 +209,8 @@ async def send(
: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 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.
:type components: Optional[Union[ActionRow, Button, SelectMenu, List[Actionrow], List[Button], List[SelectMenu]]]
:return: The sent message as an object.
Expand All @@ -222,6 +225,9 @@ async def send(
_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
_sticker_ids: list = (
[] if stickers is MISSING else [str(sticker.id) for sticker in stickers]
)
if not embeds or embeds is MISSING:
_embeds: list = []
elif isinstance(embeds, list):
Expand Down Expand Up @@ -251,6 +257,7 @@ async def send(
embeds=_embeds,
allowed_mentions=_allowed_mentions,
components=_components,
sticker_ids=_sticker_ids,
)

res = await self._client.create_message(
Expand Down
6 changes: 4 additions & 2 deletions interactions/api/models/channel.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ from typing import Any, Callable, List, Optional, Union

from .attrs_utils import ClientSerializerMixin, define
from .guild import Invite, InviteTargetType
from .message import Embed, Message, MessageInteraction
from .misc import File, IDMixin, Overwrite, Snowflake
from .message import Embed, Message, MessageInteraction, Sticker
from .misc import File, Overwrite, Snowflake
from .attrs_utils import MISSING
from .user import User
from .webhook import Webhook
from ... import ActionRow, Button, SelectMenu
Expand Down Expand Up @@ -82,6 +83,7 @@ class Channel(ClientSerializerMixin, IDMixin):
embeds: Optional[Union[Embed, List[Embed]]] = ...,
allowed_mentions: Optional[MessageInteraction] = ...,
attachments: Optional[List["Attachment"]] = MISSING, # noqa
stickers: Optional[List["Sticker"]] = MISSING,
components: Optional[
Union[
"ActionRow",
Expand Down
1 change: 0 additions & 1 deletion interactions/api/models/gw.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ async def send(
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

if not components or components is MISSING:
_components = []
else:
Expand Down
2 changes: 1 addition & 1 deletion interactions/api/models/gw.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class GuildMember(ClientSerializerMixin):
tts: Optional[bool] = ...,
files: Optional[Union[File, List[File]]] = ...,
embeds: Optional[Union[Embed, List[Embed]]] = ...,
allowed_mentions: Optional[MessageInteraction] = ...
allowed_mentions: Optional[MessageInteraction] = ...,
) -> Message: ...
async def modify(
self,
Expand Down
2 changes: 0 additions & 2 deletions interactions/api/models/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ async def send(
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

if not components or components is MISSING:
_components = []
else:
Expand All @@ -277,7 +276,6 @@ async def send(
components=_components,
allowed_mentions=_allowed_mentions,
)

channel = Channel(**await self._client.create_dm(recipient_id=int(self.user.id)))
res = await self._client.create_message(
channel_id=int(channel.id), payload=payload, files=files
Expand Down
2 changes: 1 addition & 1 deletion interactions/api/models/member.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Member(ClientSerializerMixin, IDMixin):
tts: Optional[bool] = ...,
files: Optional[Union[File, List[File]]] = ...,
embeds: Optional[Union[Embed, List[Embed]]] = ...,
allowed_mentions: Optional[MessageInteraction] = ...
allowed_mentions: Optional[MessageInteraction] = ...,
) -> Message: ...
async def modify(
self,
Expand Down
7 changes: 7 additions & 0 deletions interactions/api/models/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ async def reply(
files: Optional[Union[File, List[File]]] = MISSING,
attachments: Optional[List["Attachment"]] = MISSING,
allowed_mentions: Optional["MessageInteraction"] = MISSING,
stickers: Optional[List["Sticker"]] = MISSING,
components: Optional[
Union[
"ActionRow", # noqa
Expand Down Expand Up @@ -1061,6 +1062,8 @@ async def reply(
:type allowed_mentions: Optional[MessageInteraction]
: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.
:type stickers: Optional[List[Sticker]]
:return: The sent message as an object.
:rtype: Message
"""
Expand Down Expand Up @@ -1094,6 +1097,9 @@ async def reply(
files = [files]

_files.extend(_attachments)
_sticker_ids: list = (
[] if stickers is MISSING else [str(sticker.id) for sticker in stickers]
)

payload = dict(
content=_content,
Expand All @@ -1103,6 +1109,7 @@ async def reply(
message_reference=_message_reference,
allowed_mentions=_allowed_mentions,
components=_components,
sticker_ids=_sticker_ids,
)

res = await self._client.create_message(
Expand Down
1 change: 1 addition & 0 deletions interactions/api/models/message.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class Message(ClientSerializerMixin, IDMixin):
embeds: Optional[Union[Embed, List[Embed]]] = MISSING,
allowed_mentions: Optional[MessageInteraction] = MISSING,
attachments: Optional[List["Attachment"]] = MISSING, # noqa
stickers: Optional[List["Sticker"]] = MISSING,
components: Optional[
Union[
ActionRow,
Expand Down