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

@ -55,6 +55,7 @@ from .integrations import _integration_factory
from .interactions import Interaction
from .ui.view import ViewStore
from .stage_instance import StageInstance
from .threads import Thread, ThreadMember
class ChunkRequest:
def __init__(self, guild_id, loop, resolver, *, cache=True):
@ -483,7 +484,7 @@ class ConnectionState:
self.dispatch('message', message)
if self._messages is not None:
self._messages.append(message)
if channel and channel.__class__ is TextChannel:
if channel and channel.__class__ in (TextChannel, Thread):
channel.last_message_id = message.id
def parse_message_delete(self, data):
@ -704,6 +705,44 @@ class ConnectionState:
else:
self.dispatch('guild_channel_pins_update', channel, last_pin)
def parse_thread_create(self, data):
guild_id = int(data['guild_id'])
guild = self._get_guild(guild_id)
if guild is None:
log.debug('THREAD_CREATE referencing an unknown guild ID: %s. Discarding', guild_id)
return
thread = Thread(guild=guild, data=data)
guild._add_thread(thread)
self.dispatch('thread_create', thread)
def parse_thread_update(self, data):
guild_id = int(data['guild_id'])
guild = self._get_guild(guild_id)
if guild is None:
log.debug('THREAD_UPDATE referencing an unknown guild ID: %s. Discarding', guild_id)
return
thread_id = int(data['id'])
thread = guild._get_thread(thread_id)
if thread is not None:
old = copy.copy(thread)
thread._update(data)
self.dispatch('thread_update', old, thread)
def parse_thread_delete(self, data):
guild_id = int(data['guild_id'])
guild = self._get_guild(guild_id)
if guild is None:
log.debug('THREAD_UPDATE referencing an unknown guild ID: %s. Discarding', guild_id)
return
thread_id = int(data['id'])
thread = guild._get_thread(thread_id)
if thread is not None:
guild._remove_thread(thread)
self.dispatch('thread_delete', thread)
def parse_guild_member_add(self, data):
guild = self._get_guild(int(data['guild_id']))
if guild is None: