add parent properties

This commit is contained in:
grey-cat-1908 2022-05-20 15:16:27 +03:00
parent 23c0ebbefb
commit 40281d016c
4 changed files with 34 additions and 9 deletions

View file

@ -4,15 +4,13 @@
from __future__ import annotations
from ..utils.types import Coro
from ..models.guild import Channel, ChannelType, channel_types_for_converting
from ..models.guild.channel import ChannelType, _choose_channel_type
async def channel_delete_listener(self, gateway, payload: dict):
payload.update({"type": ChannelType(payload.pop("type"))})
channel_cls = channel_types_for_converting.get(payload["type"], Channel)
channel = channel_cls.from_dict(payload)
channel = _choose_channel_type(payload)
await self.dispatch("on_channel_delete", (channel,))

View file

@ -32,11 +32,11 @@ class CacheManager:
self,
*,
disabled: bool = False,
auto_models: Optional[List[AutoCacheModels]] = None,
disabled_auto_models: Optional[List[AutoCacheModels]] = None,
auto_unused_attributes: Optional[Dict[Any, List[str]]] = None,
):
self._auto_models: List[AutoCacheModels] = (
[] if auto_models is None else auto_models
self._disabled_auto_models: List[AutoCacheModels] = (
[] if disabled_auto_models is None else disabled_auto_models
)
self.auto_unused_attributes: Dict[Any, List[str]] = (
{} if auto_unused_attributes is not None else auto_unused_attributes
@ -105,9 +105,9 @@ class CacheManager:
if hasattr(guild, "channels"):
channels = guild.channels.values()
if AutoCacheModels.TEXT_CHANNELS not in self._auto_models:
if AutoCacheModels.TEXT_CHANNELS not in self._disabled_auto_models:
channels = filter(
lambda channel: channel.type != ChannelType.GUILD_TEXT, channels
lambda channel: channel.type == ChannelType.GUILD_TEXT, channels
)
for sym in channels:

View file

@ -116,6 +116,8 @@ class Channel(APIModelBase):
guild_id: :class:`~melisa.utils.types.Snowflake`
The id of the guild
(may be missing for some channel objects received over gateway guild dispatches)
guild: Optional[:class:`~melisa.models.guild.Guild`]
Object of guild where channel is
position: :class:`int`
Sorting position of the channel
permission_overwrites: :class:`typing.Any`
@ -203,6 +205,12 @@ class Channel(APIModelBase):
def mention(self):
return f"<#{self.id}>"
@property
def guild(self):
if self.guild_id is not None:
return self._client.cache.get_guild(self.guild_id)
return None
async def edit(self, *, reason: Optional[str] = None, **kwargs):
"""|coro|
Edit a channel with the specified keyword arguments.

View file

@ -184,6 +184,10 @@ class Message(APIModelBase):
Id of the message
channel_id: :class:`~melisa.utils.types.snowflake.Snowflake`
Id of the channel the message was sent in
channel: :class:`~melisa.models.guild.Channel`
Object of channel where message was sent in
guild: :class:`~melisa.models.guild.Guild`
Object of guild where message was sent in
guild_id: :class:`~melisa.utils.types.snowflake.Snowflake`
Id of the guild the message was sent in
author: :class:`typing.Any`
@ -351,6 +355,21 @@ class Message(APIModelBase):
return self
@property
def guild(self):
if self.guild_id is not None:
return self._client.cache.get_guild(self.guild_id)
return None
@property
def channel(self):
print(self.channel_id)
print(self._client.cache._channel_symlinks)
if self.channel_id is not None:
return self._client.cache.get_guild_channel(self.channel_id)
return None
async def pin(self, *, reason: Optional[str] = None):
"""|coro|