From 6c79714b42b0532ce21a4c587d54b1d36823154f Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 14 Apr 2021 01:12:40 -0400 Subject: [PATCH] [types] Add support thread API typings --- discord/types/channel.py | 22 ++++++++++++-- discord/types/guild.py | 1 + discord/types/message.py | 2 +- discord/types/threads.py | 62 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 discord/types/threads.py diff --git a/discord/types/channel.py b/discord/types/channel.py index 3b4f22b9d..43a85a55f 100644 --- a/discord/types/channel.py +++ b/discord/types/channel.py @@ -25,6 +25,7 @@ DEALINGS IN THE SOFTWARE. from typing import List, Literal, Optional, TypedDict, Union from .user import PartialUser from .snowflake import Snowflake +from .threads import ThreadMetadata, ThreadMember class PermissionOverwrite(TypedDict): @@ -34,7 +35,7 @@ class PermissionOverwrite(TypedDict): deny: str -ChannelType = Literal[0, 1, 2, 3, 4, 5, 6, 13] +ChannelType = Literal[0, 1, 2, 3, 4, 5, 6, 11, 12, 13] class _BaseChannel(TypedDict): @@ -102,7 +103,24 @@ class StageChannel(_BaseGuildChannel, _StageChannelOptional): type: Literal[13] -GuildChannel = Union[TextChannel, NewsChannel, VoiceChannel, CategoryChannel, StoreChannel, StageChannel] +class _ThreadChannelOptional(TypedDict, total=False): + member: ThreadMember + + +class ThreadChannel(_BaseChannel, _ThreadChannelOptional): + type: Literal[11, 12] + guild_id: Snowflake + parent_id: Snowflake + owner_id: Snowflake + nsfw: bool + last_message_id: Optional[Snowflake] + rate_limit_per_user: int + message_count: int + member_count: int + thread_metadata: ThreadMetadata + + +GuildChannel = Union[TextChannel, NewsChannel, VoiceChannel, CategoryChannel, StoreChannel, StageChannel, ThreadChannel] class DMChannel(_BaseChannel): diff --git a/discord/types/guild.py b/discord/types/guild.py index 65e9387be..339438fb9 100644 --- a/discord/types/guild.py +++ b/discord/types/guild.py @@ -60,6 +60,7 @@ class _GuildOptional(TypedDict, total=False): members: List[Member] channels: List[GuildChannel] presences: List[PartialPresenceUpdate] + threads: List[GuildChannel] max_presences: Optional[int] max_members: int premium_subscription_count: int diff --git a/discord/types/message.py b/discord/types/message.py index 9c9fc1aa0..34fd7aa24 100644 --- a/discord/types/message.py +++ b/discord/types/message.py @@ -123,7 +123,7 @@ class _MessageOptional(TypedDict, total=False): components: List[Component] -MessageType = Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 19, 20] +MessageType = Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 19, 18, 20, 21] class Message(_MessageOptional): diff --git a/discord/types/threads.py b/discord/types/threads.py new file mode 100644 index 000000000..02df7307c --- /dev/null +++ b/discord/types/threads.py @@ -0,0 +1,62 @@ +""" +The MIT License (MIT) + +Copyright (c) 2015-present Rapptz + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +from __future__ import annotations +from typing import Literal, Optional, TypedDict + +from .snowflake import Snowflake + +ThreadTypes = Literal[11, 12] +ThreadArchiveDuration = Literal[60, 1440, 4320, 10080] + + +class ThreadMember(TypedDict): + id: Snowflake + user_id: Snowflake + join_timestamp: str + flags: int + + +class ThreadMetadata(TypedDict): + archived: bool + archiver_id: Optional[Snowflake] + auto_archive_duration: ThreadArchiveDuration + archive_timestamp: str + + +class _ThreadOptional(TypedDict, total=False): + member: ThreadMember + last_message_id: Optional[Snowflake] + + +class Thread(_ThreadOptional): + id: Snowflake + guild_id: Snowflake + parent_id: Snowflake + owner_id: Snowflake + name: str + type: ThreadTypes + member_count: int + message_count: int + thread_metadata: ThreadMetadata