maxapi-python 1.1.20__tar.gz → 1.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- maxapi_python-1.2.1/.coderabbit.yaml +6 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/PKG-INFO +44 -54
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/README.md +42 -53
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/examples/example.py +86 -21
- maxapi_python-1.2.1/examples/flt_test.py +51 -0
- maxapi_python-1.2.1/examples/large_file_upload.py +51 -0
- maxapi_python-1.2.1/examples/reg.py +34 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/examples/telegram_bridge.py +30 -46
- maxapi_python-1.2.1/examples/test.py +20 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/pyproject.toml +5 -1
- maxapi_python-1.2.1/pytest.ini +6 -0
- maxapi_python-1.2.1/redocs/Makefile +20 -0
- maxapi_python-1.2.1/redocs/build.sh +1 -0
- maxapi_python-1.2.1/redocs/make.bat +35 -0
- maxapi_python-1.2.1/redocs/source/_static/logo.svg +13 -0
- maxapi_python-1.2.1/redocs/source/clients.rst +126 -0
- maxapi_python-1.2.1/redocs/source/conf.py +49 -0
- maxapi_python-1.2.1/redocs/source/decorators.rst +6 -0
- maxapi_python-1.2.1/redocs/source/examples.rst +374 -0
- maxapi_python-1.2.1/redocs/source/guides.rst +483 -0
- maxapi_python-1.2.1/redocs/source/index.rst +112 -0
- maxapi_python-1.2.1/redocs/source/installation.rst +151 -0
- maxapi_python-1.2.1/redocs/source/quickstart.rst +246 -0
- maxapi_python-1.2.1/redocs/source/types.rst +8 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/core.py +79 -156
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/crud.py +3 -7
- maxapi_python-1.2.1/src/pymax/filters.py +164 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/formatter.py +1 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/formatting.py +4 -6
- maxapi_python-1.2.1/src/pymax/interfaces.py +256 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/mixins/__init__.py +3 -0
- maxapi_python-1.2.1/src/pymax/mixins/auth.py +368 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/mixins/channel.py +36 -37
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/mixins/group.py +127 -8
- maxapi_python-1.2.1/src/pymax/mixins/handler.py +291 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/mixins/message.py +251 -97
- maxapi_python-1.2.1/src/pymax/mixins/scheduler.py +28 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/mixins/self.py +79 -40
- maxapi_python-1.2.1/src/pymax/mixins/socket.py +620 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/mixins/user.py +63 -42
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/mixins/websocket.py +145 -145
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/payloads.py +12 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/static/constant.py +4 -2
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/static/enum.py +5 -0
- maxapi_python-1.1.20/docs/api.md +0 -716
- maxapi_python-1.1.20/docs/assets/icon.svg +0 -13
- maxapi_python-1.1.20/docs/client.md +0 -284
- maxapi_python-1.1.20/docs/examples.md +0 -149
- maxapi_python-1.1.20/docs/index.md +0 -45
- maxapi_python-1.1.20/docs/methods.md +0 -876
- maxapi_python-1.1.20/docs/types.md +0 -512
- maxapi_python-1.1.20/examples/reg.py +0 -13
- maxapi_python-1.1.20/src/pymax/filters.py +0 -47
- maxapi_python-1.1.20/src/pymax/interfaces.py +0 -116
- maxapi_python-1.1.20/src/pymax/mixins/auth.py +0 -169
- maxapi_python-1.1.20/src/pymax/mixins/handler.py +0 -167
- maxapi_python-1.1.20/src/pymax/mixins/socket.py +0 -647
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/.github/FUNDING.yml +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/.github/ISSUE_TEMPLATE/refactor.md +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/.github/pull_request_template.md +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/.github/workflows/publish.yml +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/.gitignore +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/.pre-commit-config.yaml +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/LICENSE +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/assets/icon.svg +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/assets/logo.svg +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/mkdocs.yml +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/ruff.toml +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/__init__.py +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/exceptions.py +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/files.py +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/mixins/telemetry.py +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/mixins/utils.py +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/models.py +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/navigation.py +0 -0
- {maxapi_python-1.1.20 → maxapi_python-1.2.1}/src/pymax/types.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: maxapi-python
|
|
3
|
-
Version: 1.1
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: Python wrapper для API мессенджера Max
|
|
5
5
|
Project-URL: Homepage, https://github.com/ink-developer/PyMax
|
|
6
6
|
Project-URL: Repository, https://github.com/ink-developer/PyMax
|
|
@@ -16,6 +16,7 @@ Requires-Dist: aiofiles>=24.1.0
|
|
|
16
16
|
Requires-Dist: aiohttp>=3.12.15
|
|
17
17
|
Requires-Dist: lz4>=4.4.4
|
|
18
18
|
Requires-Dist: msgpack>=1.1.1
|
|
19
|
+
Requires-Dist: qrcode>=8.2
|
|
19
20
|
Requires-Dist: sqlmodel>=0.0.24
|
|
20
21
|
Requires-Dist: websockets>=15.0
|
|
21
22
|
Description-Content-Type: text/markdown
|
|
@@ -35,6 +36,12 @@ Description-Content-Type: text/markdown
|
|
|
35
36
|
<img src="https://img.shields.io/badge/packaging-uv-D7FF64.svg" alt="Packaging">
|
|
36
37
|
</p>
|
|
37
38
|
|
|
39
|
+
> [!IMPORTANT]
|
|
40
|
+
> (20.12.25) Из за резкого изменения апи большая часть библиотеки не работает.
|
|
41
|
+
Смотрите [новость](https://t.me/pymax_news/111)
|
|
42
|
+
>
|
|
43
|
+
> P.s добавил логин по qr в dev/1.2.1
|
|
44
|
+
|
|
38
45
|
---
|
|
39
46
|
> ⚠️ **Дисклеймер**
|
|
40
47
|
>
|
|
@@ -79,65 +86,47 @@ uv add -U maxapi-python
|
|
|
79
86
|
|
|
80
87
|
```python
|
|
81
88
|
import asyncio
|
|
89
|
+
|
|
82
90
|
from pymax import MaxClient, Message
|
|
91
|
+
from pymax.filters import Filters
|
|
92
|
+
|
|
93
|
+
client = MaxClient(
|
|
94
|
+
phone="+1234567890",
|
|
95
|
+
work_dir="cache", # директория для сессий
|
|
96
|
+
)
|
|
97
|
+
|
|
83
98
|
|
|
84
|
-
#
|
|
85
|
-
|
|
86
|
-
|
|
99
|
+
# Обработка входящих сообщений
|
|
100
|
+
@client.on_message(Filters.chat(0)) # фильтр по ID чата
|
|
101
|
+
async def on_message(msg: Message) -> None:
|
|
102
|
+
print(f"[{msg.sender}] {msg.text}")
|
|
103
|
+
|
|
104
|
+
await client.send_message(
|
|
105
|
+
chat_id=msg.chat_id,
|
|
106
|
+
text="Привет, я бот на PyMax!",
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
await client.add_reaction(
|
|
110
|
+
chat_id=msg.chat_id,
|
|
111
|
+
message_id=str(msg.id),
|
|
112
|
+
reaction="👍",
|
|
113
|
+
)
|
|
87
114
|
|
|
88
|
-
# Обработчик входящих сообщений
|
|
89
|
-
@client.on_message()
|
|
90
|
-
async def handle_message(message: Message) -> None:
|
|
91
|
-
print(f"{message.sender}: {message.text}")
|
|
92
115
|
|
|
93
|
-
# Обработчик запуска клиента
|
|
94
116
|
@client.on_start
|
|
95
|
-
async def
|
|
96
|
-
print("Клиент
|
|
117
|
+
async def on_start() -> None:
|
|
118
|
+
print(f"Клиент запущен. Ваш ID: {client.me.id}")
|
|
97
119
|
|
|
98
|
-
# Получение истории
|
|
120
|
+
# Получение истории
|
|
99
121
|
history = await client.fetch_history(chat_id=0)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
# Работа с чатами
|
|
110
|
-
for chat in client.chats:
|
|
111
|
-
print(f"Чат: {chat.title}")
|
|
112
|
-
|
|
113
|
-
# Отправка сообщения
|
|
114
|
-
message = await client.send_message(
|
|
115
|
-
"Привет от PyMax!",
|
|
116
|
-
chat.id,
|
|
117
|
-
notify=True
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
# Редактирование сообщения
|
|
121
|
-
await asyncio.sleep(2)
|
|
122
|
-
await client.edit_message(
|
|
123
|
-
chat.id,
|
|
124
|
-
message.id,
|
|
125
|
-
"Привет от PyMax! (отредактировано)"
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
# Удаление сообщения
|
|
129
|
-
await asyncio.sleep(2)
|
|
130
|
-
await client.delete_message(chat.id, [message.id], for_me=False)
|
|
131
|
-
|
|
132
|
-
# Работа с диалогами
|
|
133
|
-
for dialog in client.dialogs:
|
|
134
|
-
print(f"Диалог: {dialog.last_message.text}")
|
|
135
|
-
|
|
136
|
-
# Работа с каналами
|
|
137
|
-
for channel in client.channels:
|
|
138
|
-
print(f"Канал: {channel.title}")
|
|
139
|
-
|
|
140
|
-
await client.close()
|
|
122
|
+
print("Последние сообщения из чата 0:")
|
|
123
|
+
for m in history:
|
|
124
|
+
print(f"- {m.text}")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
async def main():
|
|
128
|
+
await client.start() # подключение и авторизация
|
|
129
|
+
|
|
141
130
|
|
|
142
131
|
if __name__ == "__main__":
|
|
143
132
|
asyncio.run(main())
|
|
@@ -145,7 +134,8 @@ if __name__ == "__main__":
|
|
|
145
134
|
|
|
146
135
|
## Документация
|
|
147
136
|
|
|
148
|
-
[
|
|
137
|
+
[GitHub Pages](https://maxapiteam.github.io/PyMax/)
|
|
138
|
+
[DeepWiki](https://deepwiki.com/MaxApiTeam/PyMax)
|
|
149
139
|
|
|
150
140
|
## Лицензия
|
|
151
141
|
|
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
<img src="https://img.shields.io/badge/packaging-uv-D7FF64.svg" alt="Packaging">
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
|
+
> [!IMPORTANT]
|
|
17
|
+
> (20.12.25) Из за резкого изменения апи большая часть библиотеки не работает.
|
|
18
|
+
Смотрите [новость](https://t.me/pymax_news/111)
|
|
19
|
+
>
|
|
20
|
+
> P.s добавил логин по qr в dev/1.2.1
|
|
21
|
+
|
|
16
22
|
---
|
|
17
23
|
> ⚠️ **Дисклеймер**
|
|
18
24
|
>
|
|
@@ -57,65 +63,47 @@ uv add -U maxapi-python
|
|
|
57
63
|
|
|
58
64
|
```python
|
|
59
65
|
import asyncio
|
|
66
|
+
|
|
60
67
|
from pymax import MaxClient, Message
|
|
68
|
+
from pymax.filters import Filters
|
|
69
|
+
|
|
70
|
+
client = MaxClient(
|
|
71
|
+
phone="+1234567890",
|
|
72
|
+
work_dir="cache", # директория для сессий
|
|
73
|
+
)
|
|
74
|
+
|
|
61
75
|
|
|
62
|
-
#
|
|
63
|
-
|
|
64
|
-
|
|
76
|
+
# Обработка входящих сообщений
|
|
77
|
+
@client.on_message(Filters.chat(0)) # фильтр по ID чата
|
|
78
|
+
async def on_message(msg: Message) -> None:
|
|
79
|
+
print(f"[{msg.sender}] {msg.text}")
|
|
80
|
+
|
|
81
|
+
await client.send_message(
|
|
82
|
+
chat_id=msg.chat_id,
|
|
83
|
+
text="Привет, я бот на PyMax!",
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
await client.add_reaction(
|
|
87
|
+
chat_id=msg.chat_id,
|
|
88
|
+
message_id=str(msg.id),
|
|
89
|
+
reaction="👍",
|
|
90
|
+
)
|
|
65
91
|
|
|
66
|
-
# Обработчик входящих сообщений
|
|
67
|
-
@client.on_message()
|
|
68
|
-
async def handle_message(message: Message) -> None:
|
|
69
|
-
print(f"{message.sender}: {message.text}")
|
|
70
92
|
|
|
71
|
-
# Обработчик запуска клиента
|
|
72
93
|
@client.on_start
|
|
73
|
-
async def
|
|
74
|
-
print("Клиент
|
|
94
|
+
async def on_start() -> None:
|
|
95
|
+
print(f"Клиент запущен. Ваш ID: {client.me.id}")
|
|
75
96
|
|
|
76
|
-
# Получение истории
|
|
97
|
+
# Получение истории
|
|
77
98
|
history = await client.fetch_history(chat_id=0)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
# Работа с чатами
|
|
88
|
-
for chat in client.chats:
|
|
89
|
-
print(f"Чат: {chat.title}")
|
|
90
|
-
|
|
91
|
-
# Отправка сообщения
|
|
92
|
-
message = await client.send_message(
|
|
93
|
-
"Привет от PyMax!",
|
|
94
|
-
chat.id,
|
|
95
|
-
notify=True
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
# Редактирование сообщения
|
|
99
|
-
await asyncio.sleep(2)
|
|
100
|
-
await client.edit_message(
|
|
101
|
-
chat.id,
|
|
102
|
-
message.id,
|
|
103
|
-
"Привет от PyMax! (отредактировано)"
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
# Удаление сообщения
|
|
107
|
-
await asyncio.sleep(2)
|
|
108
|
-
await client.delete_message(chat.id, [message.id], for_me=False)
|
|
109
|
-
|
|
110
|
-
# Работа с диалогами
|
|
111
|
-
for dialog in client.dialogs:
|
|
112
|
-
print(f"Диалог: {dialog.last_message.text}")
|
|
113
|
-
|
|
114
|
-
# Работа с каналами
|
|
115
|
-
for channel in client.channels:
|
|
116
|
-
print(f"Канал: {channel.title}")
|
|
117
|
-
|
|
118
|
-
await client.close()
|
|
99
|
+
print("Последние сообщения из чата 0:")
|
|
100
|
+
for m in history:
|
|
101
|
+
print(f"- {m.text}")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
async def main():
|
|
105
|
+
await client.start() # подключение и авторизация
|
|
106
|
+
|
|
119
107
|
|
|
120
108
|
if __name__ == "__main__":
|
|
121
109
|
asyncio.run(main())
|
|
@@ -123,7 +111,8 @@ if __name__ == "__main__":
|
|
|
123
111
|
|
|
124
112
|
## Документация
|
|
125
113
|
|
|
126
|
-
[
|
|
114
|
+
[GitHub Pages](https://maxapiteam.github.io/PyMax/)
|
|
115
|
+
[DeepWiki](https://deepwiki.com/MaxApiTeam/PyMax)
|
|
127
116
|
|
|
128
117
|
## Лицензия
|
|
129
118
|
|
|
@@ -1,26 +1,73 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import datetime
|
|
3
|
+
import logging
|
|
4
|
+
from time import time
|
|
5
|
+
from typing import Any
|
|
3
6
|
|
|
7
|
+
import pymax
|
|
4
8
|
from pymax import MaxClient, Message, ReactionInfo, SocketMaxClient
|
|
5
9
|
from pymax.files import File, Video
|
|
6
|
-
from pymax.
|
|
10
|
+
from pymax.payloads import UserAgentPayload
|
|
7
11
|
from pymax.static.enum import AttachType, Opcode
|
|
8
12
|
from pymax.types import Chat
|
|
9
13
|
|
|
10
|
-
phone = "+
|
|
14
|
+
phone = "+7903223111"
|
|
15
|
+
headers = UserAgentPayload(device_type="WEB")
|
|
11
16
|
|
|
17
|
+
client = MaxClient(
|
|
18
|
+
phone=phone,
|
|
19
|
+
work_dir="cache",
|
|
20
|
+
reconnect=False,
|
|
21
|
+
logger=None,
|
|
22
|
+
headers=headers,
|
|
23
|
+
)
|
|
24
|
+
client.logger.setLevel(logging.INFO)
|
|
12
25
|
|
|
13
|
-
|
|
26
|
+
|
|
27
|
+
@client.on_raw_receive
|
|
28
|
+
async def handle_raw_receive(data: dict[str, Any]) -> None:
|
|
29
|
+
print(f"Raw data received: {data}")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@client.task(seconds=10)
|
|
33
|
+
async def periodic_task() -> None:
|
|
34
|
+
# print(f"Periodic task executed at {datetime.datetime.now()}")
|
|
35
|
+
...
|
|
14
36
|
|
|
15
37
|
|
|
16
38
|
@client.on_start
|
|
17
39
|
async def handle_start() -> None:
|
|
18
40
|
print(f"Client started as {client.me.names[0].first_name}!")
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
41
|
+
|
|
42
|
+
chat_id = -1
|
|
43
|
+
max_messages = 1000
|
|
44
|
+
messages = []
|
|
45
|
+
from_time = int(time() * 1000)
|
|
46
|
+
while len(messages) < max_messages:
|
|
47
|
+
r = await client.fetch_history(chat_id=chat_id, from_time=from_time, backward=30)
|
|
48
|
+
if not r:
|
|
49
|
+
break
|
|
50
|
+
from_time = r[0].time
|
|
51
|
+
messages.extend(r)
|
|
52
|
+
print(f"First message time: {from_time}, id: {r[0].id}, text: {r[0].text}")
|
|
53
|
+
print(f"Last message time: {from_time}, id: {r[-1].id}, text: {r[-1].text}")
|
|
54
|
+
print(f"Loaded {len(messages)}/{max_messages} messages...")
|
|
55
|
+
# channel = await client.resolve_channel_by_name("fm92")
|
|
56
|
+
# if channel:
|
|
57
|
+
# print(f"Resolved channel by name: {channel.title}, ID: {channel.id}")
|
|
58
|
+
# else:
|
|
59
|
+
# print("Channel not found by name.")
|
|
60
|
+
|
|
61
|
+
# channel = await client.join_channel(link)
|
|
62
|
+
# if channel:
|
|
63
|
+
# print(f"Joined channel: {channel.title}, ID: {channel.id}")
|
|
64
|
+
# else:
|
|
65
|
+
# print("Failed to join channel.")
|
|
66
|
+
# await client.send_message(
|
|
67
|
+
# "Hello! The client has started successfully.",
|
|
68
|
+
# chat_id=2265456546456,
|
|
69
|
+
# notify=True,
|
|
70
|
+
# )
|
|
24
71
|
# folder_update = await client.create_folder(
|
|
25
72
|
# title="My Folder",
|
|
26
73
|
# chat_include=[0],
|
|
@@ -63,21 +110,39 @@ async def handle_start() -> None:
|
|
|
63
110
|
# print(f"Member {member.contact.names[0].first_name}, ID: {member.contact.id}")
|
|
64
111
|
|
|
65
112
|
|
|
66
|
-
@client.on_reaction_change
|
|
67
|
-
async def handle_reaction_change(
|
|
68
|
-
|
|
69
|
-
) -> None:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
113
|
+
# @client.on_reaction_change
|
|
114
|
+
# async def handle_reaction_change(
|
|
115
|
+
# message_id: str, chat_id: int, reaction_info: ReactionInfo
|
|
116
|
+
# ) -> None:
|
|
117
|
+
# print(
|
|
118
|
+
# f"Reaction changed on message {message_id} in chat {chat_id}: "
|
|
119
|
+
# f"Total count: {reaction_info.total_count}, "
|
|
120
|
+
# f"Your reaction: {reaction_info.your_reaction}, "
|
|
121
|
+
# f"Counters: {reaction_info.counters[0].reaction}={reaction_info.counters[0].count}"
|
|
122
|
+
# )
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# @client.on_chat_update
|
|
126
|
+
# async def handle_chat_update(chat: Chat) -> None:
|
|
127
|
+
# print(f"Chat updated: {chat.id}, new title: {chat.title}")
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@client.on_message()
|
|
131
|
+
async def handle_message(message: Message) -> None:
|
|
132
|
+
print(f"New message in chat {message.chat_id} from {message.sender}: {message.text}")
|
|
133
|
+
# if message.link and message.link.message.attaches:
|
|
134
|
+
# for attach in message.link.message.attaches:
|
|
135
|
+
# print(f"Link attach type: {attach.type}")
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@client.on_message_edit()
|
|
139
|
+
async def handle_edited_message(message: Message) -> None:
|
|
140
|
+
print(f"Edited message in chat {message.chat_id}: {message.text}")
|
|
76
141
|
|
|
77
142
|
|
|
78
|
-
@client.
|
|
79
|
-
async def
|
|
80
|
-
print(f"
|
|
143
|
+
@client.on_message_delete()
|
|
144
|
+
async def handle_deleted_message(message: Message) -> None:
|
|
145
|
+
print(f"Deleted message in chat {message.chat_id}: {message.id}")
|
|
81
146
|
|
|
82
147
|
|
|
83
148
|
# async def login_flow_test():
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import logging
|
|
3
|
+
|
|
4
|
+
import pymax
|
|
5
|
+
import pymax.static
|
|
6
|
+
from pymax import MaxClient
|
|
7
|
+
from pymax.filters import Filters
|
|
8
|
+
from pymax.payloads import UserAgentPayload
|
|
9
|
+
from pymax.static.enum import Opcode
|
|
10
|
+
|
|
11
|
+
phone = "+7903223423"
|
|
12
|
+
headers = UserAgentPayload(device_type="WEB")
|
|
13
|
+
|
|
14
|
+
client = MaxClient(
|
|
15
|
+
phone=phone,
|
|
16
|
+
work_dir="cache",
|
|
17
|
+
reconnect=False,
|
|
18
|
+
logger=None,
|
|
19
|
+
headers=headers,
|
|
20
|
+
)
|
|
21
|
+
client.logger.setLevel(logging.DEBUG)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@client.task(seconds=10)
|
|
25
|
+
async def periodic_task() -> None:
|
|
26
|
+
client.logger.info("Periodic task executed")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@client.on_message(Filters.text("test") & ~Filters.chat(0))
|
|
30
|
+
async def handle_message(message: pymax.Message) -> None:
|
|
31
|
+
print(f"New message from {message.sender}: {message.text}")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@client.on_start
|
|
35
|
+
async def on_start():
|
|
36
|
+
print("Client started")
|
|
37
|
+
data = await client._send_and_wait(
|
|
38
|
+
opcode=Opcode.FILE_UPLOAD,
|
|
39
|
+
payload={"count": 1},
|
|
40
|
+
)
|
|
41
|
+
print("File upload response:", data)
|
|
42
|
+
# opcode=pymax.static.enum.Opcode.CHATS_LIST,
|
|
43
|
+
# payload={
|
|
44
|
+
# "marker": 1765721869777,
|
|
45
|
+
# },
|
|
46
|
+
# )
|
|
47
|
+
|
|
48
|
+
# print("Chats list:", data)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
asyncio.run(client.start())
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import logging
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from pymax import MaxClient
|
|
6
|
+
from pymax.files import File, Video
|
|
7
|
+
|
|
8
|
+
client = MaxClient(phone="+1234567890", work_dir="cache", reconnect=False)
|
|
9
|
+
client.logger.setLevel(logging.INFO)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def create_big_file(file_path: Path, size_in_mb: int) -> None:
|
|
13
|
+
with open(file_path, "wb") as f:
|
|
14
|
+
f.seek(size_in_mb * 1024 * 1024 - 1)
|
|
15
|
+
f.write(b"\0")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@client.on_start
|
|
19
|
+
async def upload_large_file_example():
|
|
20
|
+
await asyncio.sleep(2)
|
|
21
|
+
|
|
22
|
+
file_path = Path("tests2/large_file.dat")
|
|
23
|
+
|
|
24
|
+
if not file_path.exists():
|
|
25
|
+
create_big_file(file_path, size_in_mb=300)
|
|
26
|
+
file_size = file_path.stat().st_size
|
|
27
|
+
client.logger.info(f"File size: {file_size / (1024 * 1024):.2f} MB")
|
|
28
|
+
|
|
29
|
+
file = File(path=str(file_path))
|
|
30
|
+
chat_id = 0
|
|
31
|
+
|
|
32
|
+
client.logger.info("Starting file upload...")
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
await client.send_message(
|
|
36
|
+
chat_id=chat_id,
|
|
37
|
+
text="📎 Вот большой файл",
|
|
38
|
+
attachment=file,
|
|
39
|
+
)
|
|
40
|
+
client.logger.info("File uploaded successfully!")
|
|
41
|
+
|
|
42
|
+
except OSError as e:
|
|
43
|
+
if "malloc failure" in str(e):
|
|
44
|
+
client.logger.error("Memory error - file too large for current memory")
|
|
45
|
+
client.logger.info("Recommendation: Upload smaller files or free up memory")
|
|
46
|
+
else:
|
|
47
|
+
raise
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
asyncio.run(client.start())
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
from pymax import MaxClient, Message
|
|
4
|
+
from pymax.filters import Filters
|
|
5
|
+
|
|
6
|
+
client = MaxClient(
|
|
7
|
+
phone="+1234567890",
|
|
8
|
+
work_dir="cache",
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@client.on_message(Filters.chat(0))
|
|
13
|
+
async def on_message(msg: Message):
|
|
14
|
+
print(f"[{msg.sender}] {msg.text}")
|
|
15
|
+
await client.send_message(chat_id=msg.chat_id, text="Привет!")
|
|
16
|
+
await client.add_reaction(
|
|
17
|
+
chat_id=msg.chat_id, message_id=str(msg.id), reaction="👍"
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@client.on_start
|
|
22
|
+
async def on_start():
|
|
23
|
+
print(f"Клиент запущен. Ваш ID: {client.me.id}")
|
|
24
|
+
history = await client.fetch_history(chat_id=0)
|
|
25
|
+
for m in history:
|
|
26
|
+
print(f"- {m.text}")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
async def main():
|
|
30
|
+
await client.start()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == "__main__":
|
|
34
|
+
asyncio.run(main())
|