mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-11 19:07:28 +03:00
feat(interactions): ApplicationCommandData
This commit is contained in:
parent
2b5df990b0
commit
dc22ad5a41
1 changed files with 59 additions and 1 deletions
|
@ -3,11 +3,14 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any, Optional, List
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from .commands import ApplicationCommandType
|
||||||
|
from .commands import SlashCommandInteractionDataOption
|
||||||
|
from ...utils.conversion import try_enum
|
||||||
from ...models.guild import Channel, Role, _choose_channel_type, GuildMember
|
from ...models.guild import Channel, Role, _choose_channel_type, GuildMember
|
||||||
from ...utils.api_model import APIModelBase
|
from ...utils.api_model import APIModelBase
|
||||||
from ...models.message.message import Message
|
from ...models.message.message import Message
|
||||||
|
@ -107,3 +110,58 @@ class ResolvedData(APIModelBase):
|
||||||
self.users[Snowflake(_id)] = User.from_dict(value)
|
self.users[Snowflake(_id)] = User.from_dict(value)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(repr=False)
|
||||||
|
class ApplicationCommandData(APIModelBase):
|
||||||
|
"""Application Command Data
|
||||||
|
|
||||||
|
Attributes
|
||||||
|
----------
|
||||||
|
id: :class:`~melisa.utils.types.snowflake.Snowflake`
|
||||||
|
The ID of the invoked command
|
||||||
|
name: str
|
||||||
|
The name of the invoked command
|
||||||
|
type: :class:`~melisa.models.interactions.commands.ApplicationCommandType`
|
||||||
|
Type of the application command
|
||||||
|
resolved: Optional[:class:`~melisa.models.interactions.interactions.ResolvedData`]
|
||||||
|
Data resolved from the interaction
|
||||||
|
options: Optional[List[:class:`~melisa.models.interactions.commands.SlashCommandInteractionDataOption`]]
|
||||||
|
List of application command interaction data option the params + values from the user
|
||||||
|
guild_id: Optional[:class:`~melisa.utils.types.snowflake.Snowflake`]
|
||||||
|
The id of the guild the command is registered to
|
||||||
|
target_id: Optional[:class:`~melisa.utils.types.snowflake.Snowflake`]
|
||||||
|
Id of the user or message targeted by a user or message command
|
||||||
|
"""
|
||||||
|
|
||||||
|
id: Snowflake = None
|
||||||
|
name: str = None
|
||||||
|
type: ApplicationCommandType = None
|
||||||
|
resolved: Optional[ResolvedData] = None
|
||||||
|
options: Optional[List[SlashCommandInteractionDataOption]] = None
|
||||||
|
guild_id: Optional[Snowflake] = None
|
||||||
|
target_id: Optional[Snowflake] = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, data: Dict[str, Any]):
|
||||||
|
"""Generate a ApplicationCommandData from the given data.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
data: :class:`dict`
|
||||||
|
The dictionary to convert into a ApplicationCommandData.
|
||||||
|
"""
|
||||||
|
self: ApplicationCommandData = super().__new__(cls)
|
||||||
|
|
||||||
|
self.id = Snowflake(data.get("id", 0))
|
||||||
|
self.name = data.get("name")
|
||||||
|
self.type = try_enum(ApplicationCommandType, data.get("type"))
|
||||||
|
self.resolved = ResolvedData.from_dict(data.get("resolved", {}))
|
||||||
|
self.options = [
|
||||||
|
SlashCommandInteractionDataOption.from_dict(option)
|
||||||
|
for option in data.get("options", [])
|
||||||
|
]
|
||||||
|
self.guild_id = Snowflake(data.get("guild_id", 0))
|
||||||
|
self.target_id = Snowflake(data.get("target_id", 0))
|
||||||
|
|
||||||
|
return self
|
||||||
|
|
Loading…
Reference in a new issue