Пример #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=tools.upgrade_payload(channel)))

        return channels
Пример #3
0
    async def get_channel(self, channel_id):
        channel = await self._state.get(f"channel:{channel_id}")

        if not channel:
            return None

        factory, _ = _channel_factory(channel["type"])
        return factory(guild=self, state=self._state, data=channel)
Пример #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 _get_channel(self, channel_id):
        result = await self.get(f"channel:{channel_id}")

        if result:
            if result.get("guild_id"):
                factory, _ = _channel_factory(result["type"])
                guild = await self._get_guild(result["guild_id"])

                if guild:
                    return factory(guild=guild, state=self, data=result)
            else:
                return DMChannel(me=self.user, state=self, data=result)

        return None