Fix cyclic imports

This commit is contained in:
Lonami Exo 2023-10-19 22:41:55 +02:00
parent b8b9836cf7
commit 257b5d74e9
4 changed files with 15 additions and 4 deletions

View File

@ -3,7 +3,6 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Dict, Optional, Self, Union
from ...tl import abcs, types
from ..utils import peer_id
from .chat import Chat
from .draft import Draft
from .message import Message
@ -52,6 +51,8 @@ class Dialog(metaclass=NoPublicConstructor):
"""
The chat where messages are sent in this dialog.
"""
from ..utils import peer_id
return self._chat_map[peer_id(self._raw.peer)]
@property

View File

@ -6,7 +6,6 @@ from typing import TYPE_CHECKING, Dict, Optional, Self
from ...session import PackedChat
from ...tl import abcs, functions, types
from ..parsers import generate_html_message, generate_markdown_message
from ..utils import expand_peer, generate_random_id, peer_id
from .chat import Chat
from .message import Message
from .meta import NoPublicConstructor
@ -59,6 +58,8 @@ class Draft(metaclass=NoPublicConstructor):
"""
The chat where the draft will be sent to.
"""
from ..utils import expand_peer, peer_id
return self._chat_map.get(peer_id(self._peer)) or expand_peer(
self._peer, broadcast=None
)
@ -158,6 +159,8 @@ class Draft(metaclass=NoPublicConstructor):
)
async def _packed_chat(self) -> PackedChat:
from ..utils import peer_id
packed = None
if chat := self._chat_map.get(peer_id(self._peer)):
packed = chat.pack()
@ -179,6 +182,7 @@ class Draft(metaclass=NoPublicConstructor):
await draft.send(clear=False)
"""
from ..utils import generate_random_id
packed = await self._packed_chat()
peer = packed._to_input_peer()

View File

@ -3,7 +3,6 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Optional, Union
from ...tl import abcs, functions, types
from ..utils import generate_random_id
from .chat import ChatLike
from .message import Message
from .meta import NoPublicConstructor
@ -51,6 +50,8 @@ class InlineResult(metaclass=NoPublicConstructor):
:return: The sent message.
"""
from ..utils import generate_random_id
if chat is None and isinstance(self._default_peer, types.InputPeerEmpty):
raise ValueError("no target chat was specified")

View File

@ -5,7 +5,6 @@ from typing import TYPE_CHECKING, Any, Dict, Optional, Self, Union
from ...tl import abcs, types
from ..parsers import generate_html_message, generate_markdown_message
from ..utils import adapt_date, expand_peer, peer_id
from .chat import Chat, ChatLike
from .file import File
from .meta import NoPublicConstructor
@ -132,10 +131,14 @@ class Message(metaclass=NoPublicConstructor):
@property
def date(self) -> Optional[datetime.datetime]:
from ..utils import adapt_date
return adapt_date(getattr(self._raw, "date", None))
@property
def chat(self) -> Chat:
from ..utils import expand_peer, peer_id
peer = self._raw.peer_id or types.PeerUser(user_id=0)
broadcast = broadcast = getattr(self._raw, "post", None)
return self._chat_map.get(peer_id(peer)) or expand_peer(
@ -144,6 +147,8 @@ class Message(metaclass=NoPublicConstructor):
@property
def sender(self) -> Optional[Chat]:
from ..utils import expand_peer, peer_id
if (from_ := getattr(self._raw, "from_id", None)) is not None:
return self._chat_map.get(peer_id(from_)) or expand_peer(
from_, broadcast=getattr(self._raw, "post", None)