mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-11 19:07:28 +03:00
add parent properties
This commit is contained in:
parent
23c0ebbefb
commit
40281d016c
4 changed files with 34 additions and 9 deletions
|
@ -4,15 +4,13 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from ..utils.types import Coro
|
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):
|
async def channel_delete_listener(self, gateway, payload: dict):
|
||||||
payload.update({"type": ChannelType(payload.pop("type"))})
|
payload.update({"type": ChannelType(payload.pop("type"))})
|
||||||
|
|
||||||
channel_cls = channel_types_for_converting.get(payload["type"], Channel)
|
channel = _choose_channel_type(payload)
|
||||||
|
|
||||||
channel = channel_cls.from_dict(payload)
|
|
||||||
|
|
||||||
await self.dispatch("on_channel_delete", (channel,))
|
await self.dispatch("on_channel_delete", (channel,))
|
||||||
|
|
||||||
|
|
|
@ -32,11 +32,11 @@ class CacheManager:
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
disabled: bool = False,
|
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,
|
auto_unused_attributes: Optional[Dict[Any, List[str]]] = None,
|
||||||
):
|
):
|
||||||
self._auto_models: List[AutoCacheModels] = (
|
self._disabled_auto_models: List[AutoCacheModels] = (
|
||||||
[] if auto_models is None else auto_models
|
[] if disabled_auto_models is None else disabled_auto_models
|
||||||
)
|
)
|
||||||
self.auto_unused_attributes: Dict[Any, List[str]] = (
|
self.auto_unused_attributes: Dict[Any, List[str]] = (
|
||||||
{} if auto_unused_attributes is not None else auto_unused_attributes
|
{} if auto_unused_attributes is not None else auto_unused_attributes
|
||||||
|
@ -105,9 +105,9 @@ class CacheManager:
|
||||||
if hasattr(guild, "channels"):
|
if hasattr(guild, "channels"):
|
||||||
channels = guild.channels.values()
|
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(
|
channels = filter(
|
||||||
lambda channel: channel.type != ChannelType.GUILD_TEXT, channels
|
lambda channel: channel.type == ChannelType.GUILD_TEXT, channels
|
||||||
)
|
)
|
||||||
|
|
||||||
for sym in channels:
|
for sym in channels:
|
||||||
|
|
|
@ -116,6 +116,8 @@ class Channel(APIModelBase):
|
||||||
guild_id: :class:`~melisa.utils.types.Snowflake`
|
guild_id: :class:`~melisa.utils.types.Snowflake`
|
||||||
The id of the guild
|
The id of the guild
|
||||||
(may be missing for some channel objects received over gateway guild dispatches)
|
(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`
|
position: :class:`int`
|
||||||
Sorting position of the channel
|
Sorting position of the channel
|
||||||
permission_overwrites: :class:`typing.Any`
|
permission_overwrites: :class:`typing.Any`
|
||||||
|
@ -203,6 +205,12 @@ class Channel(APIModelBase):
|
||||||
def mention(self):
|
def mention(self):
|
||||||
return f"<#{self.id}>"
|
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):
|
async def edit(self, *, reason: Optional[str] = None, **kwargs):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
Edit a channel with the specified keyword arguments.
|
Edit a channel with the specified keyword arguments.
|
||||||
|
|
|
@ -184,6 +184,10 @@ class Message(APIModelBase):
|
||||||
Id of the message
|
Id of the message
|
||||||
channel_id: :class:`~melisa.utils.types.snowflake.Snowflake`
|
channel_id: :class:`~melisa.utils.types.snowflake.Snowflake`
|
||||||
Id of the channel the message was sent in
|
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`
|
guild_id: :class:`~melisa.utils.types.snowflake.Snowflake`
|
||||||
Id of the guild the message was sent in
|
Id of the guild the message was sent in
|
||||||
author: :class:`typing.Any`
|
author: :class:`typing.Any`
|
||||||
|
@ -351,6 +355,21 @@ class Message(APIModelBase):
|
||||||
|
|
||||||
return self
|
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):
|
async def pin(self, *, reason: Optional[str] = None):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue