Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions interactions/api/models/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from .misc import MISSING, DictSerializerMixin, Overwrite, Snowflake

# from ... import Presence, Member


class ChannelType(IntEnum):
"""An enumerable object representing the type of channels."""
Expand All @@ -19,6 +21,7 @@ class ChannelType(IntEnum):
GUILD_PUBLIC_THREAD = 11
GUILD_PRIVATE_THREAD = 12
GUILD_STAGE_VOICE = 13
FORUM = 15


class ThreadMetadata(DictSerializerMixin):
Expand Down Expand Up @@ -79,6 +82,8 @@ class ThreadMember(DictSerializerMixin):
"team_id",
"membership_state",
"permissions",
"member",
"presence",
)

def __init__(self, **kwargs):
Expand All @@ -90,6 +95,11 @@ def __init__(self, **kwargs):
if self._json.get("join_timestamp")
else None
)
# Take these conversions with a grain of salt.

# Commented out for circular import reasons, but schema says they do work.
# self.member = Member(**self._json.get("member")) if self._json.get("member") else None
# self.presence = Presence(**self._json.get("presence")) if self._json.get("presence") else None


class Channel(DictSerializerMixin):
Expand Down Expand Up @@ -1040,6 +1050,45 @@ class Thread(Channel):
.. note::
This is a derivation of the base Channel, since a
thread can be its own event.

Also note that forums are also dispatched as Thread
objects.
"""

__slots__ = (
"_json",
"id",
"type",
"guild_id",
"position",
"permission_overwrites",
"name",
"topic",
"nsfw",
"last_message_id",
"bitrate",
"user_limit",
"rate_limit_per_user",
"recipients",
"icon",
"owner_id",
"application_id",
"parent_id",
"last_pin_timestamp",
"rtc_region",
"video_quality_mode",
"message_count",
"member_count",
"thread_metadata",
"member",
"default_auto_archive_duration",
"permissions",
"_client",
# TODO: Document these when Discord officially documents them.
"banner",
"guild_hashes",
"flags", # This seems to be forum unique.
"newly_created",
)

...
4 changes: 4 additions & 0 deletions interactions/api/models/channel.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from typing import List, Optional, Union, Callable

from .guild import Invite, InviteTargetType
from .message import Message, Embed, MessageInteraction
# from ... import Member, Presence
from ...models.component import ActionRow, Button, SelectMenu
from .misc import DictSerializerMixin, Overwrite, Snowflake, MISSING
from .user import User
Expand All @@ -21,6 +22,7 @@ class ChannelType(IntEnum):
GUILD_PUBLIC_THREAD: int
GUILD_PRIVATE_THREAD: int
GUILD_STAGE_VOICE: int
FORUM: int

class ThreadMetadata(DictSerializerMixin):
_json: dict
Expand All @@ -37,6 +39,8 @@ class ThreadMember(DictSerializerMixin):
user_id: Optional[Snowflake]
join_timestamp: datetime.timestamp
flags: int
# member: Optional[Member]
# presence: Optional[Presence]
def __init__(self, **kwargs): ...

class Channel(DictSerializerMixin):
Expand Down
9 changes: 8 additions & 1 deletion interactions/api/models/gw.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,17 @@ class GuildJoinRequest(DictSerializerMixin):

:ivar Snowflake user_id: The user ID of the event.
:ivar Snowflake guild_id: The guild ID of the event.
:ivar Optional[Any] request: The actual request representing the event. This pertains to _CREATE, and maybe _UPDATE events.
:ivar Optional[str] status: The status of the event. This pertains to _CREATE events.
"""

__slots__ = ("_json", "user_id", "guild_id")
__slots__ = ("_json", "user_id", "guild_id", "request", "status")

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.user_id = Snowflake(self.user_id) if self._json.get("user_id") else None
self.guild_id = Snowflake(self.guild_id) if self._json.get("guild_id") else None
# TODO: Add model conversions for request.


class GuildMember(DictSerializerMixin):
Expand Down Expand Up @@ -801,6 +804,10 @@ def __init__(self, **kwargs):
self.emoji = Emoji(**self.emoji) if self._json.get("emoji") else None


# TODO: (temp) Add Thread object for a THREAD_UPDATE event.
# More prevalent on forums for some odd reason.


class ThreadList(DictSerializerMixin):
"""
A class object representing the gateway event ``THREAD_LIST_SYNC``.
Expand Down
2 changes: 2 additions & 0 deletions interactions/api/models/gw.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class GuildJoinRequest(DictSerializerMixin):
_json: dict
user_id: Snowflake
guild_id: Snowflake
request: Optional[Any]
status: Optional[str]
def __init__(self, **kwargs): ...

class GuildMember(DictSerializerMixin):
Expand Down
1 change: 1 addition & 0 deletions interactions/api/models/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MessageType(IntEnum):
THREAD_STARTER_MESSAGE = 21
GUILD_INVITE_REMINDER = 22
CONTEXT_MENU_COMMAND = 23
AUTO_MODERATION_ACTION = 24


class MessageActivity(DictSerializerMixin):
Expand Down
18 changes: 16 additions & 2 deletions interactions/api/models/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ class RoleTags(DictSerializerMixin):
:ivar Optional[Snowflake] bot_id?: The id of the bot this role belongs to
:ivar Optional[Snowflake] integration_id?: The id of the integration this role belongs to
:ivar Optional[Any] premium_subscriber?: Whether if this is the guild's premium subscriber role
:ivar Optional[Snowflake] subscription_listing_id?: The id of the linked premium membership role, if any.
"""

__slots__ = ("_json", "id", "bot_id", "integration_id", "premium_subscriber")
__slots__ = (
"_json",
"id",
"bot_id",
"integration_id",
"premium_subscriber",
"subscription_listing_id",
"purchasable_or_has_subscribers",
)

# TODO: Figure out what actual type it returns, all it says is null.
# TODO: Figure out what actual type it returns by Discord.

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand All @@ -23,6 +32,11 @@ def __init__(self, **kwargs):
self.integration_id = (
Snowflake(self.integration_id) if self._json.get("integration_id") else None
)
self.subscription_listing_id = (
Snowflake(self.subscription_listing_id)
if self._json.get("subscription_listing_id")
else None
)


class Role(DictSerializerMixin):
Expand Down
2 changes: 2 additions & 0 deletions interactions/api/models/role.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class RoleTags(DictSerializerMixin):
bot_id: Optional[Snowflake]
integration_id: Optional[Snowflake]
premium_subscriber: Optional[Any]
subscription_listing_id: Optional[Snowflake]
purchasable_or_has_subscribers: Optional[Any]
def __init__(self, **kwargs): ...

class Role(DictSerializerMixin):
Expand Down