mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-22 08:44:10 +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 .asset import Asset
|
||||
from .flags import SystemChannelFlags
|
||||
from .integrations import BotIntegration, StreamIntegration, _integration_factory
|
||||
from .integrations import Integration, _integration_factory
|
||||
|
||||
__all__ = (
|
||||
'Guild',
|
||||
@ -1805,7 +1805,7 @@ class Guild(Hashable):
|
||||
data = await self._state.http.get_all_integrations(self.id)
|
||||
|
||||
def convert(d):
|
||||
factory, itype = _integration_factory(d['type'])
|
||||
factory, _ = _integration_factory(d['type'])
|
||||
if factory is None:
|
||||
raise InvalidData('Unknown integration type {type!r} for integration ID {id}'.format_map(d))
|
||||
return factory(guild=self, data=d)
|
||||
|
@ -43,6 +43,8 @@ if TYPE_CHECKING:
|
||||
from .types.integration import (
|
||||
IntegrationAccount as IntegrationAccountPayload,
|
||||
Integration as IntegrationPayload,
|
||||
StreamIntegration as StreamIntegrationPayload,
|
||||
BotIntegration as BotIntegrationPayload,
|
||||
IntegrationType,
|
||||
IntegrationApplication as IntegrationApplicationPayload,
|
||||
)
|
||||
@ -142,6 +144,7 @@ class Integration:
|
||||
"""
|
||||
await self._state.http.delete_integration(self.guild.id, self.id)
|
||||
|
||||
|
||||
class StreamIntegration(Integration):
|
||||
"""Represents a stream integration for Twitch or YouTube.
|
||||
|
||||
@ -187,7 +190,7 @@ class StreamIntegration(Integration):
|
||||
'subscriber_count',
|
||||
)
|
||||
|
||||
def _from_data(self, data: IntegrationPayload) -> None:
|
||||
def _from_data(self, data: StreamIntegrationPayload) -> None:
|
||||
super()._from_data(data)
|
||||
self.revoked: bool = data['revoked']
|
||||
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)
|
||||
self.synced_at = datetime.datetime.now(datetime.timezone.utc)
|
||||
|
||||
|
||||
class IntegrationApplication:
|
||||
"""Represents an application for a bot integration.
|
||||
|
||||
@ -312,14 +316,14 @@ class IntegrationApplication:
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
'id',
|
||||
'name',
|
||||
'icon',
|
||||
'description',
|
||||
'summary',
|
||||
'id',
|
||||
'name',
|
||||
'icon',
|
||||
'description',
|
||||
'summary',
|
||||
'user',
|
||||
)
|
||||
|
||||
|
||||
def __init__(self, *, data: IntegrationApplicationPayload, state):
|
||||
self.id: int = int(data['id'])
|
||||
self.name: str = data['name']
|
||||
@ -329,9 +333,10 @@ class IntegrationApplication:
|
||||
user = data.get('bot')
|
||||
self.user: Optional[User] = User(state=state, data=user) if user else None
|
||||
|
||||
|
||||
class BotIntegration(Integration):
|
||||
"""Represents a bot integration on discord.
|
||||
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
Attributes
|
||||
@ -354,9 +359,9 @@ class BotIntegration(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)
|
||||
self.application = IntegrationApplication(data=data['application'], state=self._state)
|
||||
|
||||
|
@ -24,7 +24,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Literal, Optional, TypedDict
|
||||
from typing import Literal, Optional, TypedDict, Union
|
||||
from .snowflake import Snowflake
|
||||
from .user import User
|
||||
|
||||
@ -56,21 +56,27 @@ class PartialIntegration(TypedDict):
|
||||
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']
|
||||
|
||||
|
||||
class Integration(PartialIntegration, _IntegrationOptional):
|
||||
class BaseIntegration(PartialIntegration):
|
||||
enabled: bool
|
||||
syncing: bool
|
||||
synced_at: str
|
||||
user: User
|
||||
expire_behavior: IntegrationExpireBehavior
|
||||
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