Skip to content

Commit

Permalink
Add sort order, channel flags and total msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Nov 7, 2022
1 parent 3fd72af commit d1da9be
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@ def __str__(self):
return self.name


class SortOrder(Enum):
"""Forum Channel Sort Order"""

latest_activity = 1
creation_date = 2

def __str__(self):
return self.name


class ContentFilter(Enum, comparable=True):
"""Content Filter"""

Expand Down
11 changes: 11 additions & 0 deletions discord/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class Thread(Messageable, Hashable):
Only available for threads created after 2022-01-09.
flags: :class:`ChannelFlags`
Extra features of the thread.
total_message_sent: :class:`int`
Number of messages ever sent in a thread.
It's similar to message_count on message creation,
but will not decrement the number when a message is deleted.
.. versionadded:: 2.0
"""
Expand All @@ -151,6 +155,7 @@ class Thread(Messageable, Hashable):
"archive_timestamp",
"created_at",
"flags",
"total_message_sent",
)

def __init__(self, *, guild: Guild, state: ConnectionState, data: ThreadPayload):
Expand Down Expand Up @@ -189,6 +194,7 @@ def _from_data(self, data: ThreadPayload):
self.message_count = data.get("message_count", None)
self.member_count = data.get("member_count", None)
self.flags: ChannelFlags = ChannelFlags._from_value(data.get("flags", 0))
self.total_message_sent = data.get("total_message_sent", None)

# Here, we try to fill in potentially missing data
if thread := self.guild.get_thread(self.id) and data.pop("_invoke_flag", False):
Expand All @@ -203,6 +209,11 @@ def _from_data(self, data: ThreadPayload):
if self.message_count is None
else self.message_count
)
self.total_message_sent = (
thread.total_message_sent
if self.total_message_sent is None
else self.total_message_sent
)
self.member_count = (
thread.member_count if self.member_count is None else self.member_count
)
Expand Down
8 changes: 7 additions & 1 deletion discord/types/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from typing import Literal, Union

from .._typed_dict import NotRequired, TypedDict
from ..enums import SortOrder
from ..flags import ChannelFlags
from .snowflake import Snowflake
from .threads import ThreadArchiveDuration, ThreadMember, ThreadMetadata
from .user import PartialUser
Expand Down Expand Up @@ -67,6 +69,7 @@ class _TextChannelOptional(TypedDict, total=False):
last_pin_timestamp: str
rate_limit_per_user: int
default_auto_archive_duration: ThreadArchiveDuration
default_thread_rate_limit_per_user: int


class TextChannel(_BaseGuildChannel, _TextChannelOptional):
Expand All @@ -90,7 +93,8 @@ class ForumChannel(_BaseGuildChannel, _TextChannelOptional):
type: Literal[15]
available_tags: NotRequired(list[ForumTag] | None)
default_reaction_emoji: NotRequired(DefaultReaction | None)
flags: int
default_sort_order: NotRequired(SortOrder | None)
flags: ChannelFlags


class NewsChannel(_BaseGuildChannel, _TextChannelOptional):
Expand Down Expand Up @@ -134,6 +138,8 @@ class ThreadChannel(_BaseChannel):
member_count: int
thread_metadata: ThreadMetadata
applied_tags: NotRequired(list[Snowflake] | None)
flags: ChannelFlags
total_message_sent: int


GuildChannel = Union[
Expand Down
3 changes: 3 additions & 0 deletions discord/types/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from typing import Literal

from .._typed_dict import NotRequired, TypedDict
from ..flags import ChannelFlags
from .snowflake import Snowflake

ThreadType = Literal[10, 11, 12]
Expand Down Expand Up @@ -64,6 +65,8 @@ class Thread(TypedDict):
message_count: int
rate_limit_per_user: int
thread_metadata: ThreadMetadata
flags: ChannelFlags
total_message_sent: int


class ThreadPaginationPayload(TypedDict):
Expand Down

0 comments on commit d1da9be

Please sign in to comment.