diff options
| author | Nadir Chowdhury <[email protected]> | 2021-04-10 07:53:24 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-04-10 02:53:24 -0400 |
| commit | 3e92196a2bdcf57dfcbd8e277737345af1d35330 (patch) | |
| tree | 381dba2a0401a016beebc4200af09eb34d149f94 /discord/integrations.py | |
| parent | [commands]Add typing.Literal converter (diff) | |
| download | discord.py-3e92196a2bdcf57dfcbd8e277737345af1d35330.tar.xz discord.py-3e92196a2bdcf57dfcbd8e277737345af1d35330.zip | |
Add typings for audit logs, integrations, and webhooks
Diffstat (limited to 'discord/integrations.py')
| -rw-r--r-- | discord/integrations.py | 74 |
1 files changed, 57 insertions, 17 deletions
diff --git a/discord/integrations.py b/discord/integrations.py index 34458adc..8a804bc3 100644 --- a/discord/integrations.py +++ b/discord/integrations.py @@ -22,7 +22,10 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ +from __future__ import annotations + import datetime +from typing import Optional, TYPE_CHECKING, overload from .utils import _get_as_snowflake, get, parse_time from .user import User from .errors import InvalidArgument @@ -33,6 +36,14 @@ __all__ = ( 'Integration', ) +if TYPE_CHECKING: + from .types.integration import ( + IntegrationAccount as IntegrationAccountPayload, + Integration as IntegrationPayload, + ) + from .guild import Guild + + class IntegrationAccount: """Represents an integration account. @@ -48,13 +59,14 @@ class IntegrationAccount: __slots__ = ('id', 'name') - def __init__(self, **kwargs): - self.id = kwargs.pop('id') - self.name = kwargs.pop('name') + def __init__(self, data: IntegrationAccountPayload) -> None: + self.id: Optional[int] = _get_as_snowflake(data, 'id') + self.name: str = data.pop('name') - def __repr__(self): + def __repr__(self) -> str: return f'<IntegrationAccount id={self.id} name={self.name!r}>' + class Integration: """Represents a guild integration. @@ -90,20 +102,34 @@ class Integration: An aware UTC datetime representing when the integration was last synced. """ - __slots__ = ('id', '_state', 'guild', 'name', 'enabled', 'type', - 'syncing', 'role', 'expire_behaviour', 'expire_behavior', - 'expire_grace_period', 'synced_at', 'user', 'account', - 'enable_emoticons', '_role_id') - - def __init__(self, *, data, guild): + __slots__ = ( + 'id', + '_state', + 'guild', + 'name', + 'enabled', + 'type', + 'syncing', + 'role', + 'expire_behaviour', + 'expire_behavior', + 'expire_grace_period', + 'synced_at', + 'user', + 'account', + 'enable_emoticons', + '_role_id', + ) + + def __init__(self, *, data: IntegrationPayload, guild: Guild) -> None: self.guild = guild self._state = guild._state self._from_data(data) - def __repr__(self): + def __repr__(self) -> str: return f'<Integration id={self.id} name={self.name!r} type={self.type!r}>' - def _from_data(self, integ): + def _from_data(self, integ: IntegrationPayload): self.id = _get_as_snowflake(integ, 'id') self.name = integ['name'] self.type = integ['type'] @@ -118,9 +144,23 @@ class Integration: self.synced_at = parse_time(integ['synced_at']) self.user = User(state=self._state, data=integ['user']) - self.account = IntegrationAccount(**integ['account']) - - async def edit(self, **fields): + self.account = IntegrationAccount(integ['account']) + + @overload + async def edit( + self, + *, + expire_behaviour: Optional[ExpireBehaviour] = ..., + expire_grace_period: Optional[int] = ..., + enable_emoticons: Optional[bool] = ..., + ) -> None: + ... + + @overload + async def edit(self, **fields) -> None: + ... + + async def edit(self, **fields) -> None: """|coro| Edits the integration. @@ -173,7 +213,7 @@ class Integration: self.expire_grace_period = expire_grace_period self.enable_emoticons = enable_emoticons - async def sync(self): + async def sync(self) -> None: """|coro| Syncs the integration. @@ -191,7 +231,7 @@ class Integration: await self._state.http.sync_integration(self.guild.id, self.id) self.synced_at = datetime.datetime.now(datetime.timezone.utc) - async def delete(self): + async def delete(self) -> None: """|coro| Deletes the integration. |