From 4b12db90086e1cc881bb0aa9a3c085e9ecf1c53a Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Sat, 2 Apr 2022 09:09:29 +0300 Subject: [PATCH] thread docs --- docs/source/models/guild.rst | 34 +++++++++++++++++ melisa/models/guild/__init__.py | 1 + melisa/models/guild/channel.py | 10 ++--- melisa/models/guild/thread.py | 65 +++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 melisa/models/guild/thread.py diff --git a/docs/source/models/guild.rst b/docs/source/models/guild.rst index 1c77995..f5228b9 100644 --- a/docs/source/models/guild.rst +++ b/docs/source/models/guild.rst @@ -89,3 +89,37 @@ UnavailableGuild .. attributetable:: UnavailableGuild .. autoclass:: UnavailableGuild() + + +Thread +------ + +Thread +~~~~~~ +.. attributetable:: Thread + + +.. autoclass:: Thread() + :exclude-members: start_thread_without_message + :inherited-members: + +ThreadMember +~~~~~~~~~~~~~ +.. attributetable:: ThreadMember + +.. autoclass:: ThreadMember() + :inherited-members: + +ThreadMetadata +~~~~~~~~~~~~~ +.. attributetable:: ThreadMetadata + +.. autoclass:: ThreadMetadata() + :inherited-members: + +ThreadsList +~~~~~~~~~~~~~ +.. attributetable:: ThreadsList + +.. autoclass:: ThreadsList() + :inherited-members: diff --git a/melisa/models/guild/__init__.py b/melisa/models/guild/__init__.py index 758e6f1..376845b 100644 --- a/melisa/models/guild/__init__.py +++ b/melisa/models/guild/__init__.py @@ -3,3 +3,4 @@ from .guild import * from .channel import * +from .thread import * diff --git a/melisa/models/guild/channel.py b/melisa/models/guild/channel.py index 59e801c..31a4e35 100644 --- a/melisa/models/guild/channel.py +++ b/melisa/models/guild/channel.py @@ -11,6 +11,7 @@ from typing import List, Any, Optional, AsyncIterator, Union, Dict, overload from ...utils import Snowflake, Timestamp from ...utils import APIModelBase from ...utils.types import APINullable +from .thread import ThreadMember, ThreadMetadata class ChannelType(IntEnum): @@ -133,7 +134,7 @@ class Channel(APIModelBase): The camera video quality mode of the voice channel, 1 when not present message_count: :class:`int` An approximate count of messages in a thread, stops counting at 50 - thread_metadata: :class:`typing.Any` + thread_metadata: :class:`~melisa.models.guild.thread.ThreadMetadata` Thread-specific fields not needed by other channels member: :class:`typing.Any` Thread member object for the current user, @@ -169,7 +170,7 @@ class Channel(APIModelBase): video_quality_mode: APINullable[int] = None message_count: APINullable[int] = None member_count: APINullable[int] = None - thread_metadata: APINullable[List] = None + thread_metadata: APINullable[ThreadMetadata] = None member: APINullable[List] = None default_auto_archive_duration: APINullable[int] = None permissions: APINullable[str] = None @@ -252,8 +253,7 @@ class MessageableChannel(Channel): """|coro| Creates a new thread that is not connected to an existing message. - The created thread defaults to a ``GUILD_PRIVATE_THREAD``*. - Returns a Channel on success. + The created thread defaults to a ``GUILD_PRIVATE_THREAD``. Creating a private thread requires the server to be boosted. The guild features will indicate if that is possible for the guild. @@ -645,7 +645,7 @@ class ThreadsList(APIModelBase): """ threads: List[Thread] - members: List + members: List[ThreadMember] has_more: APINullable[bool] = None diff --git a/melisa/models/guild/thread.py b/melisa/models/guild/thread.py new file mode 100644 index 0000000..a0d08cc --- /dev/null +++ b/melisa/models/guild/thread.py @@ -0,0 +1,65 @@ +# Copyright MelisaDev 2022 - Present +# Full MIT License can be found in `LICENSE.txt` at the project root. + +from __future__ import annotations + +from dataclasses import dataclass + +from ...utils.api_model import APIModelBase +from ...utils.types import APINullable +from ...utils.snowflake import Snowflake +from ...utils.timestamp import Timestamp + + +@dataclass(repr=False) +class ThreadMetadata(APIModelBase): + """ + Represents a Discord Thread Metadata object + + Attributes + ---------- + archived: :class:`bool` + Whether the thread is archived + auto_archive_duration: :class:`int` + Duration in minutes to automatically archive the thread after recent activity, + can be set to: 60, 1440, 4320, 10080 + archive_timestamp: :class:`~melisa.utils.timestamp.Timestamp` + Timestamp when the thread's archive status was last changed, + used for calculating recent activity + locked: :class:`bool` + Whether the thread is locked; when a thread is locked, + only users with ``MANAGE_THREADS`` can unarchive it + invitable: Optional[:class:`bool`] + Whether non-moderators can add other non-moderators to a thread; + only available on private threads + create_timestamp: Optional[:class:`~melisa.utils.timestamp.Timestamp`] + Timestamp when the thread was created; only populated for threads created after 2022-01-09 + """ + archived: bool + auto_archive_duration: int + archive_timestamp: Timestamp + locked: bool + invitable: APINullable[bool] = None + create_timestamp: APINullable[Timestamp] = None + + +@dataclass(repr=False) +class ThreadMember(APIModelBase): + """Represents a Discord Thread Member object + + Attributes + ---------- + id: Optional[:class:`~melisa.utils.snowflake.Snowflake`] + The id of the thread + user_id: Optional[:class:`~melisa.utils.snowflake.Snowflake`] + The id of the user + join_timestamp: :class:`~melisa.utils.timestamp.Timestamp` + The time the current user last joined the thread + flags: :class:`int` + Any user-thread settings, currently only used for notifications + """ + join_timestamp: Timestamp + flags: int + id: APINullable[Snowflake] = None + user_id: APINullable[Snowflake] = None +