mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
Fix type errors with required keys in the integration types
This commit is contained in:
parent
1ae40a11b7
commit
794327cdb4
@ -45,7 +45,7 @@ from .iterators import AuditLogIterator, MemberIterator
|
|||||||
from .widget import Widget
|
from .widget import Widget
|
||||||
from .asset import Asset
|
from .asset import Asset
|
||||||
from .flags import SystemChannelFlags
|
from .flags import SystemChannelFlags
|
||||||
from .integrations import BotIntegration, StreamIntegration, _integration_factory
|
from .integrations import Integration, _integration_factory
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'Guild',
|
'Guild',
|
||||||
@ -1805,7 +1805,7 @@ class Guild(Hashable):
|
|||||||
data = await self._state.http.get_all_integrations(self.id)
|
data = await self._state.http.get_all_integrations(self.id)
|
||||||
|
|
||||||
def convert(d):
|
def convert(d):
|
||||||
factory, itype = _integration_factory(d['type'])
|
factory, _ = _integration_factory(d['type'])
|
||||||
if factory is None:
|
if factory is None:
|
||||||
raise InvalidData('Unknown integration type {type!r} for integration ID {id}'.format_map(d))
|
raise InvalidData('Unknown integration type {type!r} for integration ID {id}'.format_map(d))
|
||||||
return factory(guild=self, data=d)
|
return factory(guild=self, data=d)
|
||||||
|
@ -43,6 +43,8 @@ if TYPE_CHECKING:
|
|||||||
from .types.integration import (
|
from .types.integration import (
|
||||||
IntegrationAccount as IntegrationAccountPayload,
|
IntegrationAccount as IntegrationAccountPayload,
|
||||||
Integration as IntegrationPayload,
|
Integration as IntegrationPayload,
|
||||||
|
StreamIntegration as StreamIntegrationPayload,
|
||||||
|
BotIntegration as BotIntegrationPayload,
|
||||||
IntegrationType,
|
IntegrationType,
|
||||||
IntegrationApplication as IntegrationApplicationPayload,
|
IntegrationApplication as IntegrationApplicationPayload,
|
||||||
)
|
)
|
||||||
@ -142,6 +144,7 @@ class Integration:
|
|||||||
"""
|
"""
|
||||||
await self._state.http.delete_integration(self.guild.id, self.id)
|
await self._state.http.delete_integration(self.guild.id, self.id)
|
||||||
|
|
||||||
|
|
||||||
class StreamIntegration(Integration):
|
class StreamIntegration(Integration):
|
||||||
"""Represents a stream integration for Twitch or YouTube.
|
"""Represents a stream integration for Twitch or YouTube.
|
||||||
|
|
||||||
@ -187,7 +190,7 @@ class StreamIntegration(Integration):
|
|||||||
'subscriber_count',
|
'subscriber_count',
|
||||||
)
|
)
|
||||||
|
|
||||||
def _from_data(self, data: IntegrationPayload) -> None:
|
def _from_data(self, data: StreamIntegrationPayload) -> None:
|
||||||
super()._from_data(data)
|
super()._from_data(data)
|
||||||
self.revoked: bool = data['revoked']
|
self.revoked: bool = data['revoked']
|
||||||
self.expire_behaviour: ExpireBehaviour = try_enum(ExpireBehaviour, data['expire_behavior'])
|
self.expire_behaviour: ExpireBehaviour = try_enum(ExpireBehaviour, data['expire_behavior'])
|
||||||
@ -290,6 +293,7 @@ class StreamIntegration(Integration):
|
|||||||
await self._state.http.sync_integration(self.guild.id, self.id)
|
await self._state.http.sync_integration(self.guild.id, self.id)
|
||||||
self.synced_at = datetime.datetime.now(datetime.timezone.utc)
|
self.synced_at = datetime.datetime.now(datetime.timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
class IntegrationApplication:
|
class IntegrationApplication:
|
||||||
"""Represents an application for a bot integration.
|
"""Represents an application for a bot integration.
|
||||||
|
|
||||||
@ -312,14 +316,14 @@ class IntegrationApplication:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
'icon',
|
'icon',
|
||||||
'description',
|
'description',
|
||||||
'summary',
|
'summary',
|
||||||
'user',
|
'user',
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *, data: IntegrationApplicationPayload, state):
|
def __init__(self, *, data: IntegrationApplicationPayload, state):
|
||||||
self.id: int = int(data['id'])
|
self.id: int = int(data['id'])
|
||||||
self.name: str = data['name']
|
self.name: str = data['name']
|
||||||
@ -329,9 +333,10 @@ class IntegrationApplication:
|
|||||||
user = data.get('bot')
|
user = data.get('bot')
|
||||||
self.user: Optional[User] = User(state=state, data=user) if user else None
|
self.user: Optional[User] = User(state=state, data=user) if user else None
|
||||||
|
|
||||||
|
|
||||||
class BotIntegration(Integration):
|
class BotIntegration(Integration):
|
||||||
"""Represents a bot integration on discord.
|
"""Represents a bot integration on discord.
|
||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
Attributes
|
Attributes
|
||||||
@ -354,9 +359,9 @@ class BotIntegration(Integration):
|
|||||||
The application tied to this integration.
|
The application tied to this integration.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = Integration.__slots__ + ('application',)
|
__slots__ = ('application',)
|
||||||
|
|
||||||
def _from_data(self, data: IntegrationPayload) -> None:
|
def _from_data(self, data: BotIntegrationPayload) -> None:
|
||||||
super()._from_data(data)
|
super()._from_data(data)
|
||||||
self.application = IntegrationApplication(data=data['application'], state=self._state)
|
self.application = IntegrationApplication(data=data['application'], state=self._state)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Literal, Optional, TypedDict
|
from typing import Literal, Optional, TypedDict, Union
|
||||||
from .snowflake import Snowflake
|
from .snowflake import Snowflake
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
||||||
@ -56,21 +56,27 @@ class PartialIntegration(TypedDict):
|
|||||||
account: IntegrationAccount
|
account: IntegrationAccount
|
||||||
|
|
||||||
|
|
||||||
class _IntegrationOptional(TypedDict, total=False):
|
|
||||||
role_id: Snowflake
|
|
||||||
enable_emoticons: bool
|
|
||||||
subscriber_count: int
|
|
||||||
revoked: bool
|
|
||||||
application: IntegrationApplication
|
|
||||||
|
|
||||||
|
|
||||||
IntegrationType = Literal['twitch', 'youtube', 'discord']
|
IntegrationType = Literal['twitch', 'youtube', 'discord']
|
||||||
|
|
||||||
|
|
||||||
class Integration(PartialIntegration, _IntegrationOptional):
|
class BaseIntegration(PartialIntegration):
|
||||||
enabled: bool
|
enabled: bool
|
||||||
syncing: bool
|
syncing: bool
|
||||||
synced_at: str
|
synced_at: str
|
||||||
user: User
|
user: User
|
||||||
expire_behavior: IntegrationExpireBehavior
|
expire_behavior: IntegrationExpireBehavior
|
||||||
expire_grace_period: int
|
expire_grace_period: int
|
||||||
|
|
||||||
|
|
||||||
|
class StreamIntegration(BaseIntegration):
|
||||||
|
role_id: Snowflake
|
||||||
|
enable_emoticons: bool
|
||||||
|
subscriber_count: int
|
||||||
|
revoked: bool
|
||||||
|
|
||||||
|
|
||||||
|
class BotIntegration(BaseIntegration):
|
||||||
|
application: IntegrationApplication
|
||||||
|
|
||||||
|
|
||||||
|
Integration = Union[BaseIntegration, StreamIntegration, BotIntegration]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user