[types] Add support thread API typings

This commit is contained in:
Rapptz 2021-04-14 01:12:40 -04:00
parent 4724943861
commit 6c79714b42
4 changed files with 84 additions and 3 deletions

View File

@ -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):

View File

@ -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

View File

@ -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):

62
discord/types/threads.py Normal file
View File

@ -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