Update thread typings and payloads to match documentation
This commit is contained in:
parent
ac95b8b85b
commit
4a4e73ec14
@ -162,6 +162,7 @@ class ChannelType(Enum):
|
|||||||
category = 4
|
category = 4
|
||||||
news = 5
|
news = 5
|
||||||
store = 6
|
store = 6
|
||||||
|
news_thread = 10
|
||||||
public_thread = 11
|
public_thread = 11
|
||||||
private_thread = 12
|
private_thread = 12
|
||||||
stage_voice = 13
|
stage_voice = 13
|
||||||
|
@ -46,6 +46,7 @@ if TYPE_CHECKING:
|
|||||||
invite,
|
invite,
|
||||||
channel,
|
channel,
|
||||||
widget,
|
widget,
|
||||||
|
threads,
|
||||||
)
|
)
|
||||||
from .types.snowflake import Snowflake
|
from .types.snowflake import Snowflake
|
||||||
|
|
||||||
@ -741,7 +742,7 @@ class HTTPClient:
|
|||||||
name: str,
|
name: str,
|
||||||
auto_archive_duration: int,
|
auto_archive_duration: int,
|
||||||
type: int,
|
type: int,
|
||||||
):
|
) -> Response[threads.Thread]:
|
||||||
payload = {
|
payload = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'auto_archive_duration': auto_archive_duration,
|
'auto_archive_duration': auto_archive_duration,
|
||||||
@ -760,7 +761,7 @@ class HTTPClient:
|
|||||||
name: str,
|
name: str,
|
||||||
auto_archive_duration: int,
|
auto_archive_duration: int,
|
||||||
type: int,
|
type: int,
|
||||||
):
|
) -> Response[threads.Thread]:
|
||||||
payload = {
|
payload = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'auto_archive_duration': auto_archive_duration,
|
'auto_archive_duration': auto_archive_duration,
|
||||||
@ -775,7 +776,7 @@ class HTTPClient:
|
|||||||
|
|
||||||
def add_user_to_thread(self, channel_id: int, user_id: int):
|
def add_user_to_thread(self, channel_id: int, user_id: int):
|
||||||
return self.request(
|
return self.request(
|
||||||
Route('POST', '/channels/{channel_id}/thread-members/{user_id}', channel_id=channel_id, user_id=user_id)
|
Route('PUT', '/channels/{channel_id}/thread-members/{user_id}', channel_id=channel_id, user_id=user_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
def leave_thread(self, channel_id: int):
|
def leave_thread(self, channel_id: int):
|
||||||
@ -785,7 +786,9 @@ class HTTPClient:
|
|||||||
route = Route('DELETE', '/channels/{channel_id}/thread-members/{user_id}', channel_id=channel_id, user_id=user_id)
|
route = Route('DELETE', '/channels/{channel_id}/thread-members/{user_id}', channel_id=channel_id, user_id=user_id)
|
||||||
return self.request(route)
|
return self.request(route)
|
||||||
|
|
||||||
def get_public_archived_threads(self, channel_id: int, before=None, limit: int = 50):
|
def get_public_archived_threads(
|
||||||
|
self, channel_id: int, before=None, limit: int = 50
|
||||||
|
) -> Response[threads.ThreadPaginationPayload]:
|
||||||
route = Route('GET', '/channels/{channel_id}/threads/archived/public', channel_id=channel_id)
|
route = Route('GET', '/channels/{channel_id}/threads/archived/public', channel_id=channel_id)
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
@ -794,7 +797,9 @@ class HTTPClient:
|
|||||||
params['limit'] = limit
|
params['limit'] = limit
|
||||||
return self.request(route, params=params)
|
return self.request(route, params=params)
|
||||||
|
|
||||||
def get_private_archived_threads(self, channel_id: int, before=None, limit: int = 50):
|
def get_private_archived_threads(
|
||||||
|
self, channel_id: int, before=None, limit: int = 50
|
||||||
|
) -> Response[threads.ThreadPaginationPayload]:
|
||||||
route = Route('GET', '/channels/{channel_id}/threads/archived/private', channel_id=channel_id)
|
route = Route('GET', '/channels/{channel_id}/threads/archived/private', channel_id=channel_id)
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
@ -803,7 +808,9 @@ class HTTPClient:
|
|||||||
params['limit'] = limit
|
params['limit'] = limit
|
||||||
return self.request(route, params=params)
|
return self.request(route, params=params)
|
||||||
|
|
||||||
def get_joined_private_archived_threads(self, channel_id, before=None, limit: int = 50):
|
def get_joined_private_archived_threads(
|
||||||
|
self, channel_id: int, before=None, limit: int = 50
|
||||||
|
) -> Response[threads.ThreadPaginationPayload]:
|
||||||
route = Route('GET', '/channels/{channel_id}/users/@me/threads/archived/private', channel_id=channel_id)
|
route = Route('GET', '/channels/{channel_id}/users/@me/threads/archived/private', channel_id=channel_id)
|
||||||
params = {}
|
params = {}
|
||||||
if before:
|
if before:
|
||||||
@ -811,6 +818,14 @@ class HTTPClient:
|
|||||||
params['limit'] = limit
|
params['limit'] = limit
|
||||||
return self.request(route, params=params)
|
return self.request(route, params=params)
|
||||||
|
|
||||||
|
def get_active_threads(self, channel_id: int) -> Response[threads.ThreadPaginationPayload]:
|
||||||
|
route = Route('GET', '/channels/{channel_id}/threads/active', channel_id=channel_id)
|
||||||
|
return self.request(route)
|
||||||
|
|
||||||
|
def get_thread_members(self, channel_id: int) -> Response[List[threads.ThreadMember]]:
|
||||||
|
route = Route('GET', '/channels/{channel_id}/thread-members', channel_id=channel_id)
|
||||||
|
return self.request(route)
|
||||||
|
|
||||||
# Webhook management
|
# Webhook management
|
||||||
|
|
||||||
def create_webhook(self, channel_id, *, name, avatar=None, reason=None):
|
def create_webhook(self, channel_id, *, name, avatar=None, reason=None):
|
||||||
@ -1456,7 +1471,9 @@ class HTTPClient:
|
|||||||
)
|
)
|
||||||
return self.request(r)
|
return self.request(r)
|
||||||
|
|
||||||
def get_guild_application_command_permissions(self, application_id, guild_id) -> Response[List[interactions.GuildApplicationCommandPermissions]]:
|
def get_guild_application_command_permissions(
|
||||||
|
self, application_id, guild_id
|
||||||
|
) -> Response[List[interactions.GuildApplicationCommandPermissions]]:
|
||||||
r = Route(
|
r = Route(
|
||||||
'GET',
|
'GET',
|
||||||
'/applications/{application_id}/guilds/{guild_id}/commands/permissions',
|
'/applications/{application_id}/guilds/{guild_id}/commands/permissions',
|
||||||
@ -1465,7 +1482,9 @@ class HTTPClient:
|
|||||||
)
|
)
|
||||||
return self.request(r)
|
return self.request(r)
|
||||||
|
|
||||||
def get_application_command_permissions(self, application_id, guild_id, command_id) -> Response[interactions.GuildApplicationCommandPermissions]:
|
def get_application_command_permissions(
|
||||||
|
self, application_id, guild_id, command_id
|
||||||
|
) -> Response[interactions.GuildApplicationCommandPermissions]:
|
||||||
r = Route(
|
r = Route(
|
||||||
'GET',
|
'GET',
|
||||||
'/applications/{application_id}/guilds/{guild_id}/commands/{command_id}/permissions',
|
'/applications/{application_id}/guilds/{guild_id}/commands/{command_id}/permissions',
|
||||||
|
@ -87,6 +87,11 @@ class Thread(Messageable, Hashable):
|
|||||||
last_message_id: Optional[:class:`int`]
|
last_message_id: Optional[:class:`int`]
|
||||||
The last message ID of the message sent to this thread. It may
|
The last message ID of the message sent to this thread. It may
|
||||||
*not* point to an existing or valid message.
|
*not* point to an existing or valid message.
|
||||||
|
slowmode_delay: :class:`int`
|
||||||
|
The number of seconds a member must wait between sending messages
|
||||||
|
in this thread. A value of `0` denotes that it is disabled.
|
||||||
|
Bots and users with :attr:`~Permissions.manage_channels` or
|
||||||
|
:attr:`~Permissions.manage_messages` bypass slowmode.
|
||||||
message_count: :class:`int`
|
message_count: :class:`int`
|
||||||
An approximate number of messages in this thread. This caps at 50.
|
An approximate number of messages in this thread. This caps at 50.
|
||||||
member_count: :class:`int`
|
member_count: :class:`int`
|
||||||
@ -112,10 +117,13 @@ class Thread(Messageable, Hashable):
|
|||||||
'_type',
|
'_type',
|
||||||
'_state',
|
'_state',
|
||||||
'owner_id',
|
'owner_id',
|
||||||
|
'parent_id',
|
||||||
'last_message_id',
|
'last_message_id',
|
||||||
'message_count',
|
'message_count',
|
||||||
'member_count',
|
'member_count',
|
||||||
|
'slowmode_delay',
|
||||||
'me',
|
'me',
|
||||||
|
'locked',
|
||||||
'archived',
|
'archived',
|
||||||
'archiver_id',
|
'archiver_id',
|
||||||
'auto_archive_duration',
|
'auto_archive_duration',
|
||||||
@ -135,8 +143,9 @@ class Thread(Messageable, Hashable):
|
|||||||
self.parent_id = int(data['parent_id'])
|
self.parent_id = int(data['parent_id'])
|
||||||
self.owner_id = int(data['owner_id'])
|
self.owner_id = int(data['owner_id'])
|
||||||
self.name = data['name']
|
self.name = data['name']
|
||||||
self.type = try_enum(ChannelType, data['type'])
|
self._type = try_enum(ChannelType, data['type'])
|
||||||
self.last_message_id = utils._get_as_snowflake(data, 'last_message_id')
|
self.last_message_id = utils._get_as_snowflake(data, 'last_message_id')
|
||||||
|
self.slowmode_delay = data.get('rate_limit_per_user', 0)
|
||||||
self._unroll_metadata(data['thread_metadata'])
|
self._unroll_metadata(data['thread_metadata'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -151,6 +160,7 @@ class Thread(Messageable, Hashable):
|
|||||||
self.archiver_id = utils._get_as_snowflake(data, 'archiver_id')
|
self.archiver_id = utils._get_as_snowflake(data, 'archiver_id')
|
||||||
self.auto_archive_duration = data['auto_archive_duration']
|
self.auto_archive_duration = data['auto_archive_duration']
|
||||||
self.archive_timestamp = utils.parse_time(data['archive_timestamp'])
|
self.archive_timestamp = utils.parse_time(data['archive_timestamp'])
|
||||||
|
self.locked = data.get('locked', False)
|
||||||
|
|
||||||
def _update(self, data):
|
def _update(self, data):
|
||||||
try:
|
try:
|
||||||
@ -196,7 +206,7 @@ class Thread(Messageable, Hashable):
|
|||||||
|
|
||||||
def is_private(self) -> bool:
|
def is_private(self) -> bool:
|
||||||
""":class:`bool`: Whether the thread is a private thread."""
|
""":class:`bool`: Whether the thread is a private thread."""
|
||||||
return self.type is ChannelType.private_thread
|
return self._type is ChannelType.private_thread
|
||||||
|
|
||||||
async def edit(
|
async def edit(
|
||||||
self,
|
self,
|
||||||
|
@ -35,7 +35,7 @@ class PermissionOverwrite(TypedDict):
|
|||||||
deny: str
|
deny: str
|
||||||
|
|
||||||
|
|
||||||
ChannelType = Literal[0, 1, 2, 3, 4, 5, 6, 11, 12, 13]
|
ChannelType = Literal[0, 1, 2, 3, 4, 5, 6, 10, 11, 12, 13]
|
||||||
|
|
||||||
|
|
||||||
class _BaseChannel(TypedDict):
|
class _BaseChannel(TypedDict):
|
||||||
@ -105,6 +105,10 @@ class StageChannel(_BaseGuildChannel, _StageChannelOptional):
|
|||||||
|
|
||||||
class _ThreadChannelOptional(TypedDict, total=False):
|
class _ThreadChannelOptional(TypedDict, total=False):
|
||||||
member: ThreadMember
|
member: ThreadMember
|
||||||
|
owner_id: Snowflake
|
||||||
|
rate_limit_per_user: int
|
||||||
|
last_message_id: Optional[Snowflake]
|
||||||
|
last_pin_timestamp: str
|
||||||
|
|
||||||
|
|
||||||
class ThreadChannel(_BaseChannel, _ThreadChannelOptional):
|
class ThreadChannel(_BaseChannel, _ThreadChannelOptional):
|
||||||
|
@ -23,11 +23,11 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import Literal, Optional, TypedDict
|
from typing import List, Literal, Optional, TypedDict
|
||||||
|
|
||||||
from .snowflake import Snowflake
|
from .snowflake import Snowflake
|
||||||
|
|
||||||
ThreadTypes = Literal[11, 12]
|
ThreadTypes = Literal[10, 11, 12]
|
||||||
ThreadArchiveDuration = Literal[60, 1440, 4320, 10080]
|
ThreadArchiveDuration = Literal[60, 1440, 4320, 10080]
|
||||||
|
|
||||||
|
|
||||||
@ -38,9 +38,13 @@ class ThreadMember(TypedDict):
|
|||||||
flags: int
|
flags: int
|
||||||
|
|
||||||
|
|
||||||
class ThreadMetadata(TypedDict):
|
class _ThreadMetadataOptional(TypedDict, total=False):
|
||||||
|
archiver_id: Snowflake
|
||||||
|
locked: bool
|
||||||
|
|
||||||
|
|
||||||
|
class ThreadMetadata(_ThreadMetadataOptional):
|
||||||
archived: bool
|
archived: bool
|
||||||
archiver_id: Optional[Snowflake]
|
|
||||||
auto_archive_duration: ThreadArchiveDuration
|
auto_archive_duration: ThreadArchiveDuration
|
||||||
archive_timestamp: str
|
archive_timestamp: str
|
||||||
|
|
||||||
@ -48,6 +52,7 @@ class ThreadMetadata(TypedDict):
|
|||||||
class _ThreadOptional(TypedDict, total=False):
|
class _ThreadOptional(TypedDict, total=False):
|
||||||
member: ThreadMember
|
member: ThreadMember
|
||||||
last_message_id: Optional[Snowflake]
|
last_message_id: Optional[Snowflake]
|
||||||
|
last_pin_timestamp: Optional[Snowflake]
|
||||||
|
|
||||||
|
|
||||||
class Thread(_ThreadOptional):
|
class Thread(_ThreadOptional):
|
||||||
@ -59,4 +64,11 @@ class Thread(_ThreadOptional):
|
|||||||
type: ThreadTypes
|
type: ThreadTypes
|
||||||
member_count: int
|
member_count: int
|
||||||
message_count: int
|
message_count: int
|
||||||
|
rate_limit_per_user: int
|
||||||
thread_metadata: ThreadMetadata
|
thread_metadata: ThreadMetadata
|
||||||
|
|
||||||
|
|
||||||
|
class ThreadPaginationPayload(TypedDict):
|
||||||
|
threads: List[Thread]
|
||||||
|
members: List[ThreadMember]
|
||||||
|
has_more: bool
|
||||||
|
23
docs/api.rst
23
docs/api.rst
@ -1065,6 +1065,12 @@ of :class:`enum.Enum`.
|
|||||||
|
|
||||||
.. versionadded:: 1.7
|
.. versionadded:: 1.7
|
||||||
|
|
||||||
|
.. attribute:: news_thread
|
||||||
|
|
||||||
|
A news thread
|
||||||
|
|
||||||
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
.. attribute:: public_thread
|
.. attribute:: public_thread
|
||||||
|
|
||||||
A public thread
|
A public thread
|
||||||
@ -1096,12 +1102,12 @@ of :class:`enum.Enum`.
|
|||||||
The default message type. This is the same as regular messages.
|
The default message type. This is the same as regular messages.
|
||||||
.. attribute:: recipient_add
|
.. attribute:: recipient_add
|
||||||
|
|
||||||
The system message when a recipient is added to a group private
|
The system message when a user is added to a group private
|
||||||
message, i.e. a private channel of type :attr:`ChannelType.group`.
|
message or a thread.
|
||||||
.. attribute:: recipient_remove
|
.. attribute:: recipient_remove
|
||||||
|
|
||||||
The system message when a recipient is removed from a group private
|
The system message when a user is removed from a group private
|
||||||
message, i.e. a private channel of type :attr:`ChannelType.group`.
|
message or a thread.
|
||||||
.. attribute:: call
|
.. attribute:: call
|
||||||
|
|
||||||
The system message denoting call state, e.g. missed call, started call,
|
The system message denoting call state, e.g. missed call, started call,
|
||||||
@ -1170,7 +1176,10 @@ of :class:`enum.Enum`.
|
|||||||
.. versionadded:: 1.7
|
.. versionadded:: 1.7
|
||||||
.. attribute:: thread_created
|
.. attribute:: thread_created
|
||||||
|
|
||||||
The system message denoting that a thread has been created
|
The system message denoting that a thread has been created. This is only
|
||||||
|
sent if the thread has been created from an older message. The period of time
|
||||||
|
required for a message to be considered old cannot be relied upon and is up to
|
||||||
|
Discord.
|
||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
.. attribute:: reply
|
.. attribute:: reply
|
||||||
@ -1190,8 +1199,8 @@ of :class:`enum.Enum`.
|
|||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
.. attribute:: thread_starter_message
|
.. attribute:: thread_starter_message
|
||||||
|
|
||||||
The system message denoting that this message is the one that started a thread's
|
The system message denoting the message in the thread that is the one that started the
|
||||||
conversation topic.
|
thread's conversation topic.
|
||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user