예제 #1
0
 async def parse_channel_update(self, data, old):
     channel_type = try_enum(ChannelType, data.get("type"))
     if old and channel_type is ChannelType.private:
         channel = DMChannel(me=self.user, state=self, data=data)
         old_channel = DMChannel(me=self.user, state=self, data=old)
         self.dispatch("private_channel_update", old_channel, channel)
     elif old:
         guild = await self._get_guild(
             utils._get_as_snowflake(data, "guild_id"))
         if guild:
             factory, _ = _channel_factory(data["type"])
             channel = factory(guild=guild, state=self, data=data)
             old_factory, _ = _channel_factory(old["type"])
             old_channel = old_factory(guild=guild, state=self, data=old)
             self.dispatch("guild_channel_update", old_channel, channel)
예제 #2
0
 async def _channels(self):
     channels = []
     for channel in await self._state._members_get_all("guild",
                                                       key_id=self.id,
                                                       name="channel"):
         factory, _ = _channel_factory(channel["type"])
         channels.append(
             factory(guild=self, state=self._state, data=channel))
     return channels
예제 #3
0
 async def _get_guild_channel(self, channel_id):
     result = await self._members_get("channel", second=channel_id)
     if result:
         factory, _ = _channel_factory(result["type"])
         guild = await self._get_guild(self._key_first(result))
         if guild:
             result = factory(guild=guild, state=self, data=result)
         else:
             result = None
     return result
예제 #4
0
 async def parse_channel_create(self, data, old):
     factory, ch_type = _channel_factory(data["type"])
     if ch_type is ChannelType.private:
         channel = DMChannel(me=self.user, data=data, state=self)
         self.dispatch("private_channel_create", channel)
     else:
         guild = await self._get_guild(
             utils._get_as_snowflake(data, "guild_id"))
         if guild:
             channel = factory(guild=guild, state=self, data=data)
             self.dispatch("guild_channel_create", channel)
예제 #5
0
 async def parse_channel_delete(self, data, old):
     if old and old["guild_id"]:
         guild = await self._get_guild(
             utils._get_as_snowflake(data, "guild_id"))
         if guild:
             factory, _ = _channel_factory(old["type"])
             channel = factory(guild=guild, state=self, data=old)
             self.dispatch("guild_channel_delete", channel)
     elif old:
         channel = DMChannel(me=self.user, state=self, data=old)
         self.dispatch("private_channel_delete", channel)
예제 #6
0
    async def fetch_channel(self, id: int, *, guild=None):
        data = await self.http.get_channel(id)

        factory, ch_type = _channel_factory(data['type'])
        if factory is None:
            raise InvalidData(
                'Unknown channel type {type} for channel ID {id}.'.format_map(
                    data))

        if ch_type in (ChannelType.group, ChannelType.private):
            channel = factory(me=self.user, data=data, state=self._connection)
        else:
            guild_id = int(data['guild_id'])
            guild = guild or self.get_guild(guild_id) or Object(id=guild_id)
            channel = factory(guild=guild, state=self._connection, data=data)

        return channel
예제 #7
0
 async def get_channel(self, channel_id):
     result = await self._state._get(f"channel:{self.id}:{channel_id}")
     if not result:
         return None
     factory, _ = _channel_factory(result["type"])
     return factory(guild=self, state=self._state, data=result)