Add category support.

This adds:

* CategoryChannel, which represents a category
* Guild.by_category() which traverses the channels grouping by category
* Guild.categories to get a list of categories
* abc.GuildChannel.category to get the category a channel belongs to
* sync_permissions keyword argument to abc.GuildChannel.edit to sync
  permissions with a pre-existing or new category
* category keyword argument to abc.GuildChannel.edit to move a channel
  to a category
This commit is contained in:
Rapptz
2017-09-13 09:38:05 -04:00
parent e24914be0b
commit 53b4890435
8 changed files with 249 additions and 32 deletions

View File

@ -484,6 +484,10 @@ class ConnectionState:
def parse_channel_create(self, data):
factory, ch_type = _channel_factory(data['type'])
if factory is None:
log.warning('CHANNEL_CREATE referencing an unknown channel type %s. Discarding.', data['type'])
return
channel = None
if ch_type in (ChannelType.group, ChannelType.private):
@ -496,10 +500,6 @@ class ConnectionState:
guild_id = utils._get_as_snowflake(data, 'guild_id')
guild = self._get_guild(guild_id)
if guild is not None:
if factory is None:
log.warning('CHANNEL_CREATE referencing an unknown channel type %s. Discarding.', data['type'])
return
channel = factory(guild=guild, state=self, data=data)
guild._add_channel(channel)
self.dispatch('guild_channel_create', channel)