First pass at preliminary thread support

This is missing a lot of functionality right now, such as two gateway
events and all the HTTP CRUD endpoints.
This commit is contained in:
Rapptz
2021-04-14 05:05:47 -04:00
parent 6c79714b42
commit 68c7c538f5
9 changed files with 504 additions and 12 deletions

View File

@@ -47,6 +47,7 @@ from .asset import Asset
from .flags import SystemChannelFlags
from .integrations import Integration, _integration_factory
from .stage_instance import StageInstance
from .threads import Thread
__all__ = (
'Guild',
@@ -182,7 +183,7 @@ class Guild(Hashable):
'description', 'max_presences', 'max_members', 'max_video_channel_users',
'premium_tier', 'premium_subscription_count', '_system_channel_flags',
'preferred_locale', '_discovery_splash', '_rules_channel_id',
'_public_updates_channel_id', '_stage_instances', 'nsfw_level')
'_public_updates_channel_id', '_stage_instances', 'nsfw_level', '_threads')
_PREMIUM_GUILD_LIMITS = {
None: _GuildLimit(emoji=50, bitrate=96e3, filesize=8388608),
@@ -196,6 +197,7 @@ class Guild(Hashable):
self._channels = {}
self._members = {}
self._voice_states = {}
self._threads = {}
self._state = state
self._from_data(data)
@@ -214,6 +216,12 @@ class Guild(Hashable):
def _remove_member(self, member):
self._members.pop(member.id, None)
def _add_thread(self, thread):
self._threads[thread.id] = thread
def _remove_thread(self, thread):
self._threads.pop(thread.id, None)
def __str__(self):
return self.name or ''
@@ -360,11 +368,24 @@ class Guild(Hashable):
if factory:
self._add_channel(factory(guild=self, data=c, state=self._state))
if 'threads' in data:
threads = data['threads']
for thread in threads:
self._add_thread(Thread(guild=self, data=thread))
@property
def channels(self):
"""List[:class:`abc.GuildChannel`]: A list of channels that belongs to this guild."""
return list(self._channels.values())
@property
def threads(self):
"""List[:class:`Thread`]: A list of threads that you have permission to view.
.. versionadded:: 2.0
"""
return list(self._threads.values())
@property
def large(self):
""":class:`bool`: Indicates if the guild is a 'large' guild.
@@ -484,6 +505,23 @@ class Guild(Hashable):
"""
return self._channels.get(channel_id)
def get_thread(self, thread_id):
"""Returns a thread with the given ID.
.. versionadded:: 2.0
Parameters
-----------
thread_id: :class:`int`
The ID to search for.
Returns
--------
Optional[:class:`Thread`]
The returned thread or ``None`` if not found.
"""
return self._threads.get(thread_id)
@property
def system_channel(self):
"""Optional[:class:`TextChannel`]: Returns the guild's channel used for system messages.
@@ -2377,7 +2415,7 @@ class Guild(Hashable):
data = await self._state.http.get_widget(self.id)
return Widget(state=self._state, data=data)
async def edit_widget(self, *, enabled: bool = utils.MISSING, channel: Optional[abc.Snowflake] = utils.MISSING) -> None:
"""|coro|