Type hint instance variables in interactions
This commit is contained in:
parent
a8db8546db
commit
12e90f9c6d
@ -46,6 +46,7 @@ __all__ = (
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .types.interactions import (
|
from .types.interactions import (
|
||||||
Interaction as InteractionPayload,
|
Interaction as InteractionPayload,
|
||||||
|
InteractionData,
|
||||||
)
|
)
|
||||||
from .guild import Guild
|
from .guild import Guild
|
||||||
from .state import ConnectionState
|
from .state import ConnectionState
|
||||||
@ -107,23 +108,24 @@ class Interaction:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *, data: InteractionPayload, state: ConnectionState):
|
def __init__(self, *, data: InteractionPayload, state: ConnectionState):
|
||||||
self._state = state
|
self._state: ConnectionState = state
|
||||||
self._session: ClientSession = state.http._HTTPClient__session
|
self._session: ClientSession = state.http._HTTPClient__session
|
||||||
self._from_data(data)
|
self._from_data(data)
|
||||||
|
|
||||||
def _from_data(self, data: InteractionPayload):
|
def _from_data(self, data: InteractionPayload):
|
||||||
self.id = int(data['id'])
|
self.id: int = int(data['id'])
|
||||||
self.type = try_enum(InteractionType, data['type'])
|
self.type: InteractionType = try_enum(InteractionType, data['type'])
|
||||||
self.data = data.get('data')
|
self.data: Optional[InteractionData] = data.get('data')
|
||||||
self.token = data['token']
|
self.token: str = data['token']
|
||||||
self.version = data['version']
|
self.version: int = data['version']
|
||||||
self.channel_id = utils._get_as_snowflake(data, 'channel_id')
|
self.channel_id: Optional[int] = utils._get_as_snowflake(data, 'channel_id')
|
||||||
self.guild_id = utils._get_as_snowflake(data, 'guild_id')
|
self.guild_id: Optional[int] = utils._get_as_snowflake(data, 'guild_id')
|
||||||
self.application_id = utils._get_as_snowflake(data, 'application_id')
|
self.application_id: Optional[int] = utils._get_as_snowflake(data, 'application_id')
|
||||||
|
|
||||||
channel = self.channel or Object(id=self.channel_id)
|
channel = self.channel or Object(id=self.channel_id) # type: ignore
|
||||||
|
self.message: Optional[Message]
|
||||||
try:
|
try:
|
||||||
self.message = Message(state=self._state, channel=channel, data=data['message'])
|
self.message = Message(state=self._state, channel=channel, data=data['message']) # type: ignore
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.message = None
|
self.message = None
|
||||||
|
|
||||||
@ -133,7 +135,7 @@ class Interaction:
|
|||||||
if self.guild_id:
|
if self.guild_id:
|
||||||
guild = self.guild or Object(id=self.guild_id)
|
guild = self.guild or Object(id=self.guild_id)
|
||||||
try:
|
try:
|
||||||
self.user = Member(state=self._state, guild=guild, data=data['member'])
|
self.user = Member(state=self._state, guild=guild, data=data['member']) # type: ignore
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -97,37 +97,27 @@ class _ApplicationCommandInteractionDataOption(TypedDict):
|
|||||||
name: str
|
name: str
|
||||||
|
|
||||||
|
|
||||||
class _ApplicationCommandInteractionDataOptionSubcommand(
|
class _ApplicationCommandInteractionDataOptionSubcommand(_ApplicationCommandInteractionDataOption):
|
||||||
_ApplicationCommandInteractionDataOption
|
|
||||||
):
|
|
||||||
type: Literal[1, 2]
|
type: Literal[1, 2]
|
||||||
options: List[ApplicationCommandInteractionDataOption]
|
options: List[ApplicationCommandInteractionDataOption]
|
||||||
|
|
||||||
|
|
||||||
class _ApplicationCommandInteractionDataOptionString(
|
class _ApplicationCommandInteractionDataOptionString(_ApplicationCommandInteractionDataOption):
|
||||||
_ApplicationCommandInteractionDataOption
|
|
||||||
):
|
|
||||||
type: Literal[3]
|
type: Literal[3]
|
||||||
value: str
|
value: str
|
||||||
|
|
||||||
|
|
||||||
class _ApplicationCommandInteractionDataOptionInteger(
|
class _ApplicationCommandInteractionDataOptionInteger(_ApplicationCommandInteractionDataOption):
|
||||||
_ApplicationCommandInteractionDataOption
|
|
||||||
):
|
|
||||||
type: Literal[4]
|
type: Literal[4]
|
||||||
value: int
|
value: int
|
||||||
|
|
||||||
|
|
||||||
class _ApplicationCommandInteractionDataOptionBoolean(
|
class _ApplicationCommandInteractionDataOptionBoolean(_ApplicationCommandInteractionDataOption):
|
||||||
_ApplicationCommandInteractionDataOption
|
|
||||||
):
|
|
||||||
type: Literal[5]
|
type: Literal[5]
|
||||||
value: bool
|
value: bool
|
||||||
|
|
||||||
|
|
||||||
class _ApplicationCommandInteractionDataOptionSnowflake(
|
class _ApplicationCommandInteractionDataOptionSnowflake(_ApplicationCommandInteractionDataOption):
|
||||||
_ApplicationCommandInteractionDataOption
|
|
||||||
):
|
|
||||||
type: Literal[6, 7, 8, 9]
|
type: Literal[6, 7, 8, 9]
|
||||||
value: Snowflake
|
value: Snowflake
|
||||||
|
|
||||||
@ -174,8 +164,11 @@ class ComponentInteractionData(_ComponentInteractionDataOptional):
|
|||||||
component_type: ComponentType
|
component_type: ComponentType
|
||||||
|
|
||||||
|
|
||||||
|
InteractionData = Union[ApplicationCommandInteractionData, ComponentInteractionData]
|
||||||
|
|
||||||
|
|
||||||
class _InteractionOptional(TypedDict, total=False):
|
class _InteractionOptional(TypedDict, total=False):
|
||||||
data: Union[ApplicationCommandInteractionData, ComponentInteractionData]
|
data: InteractionData
|
||||||
guild_id: Snowflake
|
guild_id: Snowflake
|
||||||
channel_id: Snowflake
|
channel_id: Snowflake
|
||||||
member: Member
|
member: Member
|
||||||
|
Loading…
x
Reference in New Issue
Block a user