mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Rename Chat base class to Peer
This commit is contained in:
parent
031c128fef
commit
c95e979119
|
@ -25,7 +25,6 @@ from ..types import (
|
||||||
AdminRight,
|
AdminRight,
|
||||||
AlbumBuilder,
|
AlbumBuilder,
|
||||||
AsyncList,
|
AsyncList,
|
||||||
Chat,
|
|
||||||
ChatLike,
|
ChatLike,
|
||||||
ChatRestriction,
|
ChatRestriction,
|
||||||
Dialog,
|
Dialog,
|
||||||
|
@ -38,6 +37,7 @@ from ..types import (
|
||||||
OutFileLike,
|
OutFileLike,
|
||||||
Participant,
|
Participant,
|
||||||
PasswordToken,
|
PasswordToken,
|
||||||
|
Peer,
|
||||||
RecentAction,
|
RecentAction,
|
||||||
User,
|
User,
|
||||||
)
|
)
|
||||||
|
@ -253,7 +253,7 @@ class Client:
|
||||||
self._chat_hashes = ChatHashCache(None)
|
self._chat_hashes = ChatHashCache(None)
|
||||||
self._last_update_limit_warn: Optional[float] = None
|
self._last_update_limit_warn: Optional[float] = None
|
||||||
self._updates: asyncio.Queue[
|
self._updates: asyncio.Queue[
|
||||||
tuple[abcs.Update, dict[int, Chat]]
|
tuple[abcs.Update, dict[int, Peer]]
|
||||||
] = asyncio.Queue(maxsize=self._config.update_queue_limit or 0)
|
] = asyncio.Queue(maxsize=self._config.update_queue_limit or 0)
|
||||||
self._dispatcher: Optional[asyncio.Task[None]] = None
|
self._dispatcher: Optional[asyncio.Task[None]] = None
|
||||||
self._handlers: dict[
|
self._handlers: dict[
|
||||||
|
@ -676,11 +676,11 @@ class Client:
|
||||||
|
|
||||||
async def get_chats(
|
async def get_chats(
|
||||||
self, chats: list[ChatLike] | tuple[ChatLike, ...]
|
self, chats: list[ChatLike] | tuple[ChatLike, ...]
|
||||||
) -> list[Chat]:
|
) -> list[Peer]:
|
||||||
"""
|
"""
|
||||||
Get the latest basic information about the given chats.
|
Get the latest basic information about the given chats.
|
||||||
|
|
||||||
This method is most commonly used to turn one or more :class:`~types.PackedChat` into the original :class:`~types.Chat`.
|
This method is most commonly used to turn one or more :class:`~types.PackedChat` into the original :class:`~types.Peer`.
|
||||||
This includes users, groups and broadcast channels.
|
This includes users, groups and broadcast channels.
|
||||||
|
|
||||||
:param chats:
|
:param chats:
|
||||||
|
@ -1227,12 +1227,12 @@ class Client:
|
||||||
"""
|
"""
|
||||||
return await request_login_code(self, phone)
|
return await request_login_code(self, phone)
|
||||||
|
|
||||||
async def resolve_username(self, username: str) -> Chat:
|
async def resolve_username(self, username: str) -> Peer:
|
||||||
"""
|
"""
|
||||||
Resolve a username into a :term:`chat`.
|
Resolve a username into a :term:`chat`.
|
||||||
|
|
||||||
This method is rather expensive to call.
|
This method is rather expensive to call.
|
||||||
It is recommended to use it once and then :meth:`types.Chat.pack` the result.
|
It is recommended to use it once and then :meth:`types.Peer.pack` the result.
|
||||||
The packed chat can then be used (and re-fetched) more cheaply.
|
The packed chat can then be used (and re-fetched) more cheaply.
|
||||||
|
|
||||||
:param username:
|
:param username:
|
||||||
|
|
|
@ -6,7 +6,7 @@ from typing import TYPE_CHECKING, Literal, Optional, Self
|
||||||
|
|
||||||
from ...session import PackedChat
|
from ...session import PackedChat
|
||||||
from ...tl import abcs, functions, types
|
from ...tl import abcs, functions, types
|
||||||
from ..types import AsyncList, Chat, ChatLike, Message, build_chat_map
|
from ..types import AsyncList, ChatLike, Message, Peer, build_chat_map
|
||||||
from ..types import buttons as btns
|
from ..types import buttons as btns
|
||||||
from ..types import generate_random_id, parse_message, peer_id
|
from ..types import generate_random_id, parse_message, peer_id
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ class MessageList(AsyncList[Message]):
|
||||||
|
|
||||||
def _extend_buffer(
|
def _extend_buffer(
|
||||||
self, client: Client, messages: abcs.messages.Messages
|
self, client: Client, messages: abcs.messages.Messages
|
||||||
) -> dict[int, Chat]:
|
) -> dict[int, Peer]:
|
||||||
if isinstance(messages, types.messages.MessagesNotModified):
|
if isinstance(messages, types.messages.MessagesNotModified):
|
||||||
self._total = messages.count
|
self._total = messages.count
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -8,9 +8,9 @@ from ...tl import abcs, functions, types
|
||||||
from ..types import (
|
from ..types import (
|
||||||
AsyncList,
|
AsyncList,
|
||||||
Channel,
|
Channel,
|
||||||
Chat,
|
|
||||||
ChatLike,
|
ChatLike,
|
||||||
Group,
|
Group,
|
||||||
|
Peer,
|
||||||
User,
|
User,
|
||||||
build_chat_map,
|
build_chat_map,
|
||||||
expand_peer,
|
expand_peer,
|
||||||
|
@ -52,7 +52,7 @@ def get_contacts(self: Client) -> AsyncList[User]:
|
||||||
return ContactList(self)
|
return ContactList(self)
|
||||||
|
|
||||||
|
|
||||||
def resolved_peer_to_chat(client: Client, resolved: abcs.contacts.ResolvedPeer) -> Chat:
|
def resolved_peer_to_chat(client: Client, resolved: abcs.contacts.ResolvedPeer) -> Peer:
|
||||||
assert isinstance(resolved, types.contacts.ResolvedPeer)
|
assert isinstance(resolved, types.contacts.ResolvedPeer)
|
||||||
|
|
||||||
map = build_chat_map(client, resolved.users, resolved.chats)
|
map = build_chat_map(client, resolved.users, resolved.chats)
|
||||||
|
@ -62,13 +62,13 @@ def resolved_peer_to_chat(client: Client, resolved: abcs.contacts.ResolvedPeer)
|
||||||
raise ValueError("no matching chat found in response")
|
raise ValueError("no matching chat found in response")
|
||||||
|
|
||||||
|
|
||||||
async def resolve_phone(client: Client, phone: str) -> Chat:
|
async def resolve_phone(client: Client, phone: str) -> Peer:
|
||||||
return resolved_peer_to_chat(
|
return resolved_peer_to_chat(
|
||||||
client, await client(functions.contacts.resolve_phone(phone=phone))
|
client, await client(functions.contacts.resolve_phone(phone=phone))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def resolve_username(self: Client, username: str) -> Chat:
|
async def resolve_username(self: Client, username: str) -> Peer:
|
||||||
return resolved_peer_to_chat(
|
return resolved_peer_to_chat(
|
||||||
self, await self(functions.contacts.resolve_username(username=username))
|
self, await self(functions.contacts.resolve_username(username=username))
|
||||||
)
|
)
|
||||||
|
@ -76,7 +76,7 @@ async def resolve_username(self: Client, username: str) -> Chat:
|
||||||
|
|
||||||
async def get_chats(
|
async def get_chats(
|
||||||
self: Client, chats: list[ChatLike] | tuple[ChatLike, ...]
|
self: Client, chats: list[ChatLike] | tuple[ChatLike, ...]
|
||||||
) -> list[Chat]:
|
) -> list[Peer]:
|
||||||
packed_chats: list[PackedChat] = []
|
packed_chats: list[PackedChat] = []
|
||||||
input_users: list[types.InputUser] = []
|
input_users: list[types.InputUser] = []
|
||||||
input_chats: list[int] = []
|
input_chats: list[int] = []
|
||||||
|
|
|
@ -4,7 +4,7 @@ import abc
|
||||||
from typing import TYPE_CHECKING, Optional, Self
|
from typing import TYPE_CHECKING, Optional, Self
|
||||||
|
|
||||||
from ...tl import abcs
|
from ...tl import abcs
|
||||||
from ..types import Chat, NoPublicConstructor
|
from ..types import NoPublicConstructor, Peer
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..client.client import Client
|
from ..client.client import Client
|
||||||
|
@ -25,7 +25,7 @@ class Event(metaclass=NoPublicConstructor):
|
||||||
@classmethod
|
@classmethod
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def _try_from_update(
|
def _try_from_update(
|
||||||
cls, client: Client, update: abcs.Update, chat_map: dict[int, Chat]
|
cls, client: Client, update: abcs.Update, chat_map: dict[int, Peer]
|
||||||
) -> Optional[Self]:
|
) -> Optional[Self]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||||
from typing import TYPE_CHECKING, Optional, Self, Sequence
|
from typing import TYPE_CHECKING, Optional, Self, Sequence
|
||||||
|
|
||||||
from ...tl import abcs, types
|
from ...tl import abcs, types
|
||||||
from ..types import Chat, Message, expand_peer, peer_id
|
from ..types import Message, Peer, expand_peer, peer_id
|
||||||
from .event import Event
|
from .event import Event
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -25,7 +25,7 @@ class NewMessage(Event, Message):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _try_from_update(
|
def _try_from_update(
|
||||||
cls, client: Client, update: abcs.Update, chat_map: dict[int, Chat]
|
cls, client: Client, update: abcs.Update, chat_map: dict[int, Peer]
|
||||||
) -> Optional[Self]:
|
) -> Optional[Self]:
|
||||||
if isinstance(update, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
|
if isinstance(update, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
|
||||||
if isinstance(update.message, types.Message):
|
if isinstance(update.message, types.Message):
|
||||||
|
@ -47,7 +47,7 @@ class MessageEdited(Event, Message):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _try_from_update(
|
def _try_from_update(
|
||||||
cls, client: Client, update: abcs.Update, chat_map: dict[int, Chat]
|
cls, client: Client, update: abcs.Update, chat_map: dict[int, Peer]
|
||||||
) -> Optional[Self]:
|
) -> Optional[Self]:
|
||||||
if isinstance(
|
if isinstance(
|
||||||
update, (types.UpdateEditMessage, types.UpdateEditChannelMessage)
|
update, (types.UpdateEditMessage, types.UpdateEditChannelMessage)
|
||||||
|
@ -75,7 +75,7 @@ class MessageDeleted(Event):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _try_from_update(
|
def _try_from_update(
|
||||||
cls, client: Client, update: abcs.Update, chat_map: dict[int, Chat]
|
cls, client: Client, update: abcs.Update, chat_map: dict[int, Peer]
|
||||||
) -> Optional[Self]:
|
) -> Optional[Self]:
|
||||||
if isinstance(update, types.UpdateDeleteMessages):
|
if isinstance(update, types.UpdateDeleteMessages):
|
||||||
return cls._create(update.messages, None)
|
return cls._create(update.messages, None)
|
||||||
|
@ -115,7 +115,7 @@ class MessageRead(Event):
|
||||||
| types.UpdateReadChannelInbox
|
| types.UpdateReadChannelInbox
|
||||||
| types.UpdateReadChannelOutbox
|
| types.UpdateReadChannelOutbox
|
||||||
),
|
),
|
||||||
chat_map: dict[int, Chat],
|
chat_map: dict[int, Peer],
|
||||||
) -> None:
|
) -> None:
|
||||||
self._client = client
|
self._client = client
|
||||||
self._raw = update
|
self._raw = update
|
||||||
|
@ -123,7 +123,7 @@ class MessageRead(Event):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _try_from_update(
|
def _try_from_update(
|
||||||
cls, client: Client, update: abcs.Update, chat_map: dict[int, Chat]
|
cls, client: Client, update: abcs.Update, chat_map: dict[int, Peer]
|
||||||
) -> Optional[Self]:
|
) -> Optional[Self]:
|
||||||
if isinstance(
|
if isinstance(
|
||||||
update,
|
update,
|
||||||
|
@ -147,7 +147,7 @@ class MessageRead(Event):
|
||||||
return types.PeerChannel(channel_id=self._raw.channel_id)
|
return types.PeerChannel(channel_id=self._raw.channel_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chat(self) -> Chat:
|
def chat(self) -> Peer:
|
||||||
"""
|
"""
|
||||||
The :term:`chat` when the messages were read.
|
The :term:`chat` when the messages were read.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,7 +4,7 @@ from typing import TYPE_CHECKING, Optional, Self
|
||||||
|
|
||||||
from ...tl import abcs, functions, types
|
from ...tl import abcs, functions, types
|
||||||
from ..client.messages import CherryPickedList
|
from ..client.messages import CherryPickedList
|
||||||
from ..types import Chat, Message
|
from ..types import Message, Peer
|
||||||
from ..types.peer import peer_id
|
from ..types.peer import peer_id
|
||||||
from .event import Event
|
from .event import Event
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class ButtonCallback(Event):
|
||||||
self,
|
self,
|
||||||
client: Client,
|
client: Client,
|
||||||
update: types.UpdateBotCallbackQuery,
|
update: types.UpdateBotCallbackQuery,
|
||||||
chat_map: dict[int, Chat],
|
chat_map: dict[int, Peer],
|
||||||
):
|
):
|
||||||
self._client = client
|
self._client = client
|
||||||
self._raw = update
|
self._raw = update
|
||||||
|
@ -31,7 +31,7 @@ class ButtonCallback(Event):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _try_from_update(
|
def _try_from_update(
|
||||||
cls, client: Client, update: abcs.Update, chat_map: dict[int, Chat]
|
cls, client: Client, update: abcs.Update, chat_map: dict[int, Peer]
|
||||||
) -> Optional[Self]:
|
) -> Optional[Self]:
|
||||||
if isinstance(update, types.UpdateBotCallbackQuery) and update.data is not None:
|
if isinstance(update, types.UpdateBotCallbackQuery) and update.data is not None:
|
||||||
return cls._create(client, update, chat_map)
|
return cls._create(client, update, chat_map)
|
||||||
|
@ -105,7 +105,7 @@ class InlineQuery(Event):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _try_from_update(
|
def _try_from_update(
|
||||||
cls, client: Client, update: abcs.Update, chat_map: dict[int, Chat]
|
cls, client: Client, update: abcs.Update, chat_map: dict[int, Peer]
|
||||||
) -> Optional[Self]:
|
) -> Optional[Self]:
|
||||||
if isinstance(update, types.UpdateBotInlineQuery):
|
if isinstance(update, types.UpdateBotInlineQuery):
|
||||||
return cls._create(update)
|
return cls._create(update)
|
||||||
|
|
|
@ -27,9 +27,9 @@ from .participant import Participant
|
||||||
from .password_token import PasswordToken
|
from .password_token import PasswordToken
|
||||||
from .peer import (
|
from .peer import (
|
||||||
Channel,
|
Channel,
|
||||||
Chat,
|
|
||||||
ChatLike,
|
ChatLike,
|
||||||
Group,
|
Group,
|
||||||
|
Peer,
|
||||||
User,
|
User,
|
||||||
build_chat_map,
|
build_chat_map,
|
||||||
expand_peer,
|
expand_peer,
|
||||||
|
@ -44,7 +44,7 @@ __all__ = [
|
||||||
"ChatRestriction",
|
"ChatRestriction",
|
||||||
"CallbackAnswer",
|
"CallbackAnswer",
|
||||||
"Channel",
|
"Channel",
|
||||||
"Chat",
|
"Peer",
|
||||||
"ChatLike",
|
"ChatLike",
|
||||||
"Group",
|
"Group",
|
||||||
"User",
|
"User",
|
||||||
|
|
|
@ -6,7 +6,7 @@ from ...tl import abcs, types
|
||||||
from .draft import Draft
|
from .draft import Draft
|
||||||
from .message import Message
|
from .message import Message
|
||||||
from .meta import NoPublicConstructor
|
from .meta import NoPublicConstructor
|
||||||
from .peer import Chat, peer_id
|
from .peer import Peer, peer_id
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..client.client import Client
|
from ..client.client import Client
|
||||||
|
@ -27,7 +27,7 @@ class Dialog(metaclass=NoPublicConstructor):
|
||||||
self,
|
self,
|
||||||
client: Client,
|
client: Client,
|
||||||
raw: types.Dialog | types.DialogFolder,
|
raw: types.Dialog | types.DialogFolder,
|
||||||
chat_map: dict[int, Chat],
|
chat_map: dict[int, Peer],
|
||||||
msg_map: dict[int, Message],
|
msg_map: dict[int, Message],
|
||||||
) -> None:
|
) -> None:
|
||||||
self._client = client
|
self._client = client
|
||||||
|
@ -40,14 +40,14 @@ class Dialog(metaclass=NoPublicConstructor):
|
||||||
cls,
|
cls,
|
||||||
client: Client,
|
client: Client,
|
||||||
dialog: abcs.Dialog,
|
dialog: abcs.Dialog,
|
||||||
chat_map: dict[int, Chat],
|
chat_map: dict[int, Peer],
|
||||||
msg_map: dict[int, Message],
|
msg_map: dict[int, Message],
|
||||||
) -> Self:
|
) -> Self:
|
||||||
assert isinstance(dialog, (types.Dialog, types.DialogFolder))
|
assert isinstance(dialog, (types.Dialog, types.DialogFolder))
|
||||||
return cls._create(client, dialog, chat_map, msg_map)
|
return cls._create(client, dialog, chat_map, msg_map)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chat(self) -> Chat:
|
def chat(self) -> Peer:
|
||||||
"""
|
"""
|
||||||
The chat where messages are sent in this dialog.
|
The chat where messages are sent in this dialog.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -8,7 +8,7 @@ from ...tl import abcs, functions, types
|
||||||
from ..parsers import generate_html_message, generate_markdown_message
|
from ..parsers import generate_html_message, generate_markdown_message
|
||||||
from .message import Message, generate_random_id
|
from .message import Message, generate_random_id
|
||||||
from .meta import NoPublicConstructor
|
from .meta import NoPublicConstructor
|
||||||
from .peer import Chat, expand_peer, peer_id
|
from .peer import Peer, expand_peer, peer_id
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..client.client import Client
|
from ..client.client import Client
|
||||||
|
@ -27,7 +27,7 @@ class Draft(metaclass=NoPublicConstructor):
|
||||||
peer: abcs.Peer,
|
peer: abcs.Peer,
|
||||||
top_msg_id: Optional[int],
|
top_msg_id: Optional[int],
|
||||||
raw: abcs.DraftMessage,
|
raw: abcs.DraftMessage,
|
||||||
chat_map: dict[int, Chat],
|
chat_map: dict[int, Peer],
|
||||||
) -> None:
|
) -> None:
|
||||||
assert isinstance(raw, (types.DraftMessage, types.DraftMessageEmpty))
|
assert isinstance(raw, (types.DraftMessage, types.DraftMessageEmpty))
|
||||||
self._client = client
|
self._client = client
|
||||||
|
@ -38,7 +38,7 @@ class Draft(metaclass=NoPublicConstructor):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _from_raw_update(
|
def _from_raw_update(
|
||||||
cls, client: Client, draft: types.UpdateDraftMessage, chat_map: dict[int, Chat]
|
cls, client: Client, draft: types.UpdateDraftMessage, chat_map: dict[int, Peer]
|
||||||
) -> Self:
|
) -> Self:
|
||||||
return cls._create(client, draft.peer, draft.top_msg_id, draft.draft, chat_map)
|
return cls._create(client, draft.peer, draft.top_msg_id, draft.draft, chat_map)
|
||||||
|
|
||||||
|
@ -49,12 +49,12 @@ class Draft(metaclass=NoPublicConstructor):
|
||||||
peer: abcs.Peer,
|
peer: abcs.Peer,
|
||||||
top_msg_id: int,
|
top_msg_id: int,
|
||||||
draft: abcs.DraftMessage,
|
draft: abcs.DraftMessage,
|
||||||
chat_map: dict[int, Chat],
|
chat_map: dict[int, Peer],
|
||||||
) -> Self:
|
) -> Self:
|
||||||
return cls._create(client, peer, top_msg_id, draft, chat_map)
|
return cls._create(client, peer, top_msg_id, draft, chat_map)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chat(self) -> Chat:
|
def chat(self) -> Peer:
|
||||||
"""
|
"""
|
||||||
The chat where the draft is saved.
|
The chat where the draft is saved.
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ from ..parsers import (
|
||||||
from .buttons import Button, as_concrete_row, create_button
|
from .buttons import Button, as_concrete_row, create_button
|
||||||
from .file import File
|
from .file import File
|
||||||
from .meta import NoPublicConstructor
|
from .meta import NoPublicConstructor
|
||||||
from .peer import Chat, ChatLike, expand_peer, peer_id
|
from .peer import ChatLike, Peer, expand_peer, peer_id
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..client.client import Client
|
from ..client.client import Client
|
||||||
|
@ -58,7 +58,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, client: Client, message: abcs.Message, chat_map: dict[int, Chat]
|
self, client: Client, message: abcs.Message, chat_map: dict[int, Peer]
|
||||||
) -> None:
|
) -> None:
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
message, (types.Message, types.MessageService, types.MessageEmpty)
|
message, (types.Message, types.MessageService, types.MessageEmpty)
|
||||||
|
@ -69,7 +69,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _from_raw(
|
def _from_raw(
|
||||||
cls, client: Client, message: abcs.Message, chat_map: dict[int, Chat]
|
cls, client: Client, message: abcs.Message, chat_map: dict[int, Peer]
|
||||||
) -> Self:
|
) -> Self:
|
||||||
return cls._create(client, message, chat_map)
|
return cls._create(client, message, chat_map)
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
def _from_defaults(
|
def _from_defaults(
|
||||||
cls,
|
cls,
|
||||||
client: Client,
|
client: Client,
|
||||||
chat_map: dict[int, Chat],
|
chat_map: dict[int, Peer],
|
||||||
id: int,
|
id: int,
|
||||||
peer_id: abcs.Peer,
|
peer_id: abcs.Peer,
|
||||||
date: int,
|
date: int,
|
||||||
|
@ -184,7 +184,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
return adapt_date(getattr(self._raw, "date", None))
|
return adapt_date(getattr(self._raw, "date", None))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chat(self) -> Chat:
|
def chat(self) -> Peer:
|
||||||
"""
|
"""
|
||||||
The :term:`chat` when the message was sent.
|
The :term:`chat` when the message was sent.
|
||||||
"""
|
"""
|
||||||
|
@ -197,7 +197,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
return self._chat_map[pid]
|
return self._chat_map[pid]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sender(self) -> Optional[Chat]:
|
def sender(self) -> Optional[Peer]:
|
||||||
"""
|
"""
|
||||||
The :term:`chat` that sent the message.
|
The :term:`chat` that sent the message.
|
||||||
|
|
||||||
|
@ -502,7 +502,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
|
|
||||||
|
|
||||||
def build_msg_map(
|
def build_msg_map(
|
||||||
client: Client, messages: Sequence[abcs.Message], chat_map: dict[int, Chat]
|
client: Client, messages: Sequence[abcs.Message], chat_map: dict[int, Peer]
|
||||||
) -> dict[int, Message]:
|
) -> dict[int, Message]:
|
||||||
return {
|
return {
|
||||||
msg.id: msg
|
msg.id: msg
|
||||||
|
|
|
@ -8,7 +8,7 @@ from ...tl import abcs, types
|
||||||
from .admin_right import AdminRight
|
from .admin_right import AdminRight
|
||||||
from .chat_restriction import ChatRestriction
|
from .chat_restriction import ChatRestriction
|
||||||
from .meta import NoPublicConstructor
|
from .meta import NoPublicConstructor
|
||||||
from .peer import Chat, User, peer_id
|
from .peer import Peer, User, peer_id
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..client.client import Client
|
from ..client.client import Client
|
||||||
|
@ -36,7 +36,7 @@ class Participant(metaclass=NoPublicConstructor):
|
||||||
| types.ChatParticipantCreator
|
| types.ChatParticipantCreator
|
||||||
| types.ChatParticipantAdmin
|
| types.ChatParticipantAdmin
|
||||||
),
|
),
|
||||||
chat_map: dict[int, Chat],
|
chat_map: dict[int, Peer],
|
||||||
) -> None:
|
) -> None:
|
||||||
self._client = client
|
self._client = client
|
||||||
self._chat = chat
|
self._chat = chat
|
||||||
|
@ -49,7 +49,7 @@ class Participant(metaclass=NoPublicConstructor):
|
||||||
client: Client,
|
client: Client,
|
||||||
chat: PackedChat,
|
chat: PackedChat,
|
||||||
participant: abcs.ChannelParticipant,
|
participant: abcs.ChannelParticipant,
|
||||||
chat_map: dict[int, Chat],
|
chat_map: dict[int, Peer],
|
||||||
) -> Self:
|
) -> Self:
|
||||||
if isinstance(
|
if isinstance(
|
||||||
participant,
|
participant,
|
||||||
|
@ -72,7 +72,7 @@ class Participant(metaclass=NoPublicConstructor):
|
||||||
client: Client,
|
client: Client,
|
||||||
chat: PackedChat,
|
chat: PackedChat,
|
||||||
participant: abcs.ChatParticipant,
|
participant: abcs.ChatParticipant,
|
||||||
chat_map: dict[int, Chat],
|
chat_map: dict[int, Peer],
|
||||||
) -> Self:
|
) -> Self:
|
||||||
if isinstance(
|
if isinstance(
|
||||||
participant,
|
participant,
|
||||||
|
@ -129,7 +129,7 @@ class Participant(metaclass=NoPublicConstructor):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def banned(self) -> Optional[Chat]:
|
def banned(self) -> Optional[Peer]:
|
||||||
"""
|
"""
|
||||||
The banned participant.
|
The banned participant.
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ class Participant(metaclass=NoPublicConstructor):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def left(self) -> Optional[Chat]:
|
def left(self) -> Optional[Peer]:
|
||||||
"""
|
"""
|
||||||
The participant that has left the group.
|
The participant that has left the group.
|
||||||
|
|
||||||
|
|
|
@ -9,18 +9,18 @@ from ....session import PackedChat
|
||||||
from ....tl import abcs, types
|
from ....tl import abcs, types
|
||||||
from .channel import Channel
|
from .channel import Channel
|
||||||
from .group import Group
|
from .group import Group
|
||||||
from .peer import Chat
|
from .peer import Peer
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ...client.client import Client
|
from ...client.client import Client
|
||||||
|
|
||||||
ChatLike = Chat | PackedChat | int | str
|
ChatLike = Peer | PackedChat | int | str
|
||||||
|
|
||||||
|
|
||||||
def build_chat_map(
|
def build_chat_map(
|
||||||
client: Client, users: Sequence[abcs.User], chats: Sequence[abcs.Chat]
|
client: Client, users: Sequence[abcs.User], chats: Sequence[abcs.Chat]
|
||||||
) -> dict[int, Chat]:
|
) -> dict[int, Peer]:
|
||||||
users_iter = (User._from_raw(u) for u in users)
|
users_iter = (User._from_raw(u) for u in users)
|
||||||
chats_iter = (
|
chats_iter = (
|
||||||
(
|
(
|
||||||
|
@ -31,7 +31,7 @@ def build_chat_map(
|
||||||
for c in chats
|
for c in chats
|
||||||
)
|
)
|
||||||
|
|
||||||
result: dict[int, Chat] = {c.id: c for c in itertools.chain(users_iter, chats_iter)}
|
result: dict[int, Peer] = {c.id: c for c in itertools.chain(users_iter, chats_iter)}
|
||||||
|
|
||||||
if len(result) != len(users) + len(chats):
|
if len(result) != len(users) + len(chats):
|
||||||
# The fabled ID collision between different chat types.
|
# The fabled ID collision between different chat types.
|
||||||
|
@ -66,7 +66,7 @@ def peer_id(peer: abcs.Peer) -> int:
|
||||||
raise RuntimeError("unexpected case")
|
raise RuntimeError("unexpected case")
|
||||||
|
|
||||||
|
|
||||||
def expand_peer(client: Client, peer: abcs.Peer, *, broadcast: Optional[bool]) -> Chat:
|
def expand_peer(client: Client, peer: abcs.Peer, *, broadcast: Optional[bool]) -> Peer:
|
||||||
if isinstance(peer, types.PeerUser):
|
if isinstance(peer, types.PeerUser):
|
||||||
return User._from_raw(types.UserEmpty(id=peer.user_id))
|
return User._from_raw(types.UserEmpty(id=peer.user_id))
|
||||||
elif isinstance(peer, types.PeerChat):
|
elif isinstance(peer, types.PeerChat):
|
||||||
|
@ -93,4 +93,4 @@ def expand_peer(client: Client, peer: abcs.Peer, *, broadcast: Optional[bool]) -
|
||||||
raise RuntimeError("unexpected case")
|
raise RuntimeError("unexpected case")
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["Channel", "Chat", "Group", "User"]
|
__all__ = ["Channel", "Peer", "Group", "User"]
|
||||||
|
|
|
@ -3,10 +3,10 @@ from typing import Optional, Self
|
||||||
from ....session import PackedChat, PackedType
|
from ....session import PackedChat, PackedType
|
||||||
from ....tl import abcs, types
|
from ....tl import abcs, types
|
||||||
from ..meta import NoPublicConstructor
|
from ..meta import NoPublicConstructor
|
||||||
from .peer import Chat
|
from .peer import Peer
|
||||||
|
|
||||||
|
|
||||||
class Channel(Chat, metaclass=NoPublicConstructor):
|
class Channel(Peer, metaclass=NoPublicConstructor):
|
||||||
"""
|
"""
|
||||||
A broadcast channel.
|
A broadcast channel.
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,13 @@ from ....session import PackedChat, PackedType
|
||||||
from ....tl import abcs, types
|
from ....tl import abcs, types
|
||||||
from ..chat_restriction import ChatRestriction
|
from ..chat_restriction import ChatRestriction
|
||||||
from ..meta import NoPublicConstructor
|
from ..meta import NoPublicConstructor
|
||||||
from .peer import Chat
|
from .peer import Peer
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ...client.client import Client
|
from ...client.client import Client
|
||||||
|
|
||||||
|
|
||||||
class Group(Chat, metaclass=NoPublicConstructor):
|
class Group(Peer, metaclass=NoPublicConstructor):
|
||||||
"""
|
"""
|
||||||
A small group or supergroup.
|
A small group or supergroup.
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ from typing import Optional
|
||||||
from ....session import PackedChat
|
from ....session import PackedChat
|
||||||
|
|
||||||
|
|
||||||
class Chat(abc.ABC):
|
class Peer(abc.ABC):
|
||||||
"""
|
"""
|
||||||
The base class for all chat types.
|
The base class for all chat types.
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,10 @@ from typing import Optional, Self
|
||||||
from ....session import PackedChat, PackedType
|
from ....session import PackedChat, PackedType
|
||||||
from ....tl import abcs, types
|
from ....tl import abcs, types
|
||||||
from ..meta import NoPublicConstructor
|
from ..meta import NoPublicConstructor
|
||||||
from .peer import Chat
|
from .peer import Peer
|
||||||
|
|
||||||
|
|
||||||
class User(Chat, metaclass=NoPublicConstructor):
|
class User(Peer, metaclass=NoPublicConstructor):
|
||||||
"""
|
"""
|
||||||
A user, representing either a bot account or an account created with a phone number.
|
A user, representing either a bot account or an account created with a phone number.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from ...tl import abcs, types
|
from ...tl import abcs, types
|
||||||
from .meta import NoPublicConstructor
|
from .meta import NoPublicConstructor
|
||||||
from .peer import Chat
|
from .peer import Peer
|
||||||
|
|
||||||
|
|
||||||
class RecentAction(metaclass=NoPublicConstructor):
|
class RecentAction(metaclass=NoPublicConstructor):
|
||||||
|
@ -15,7 +15,7 @@ class RecentAction(metaclass=NoPublicConstructor):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
event: abcs.ChannelAdminLogEvent,
|
event: abcs.ChannelAdminLogEvent,
|
||||||
chat_map: dict[int, Chat],
|
chat_map: dict[int, Peer],
|
||||||
) -> None:
|
) -> None:
|
||||||
assert isinstance(event, types.ChannelAdminLogEvent)
|
assert isinstance(event, types.ChannelAdminLogEvent)
|
||||||
self._raw = event
|
self._raw = event
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
"""
|
"""
|
||||||
Classes for the various objects the library returns.
|
Classes for the various objects the library returns.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .._impl.client.types import (
|
from .._impl.client.types import (
|
||||||
AdminRight,
|
AdminRight,
|
||||||
AlbumBuilder,
|
AlbumBuilder,
|
||||||
AsyncList,
|
AsyncList,
|
||||||
CallbackAnswer,
|
CallbackAnswer,
|
||||||
Channel,
|
Channel,
|
||||||
Chat,
|
|
||||||
ChatRestriction,
|
ChatRestriction,
|
||||||
Dialog,
|
Dialog,
|
||||||
Draft,
|
Draft,
|
||||||
|
@ -18,6 +18,7 @@ from .._impl.client.types import (
|
||||||
Message,
|
Message,
|
||||||
Participant,
|
Participant,
|
||||||
PasswordToken,
|
PasswordToken,
|
||||||
|
Peer,
|
||||||
RecentAction,
|
RecentAction,
|
||||||
User,
|
User,
|
||||||
)
|
)
|
||||||
|
@ -30,7 +31,7 @@ __all__ = [
|
||||||
"AsyncList",
|
"AsyncList",
|
||||||
"CallbackAnswer",
|
"CallbackAnswer",
|
||||||
"Channel",
|
"Channel",
|
||||||
"Chat",
|
"Peer",
|
||||||
"ChatRestriction",
|
"ChatRestriction",
|
||||||
"Dialog",
|
"Dialog",
|
||||||
"Draft",
|
"Draft",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user