Skip to content

Commit

Permalink
Slash Attachments (Pycord-Development#579)
Browse files Browse the repository at this point in the history
* Note that attachments needs to be implemented

GPG Test

* add proto for attachment

* Attachment base logic (Needs rework)

* Update discord/types/interactions.py

Co-authored-by: Izhar Ahmad <54180221+nerdguyahmad@users.noreply.github.com>

* Parse received attachment

Co-authored-by: Izhar Ahmad <54180221+nerdguyahmad@users.noreply.github.com>
Co-authored-by: Dorukyum <doruk.ak@hotmail.com>
  • Loading branch information
3 people authored Feb 9, 2022
1 parent 8690471 commit 5806985
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
from ..enums import SlashCommandOptionType, ChannelType
from ..errors import ValidationError, ClientException
from ..member import Member
from ..message import Message
from ..message import Attachment, Message
from ..user import User
from ..utils import find, get_or_fetch, async_all, utcnow

Expand Down Expand Up @@ -752,6 +752,11 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
elif op.input_type == SlashCommandOptionType.string and (converter := op.converter) is not None:
arg = await converter.convert(converter, ctx, arg)

elif op.input_type == SlashCommandOptionType.attachment:
_data = ctx.interaction.data["resolved"]["attachments"][arg]
_data["id"] = int(arg)
arg = Attachment(state=ctx.interaction._state, data=_data)

kwargs[op._parameter_name] = arg

for o in self.options:
Expand Down
2 changes: 2 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ def from_datatype(cls, datatype):
return cls.channel
if datatype.__name__ == "Role":
return cls.role
if datatype.__name__ == "Attachment":
return cls.attachment
if datatype.__name__ == "Mentionable":
return cls.mentionable

Expand Down
7 changes: 5 additions & 2 deletions discord/types/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from __future__ import annotations

from typing import Optional, TYPE_CHECKING, Dict, TypedDict, Union, List, Literal

from .message import Attachment
from .snowflake import Snowflake
from .components import Component, ComponentType
from .embed import Embed
Expand Down Expand Up @@ -57,7 +59,7 @@ class _ApplicationCommandOptionOptional(TypedDict, total=False):
options: List[ApplicationCommandOption]


ApplicationCommandOptionType = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
ApplicationCommandOptionType = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]


class ApplicationCommandOption(_ApplicationCommandOptionOptional):
Expand Down Expand Up @@ -122,7 +124,7 @@ class _ApplicationCommandInteractionDataOptionBoolean(_ApplicationCommandInterac


class _ApplicationCommandInteractionDataOptionSnowflake(_ApplicationCommandInteractionDataOption):
type: Literal[6, 7, 8, 9]
type: Literal[6, 7, 8, 9, 11]
value: Snowflake


Expand Down Expand Up @@ -153,6 +155,7 @@ class ApplicationCommandInteractionDataResolved(TypedDict, total=False):
members: Dict[Snowflake, Member]
roles: Dict[Snowflake, Role]
channels: Dict[Snowflake, ApplicationCommandResolvedPartialChannel]
attachments: Dict[Snowflake, Attachment]


class _ApplicationCommandInteractionDataOptional(TypedDict, total=False):
Expand Down
6 changes: 4 additions & 2 deletions discord/types/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@

from __future__ import annotations

from typing import List, Literal, Optional, TypedDict, Union
from typing import List, Literal, Optional, TypedDict, Union, TYPE_CHECKING
from .snowflake import Snowflake, SnowflakeList
from .member import Member, UserWithMember
from .user import User
from .emoji import PartialEmoji
from .embed import Embed
from .channel import ChannelType
from .components import Component
from .interactions import MessageInteraction
from .sticker import StickerItem

if TYPE_CHECKING:
from .interactions import MessageInteraction


class ChannelMention(TypedDict):
id: Snowflake
Expand Down

0 comments on commit 5806985

Please sign in to comment.