Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.

Commit c6ab809

Browse files
committed
Добавил метод для получении информации о чате по ссылке
1 parent bae4476 commit c6ab809

2 files changed

Lines changed: 46 additions & 17 deletions

File tree

examples/example.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,22 @@
2828
async def handle_start() -> None:
2929
print(f"Client started as {client.me.names[0].first_name}!")
3030

31-
photo = Photo(path="/tests2/test.png")
32-
33-
await client.change_profile(
34-
first_name="Dima",
35-
photo=photo,
31+
"""
32+
case e.chat instanceof at:
33+
return na({ link: D, linkType: "CHANNEL" });
34+
case e.chat instanceof Ct:
35+
return na({ link: D, linkType: "CHAT" });
36+
"""
37+
data = await client._send_and_wait(
38+
opcode=Opcode.CHAT_CHECK_LINK,
39+
payload={
40+
"link": "inkomusic123",
41+
"linkType": "CHANNEL",
42+
},
3643
)
44+
45+
print(data)
46+
3747
# channel = await client.resolve_channel_by_name("fm92")
3848
# if channel:
3949
# print(f"Resolved channel by name: {channel.title}, ID: {channel.id}")

src/pymax/mixins/group.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ async def invite_users_to_group(
9595
operation="add",
9696
).model_dump(by_alias=True)
9797

98-
data = await self._send_and_wait(
99-
opcode=Opcode.CHAT_MEMBERS_UPDATE, payload=payload
100-
)
98+
data = await self._send_and_wait(opcode=Opcode.CHAT_MEMBERS_UPDATE, payload=payload)
10199

102100
if data.get("payload", {}).get("error"):
103101
MixinsUtils.handle_error(data)
@@ -155,9 +153,7 @@ async def remove_users_from_group(
155153
clean_msg_period=clean_msg_period,
156154
).model_dump(by_alias=True)
157155

158-
data = await self._send_and_wait(
159-
opcode=Opcode.CHAT_MEMBERS_UPDATE, payload=payload
160-
)
156+
data = await self._send_and_wait(opcode=Opcode.CHAT_MEMBERS_UPDATE, payload=payload)
161157

162158
if data.get("payload", {}).get("error"):
163159
MixinsUtils.handle_error(data)
@@ -293,6 +289,33 @@ async def join_group(self, link: str) -> Chat:
293289

294290
return chat
295291

292+
async def resolve_group_by_link(self, link: str) -> Chat | None:
293+
"""
294+
Разрешает группу по ссылке
295+
296+
Args:
297+
link (str): Ссылка на группу.
298+
299+
Returns:
300+
Chat | None: Объект чата группы или None, если не найдено.
301+
"""
302+
proceed_link = self._process_chat_join_link(link)
303+
if proceed_link is None:
304+
raise ValueError("Invalid group link")
305+
306+
data = await self._send_and_wait(
307+
opcode=Opcode.LINK_INFO,
308+
payload={
309+
"link": proceed_link,
310+
},
311+
)
312+
313+
if data.get("payload", {}).get("error"):
314+
MixinsUtils.handle_error(data)
315+
316+
chat = Chat.from_dict(data["payload"].get("chat", {}))
317+
return chat
318+
296319
async def rework_invite_link(self, chat_id: int) -> Chat:
297320
"""
298321
Пересоздает ссылку для приглашения в группу
@@ -329,14 +352,10 @@ async def get_chats(self, chat_ids: list[int]) -> list[Chat]:
329352
chat_id for chat_id in chat_ids if await self._get_chat(chat_id) is None
330353
]
331354
if missed_chat_ids:
332-
payload = GetChatInfoPayload(chat_ids=missed_chat_ids).model_dump(
333-
by_alias=True
334-
)
355+
payload = GetChatInfoPayload(chat_ids=missed_chat_ids).model_dump(by_alias=True)
335356
else:
336357
chats: list[Chat] = [
337-
chat
338-
for chat_id in chat_ids
339-
if (chat := await self._get_chat(chat_id)) is not None
358+
chat for chat_id in chat_ids if (chat := await self._get_chat(chat_id)) is not None
340359
]
341360
return chats
342361

0 commit comments

Comments
 (0)