This repository was archived by the owner on Feb 11, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathexample.py
More file actions
74 lines (55 loc) · 2.04 KB
/
example.py
File metadata and controls
74 lines (55 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import asyncio
import datetime
import logging
from time import time
from typing import Any
import pymax
from pymax import MaxClient, Message, ReactionInfo, SocketMaxClient, filters
from pymax.files import File, Photo, Video
from pymax.filters import Filters
from pymax.payloads import UserAgentPayload
from pymax.static.enum import AttachType, Opcode
from pymax.types import Chat
phone = "+79991234567"
headers = UserAgentPayload(device_type="WEB")
client = MaxClient(
phone=phone,
work_dir="cache",
reconnect=False,
logger=None,
headers=headers,
)
client.logger.setLevel(logging.INFO)
@client.on_start
async def handle_start() -> None:
print(f"Client started as {client.me.names[0].first_name}!")
@client.on_raw_receive
async def handle_raw_receive(data: dict[str, Any]) -> None:
print(f"Raw data received: {data}")
@client.on_reaction_change
async def handle_reaction_change(
message_id: str, chat_id: int, reaction_info: ReactionInfo
) -> None:
print(
f"Reaction changed on message {message_id} in chat {chat_id}: "
f"Total count: {reaction_info.total_count}, "
f"Your reaction: {reaction_info.your_reaction}, "
f"Counters: {reaction_info.counters[0].reaction}={reaction_info.counters[0].count}"
)
@client.on_chat_update
async def handle_chat_update(chat: Chat) -> None:
print(f"Chat updated: {chat.id}, new title: {chat.title}")
@client.on_message(Filters.chat(0) & Filters.text("hello"))
async def handle_message(message: Message) -> None:
print(f"New message in chat {message.chat_id} from {message.sender}: {message.text}")
@client.on_message_edit()
async def handle_edited_message(message: Message) -> None:
print(f"Edited message in chat {message.chat_id}: {message.text}")
@client.on_message_delete()
async def handle_deleted_message(message: Message) -> None:
print(f"Deleted message in chat {message.chat_id}: {message.id}")
if __name__ == "__main__":
try:
asyncio.run(client.start())
except KeyboardInterrupt:
print("Client stopped by user")