maxapi-python 0.1.3__py3-none-any.whl → 1.0.1__py3-none-any.whl

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.
pymax/navigation.py ADDED
@@ -0,0 +1,185 @@
1
+ import random
2
+
3
+
4
+ class Navigation:
5
+ SCREENS_GRAPH = { # noqa: RUF012
6
+ "chats_list_tab": [
7
+ "chat",
8
+ "contacts_tab",
9
+ "call_history_tab",
10
+ "settings_tab",
11
+ "create_chat",
12
+ "chat_attachments_voices",
13
+ ],
14
+ "chat": [
15
+ "chats_list_tab",
16
+ "chat_attachments_media",
17
+ ],
18
+ "contacts_tab": [
19
+ "call_history_tab",
20
+ "chats_list_tab",
21
+ "settings_tab",
22
+ "create_chat",
23
+ ],
24
+ "call_history_tab": [
25
+ "chats_list_tab",
26
+ "settings_tab",
27
+ "contacts_tab",
28
+ ],
29
+ "settings_tab": [
30
+ "settings_folders",
31
+ "settings_privacy",
32
+ "settings_notifications",
33
+ "settings_chat_decoration",
34
+ "call_history_tab",
35
+ "contacts_tab",
36
+ "chats_list_tab",
37
+ ],
38
+ "settings_folders": [
39
+ "settings_tab",
40
+ "chats_list_tab",
41
+ "contacts_tab",
42
+ "call_history_tab",
43
+ ],
44
+ "settings_privacy": [
45
+ "settings_tab",
46
+ "chats_list_tab",
47
+ "contacts_tab",
48
+ "call_history_tab",
49
+ ],
50
+ "settings_notifications": [
51
+ "settings_tab",
52
+ "contacts_tab",
53
+ "call_history_tab",
54
+ "chats_list_tab",
55
+ ],
56
+ "settings_chat_decoration": [
57
+ "settings_tab",
58
+ "chats_list_tab",
59
+ "contacts_tab",
60
+ "call_history_tab",
61
+ ],
62
+ "create_chat": [
63
+ "chats_list_tab",
64
+ "contacts_tab",
65
+ ],
66
+ "chat_attachments_media": [
67
+ "chat_attachments_files",
68
+ "chat_attachments_voices",
69
+ "chat_attachments_links",
70
+ "chat",
71
+ ],
72
+ "chat_attachments_files": [
73
+ "chat_attachments_voices",
74
+ "chat_attachments_media",
75
+ "chat_attachments_links",
76
+ "chat",
77
+ ],
78
+ "chat_attachments_voices": [
79
+ "chat_attachments_links",
80
+ "chat_attachments_media",
81
+ "chat_attachments_files",
82
+ "chat",
83
+ ],
84
+ "chat_attachments_links": [
85
+ "chat_attachments_media",
86
+ "chat_attachments_files",
87
+ "chat_attachments_voices",
88
+ "chat",
89
+ ],
90
+ }
91
+ SCREENS = { # noqa: RUF012
92
+ "application_background": 1,
93
+ "auth_sign_method": 50,
94
+ "auth_phone_login": 51,
95
+ "auth_otp": 52,
96
+ "auth_empty_profile": 53,
97
+ "auth_avatars": 54,
98
+ "contacts_tab": 100,
99
+ "contacts_search": 102,
100
+ "contacts_search_by_phone": 103,
101
+ "chats_list_tab": 150,
102
+ "chats_list_search_initial": 151,
103
+ "chats_list_search_result": 152,
104
+ "create_chat": 200,
105
+ "create_chat_members_picker": 201,
106
+ "create_chat_info": 202,
107
+ "avatar_picker_gallery": 250,
108
+ "avatar_picker_crop": 251,
109
+ "avatar_picker_camera": 252,
110
+ "avatar_viewer": 253,
111
+ "call_history_tab": 300,
112
+ "call_new_call": 302,
113
+ "call_create_group_link": 303,
114
+ "call_add_participants": 304,
115
+ "call": 305,
116
+ "chat": 350,
117
+ "chat_attach_picker": 351,
118
+ "chat_attach_picker_media_viewer": 352,
119
+ "chat_attach_picker_camera": 353,
120
+ "chat_share_location": 354,
121
+ "chat_share_contact": 355,
122
+ "chat_forward": 357,
123
+ "chat_media_viewer": 358,
124
+ "chat_system_file_viewer": 359,
125
+ "chat_location_viewer": 360,
126
+ "chat_info": 400,
127
+ "chat_info_all_participants": 401,
128
+ "chat_info_editing": 402,
129
+ "chat_info_add_participants": 403,
130
+ "chat_info_administrators": 404,
131
+ "chat_info_add_administrator": 405,
132
+ "chat_info_blocked_participants": 406,
133
+ "chat_info_change_owner": 407,
134
+ "chat_attachments_media": 408,
135
+ "chat_attachments_files": 409,
136
+ "chat_attachments_links": 410,
137
+ "chat_info_invite_link": 411,
138
+ "chat_attachments_voices": 412,
139
+ "settings_tab": 450,
140
+ "settings_profile_editing": 451,
141
+ "settings_shortname_change": 452,
142
+ "settings_phone_change": 453,
143
+ "settings_notifications": 454,
144
+ "settings_notifications_system": 455,
145
+ "settings_folders": 456,
146
+ "settings_privacy": 457,
147
+ "settings_privacy_block_list": 458,
148
+ "settings_media": 459,
149
+ "settings_messages": 460,
150
+ "settings_stickers": 461,
151
+ "settings_chat_decoration": 462,
152
+ "settings_phone_change_phone_input": 463,
153
+ "settings_phone_change_phone_otp": 464,
154
+ "settings_cache": 465,
155
+ "settings_profile_avatars": 466,
156
+ "settings_about_application": 467,
157
+ "settings_privacy_sensitive_content": 479,
158
+ "miniapp": 500,
159
+ }
160
+
161
+ @classmethod
162
+ def get_screen_id(cls, screen_name: str) -> int:
163
+ screen_id = cls.SCREENS.get(screen_name)
164
+
165
+ if screen_id is None:
166
+ raise ValueError(f"Unknown screen name: {screen_name}")
167
+
168
+ return screen_id
169
+
170
+ @classmethod
171
+ def can_navigate(cls, from_screen: str, to_screen: str) -> bool:
172
+ if from_screen == to_screen:
173
+ return True
174
+ return to_screen in cls.SCREENS_GRAPH.get(from_screen, [])
175
+
176
+ @classmethod
177
+ def get_random_navigation(cls, screen_name: str) -> str:
178
+ return random.choice(cls.SCREENS_GRAPH.get(screen_name, [])) # noqa: S311
179
+
180
+ @classmethod
181
+ def get_screen_name(cls, screen_id: int) -> str | None:
182
+ for name, id_ in cls.SCREENS.items():
183
+ if id_ == screen_id:
184
+ return name
185
+ return None
pymax/payloads.py CHANGED
@@ -1,175 +1,195 @@
1
- from typing import Any, Literal
2
-
3
- from pydantic import BaseModel, Field
4
-
5
- from pymax.static import AttachType, AuthType
6
-
7
-
8
- def to_camel(string: str) -> str:
9
- parts = string.split("_")
10
- return parts[0] + "".join(word.capitalize() for word in parts[1:])
11
-
12
-
13
- class CamelModel(BaseModel):
14
- model_config = {
15
- "alias_generator": to_camel,
16
- "populate_by_name": True,
17
- }
18
-
19
-
20
- class BaseWebSocketMessage(BaseModel):
21
- ver: int = 11
22
- cmd: int
23
- seq: int
24
- opcode: int
25
- payload: dict[str, Any]
26
-
27
-
28
- class RequestCodePayload(CamelModel):
29
- phone: str
30
- type: AuthType = AuthType.START_AUTH
31
- language: str = "ru"
32
-
33
-
34
- class SendCodePayload(CamelModel):
35
- token: str
36
- verify_code: str
37
- auth_token_type: AuthType = AuthType.CHECK_CODE
38
-
39
-
40
- class SyncPayload(CamelModel):
41
- interactive: bool = True
42
- token: str
43
- chats_sync: int = 0
44
- contacts_sync: int = 0
45
- presence_sync: int = 0
46
- drafts_sync: int = 0
47
- chats_count: int = 40
48
-
49
-
50
- class ReplyLink(CamelModel):
51
- type: str = "REPLY"
52
- message_id: str
53
-
54
-
55
- class UploadPhotoPayload(CamelModel):
56
- count: int = 1
57
-
58
-
59
- class AttachPhotoPayload(CamelModel):
60
- type: AttachType = Field(AttachType.PHOTO, alias="_type")
61
- photo_token: str
62
-
63
-
64
- class SendMessagePayloadMessage(CamelModel):
65
- text: str
66
- cid: int
67
- elements: list[Any]
68
- attaches: list[dict[str, Any]]
69
- link: ReplyLink | None = None
70
-
71
-
72
- class SendMessagePayload(CamelModel):
73
- chat_id: int
74
- message: SendMessagePayloadMessage
75
- notify: bool = False
76
-
77
-
78
- class EditMessagePayload(CamelModel):
79
- chat_id: int
80
- message_id: int
81
- text: str
82
- elements: list[Any]
83
- attaches: list[Any]
84
-
85
-
86
- class DeleteMessagePayload(CamelModel):
87
- chat_id: int
88
- message_ids: list[int]
89
- for_me: bool = False
90
-
91
-
92
- class FetchContactsPayload(CamelModel):
93
- contact_ids: list[int]
94
-
95
-
96
- class FetchHistoryPayload(CamelModel):
97
- chat_id: int
98
- from_time: int = Field(alias="from")
99
- forward: int
100
- backward: int = 200
101
- get_messages: bool = True
102
-
103
-
104
- class ChangeProfilePayload(CamelModel):
105
- first_name: str
106
- last_name: str | None = None
107
- description: str | None = None
108
-
109
-
110
- class ResolveLinkPayload(CamelModel):
111
- link: str
112
-
113
-
114
- class PinMessagePayload(CamelModel):
115
- chat_id: int
116
- notify_pin: bool
117
- pin_message_id: int
118
-
119
-
120
- class CreateGroupAttach(CamelModel):
121
- type: Literal["CONTROL"] = Field("CONTROL", alias="_type")
122
- event: str = "new"
123
- chat_type: str = "CHAT"
124
- title: str
125
- user_ids: list[int]
126
-
127
-
128
- class CreateGroupMessage(CamelModel):
129
- cid: int
130
- attaches: list[CreateGroupAttach]
131
-
132
-
133
- class CreateGroupPayload(CamelModel):
134
- message: CreateGroupMessage
135
- notify: bool = True
136
-
137
-
138
- class InviteUsersPayload(CamelModel):
139
- chat_id: int
140
- user_ids: list[int]
141
- show_history: bool
142
- operation: str = "add"
143
-
144
-
145
- class RemoveUsersPayload(CamelModel):
146
- chat_id: int
147
- user_ids: list[int]
148
- operation: str = "remove"
149
- clean_msg_period: int
150
-
151
-
152
- class ChangeGroupSettingsOptions(BaseModel):
153
- ONLY_OWNER_CAN_CHANGE_ICON_TITLE: bool | None
154
- ALL_CAN_PIN_MESSAGE: bool | None
155
- ONLY_ADMIN_CAN_ADD_MEMBER: bool | None
156
- ONLY_ADMIN_CAN_CALL: bool | None
157
- MEMBERS_CAN_SEE_PRIVATE_LINK: bool | None
158
-
159
-
160
- class ChangeGroupSettingsPayload(CamelModel):
161
- chat_id: int
162
- options: ChangeGroupSettingsOptions
163
-
164
-
165
- class ChangeGroupProfilePayload(CamelModel):
166
- chat_id: int
167
- theme: str | None
168
- description: str | None
169
-
170
-
171
- class GetGroupMembersPayload(CamelModel):
172
- type: str = "MEMBER"
173
- marker: int
174
- chat_id: int
175
- count: int
1
+ from typing import Any, Literal
2
+
3
+ from pydantic import BaseModel, Field
4
+
5
+ from pymax.static import AttachType, AuthType
6
+
7
+
8
+ def to_camel(string: str) -> str:
9
+ parts = string.split("_")
10
+ return parts[0] + "".join(word.capitalize() for word in parts[1:])
11
+
12
+
13
+ class CamelModel(BaseModel):
14
+ model_config = {
15
+ "alias_generator": to_camel,
16
+ "populate_by_name": True,
17
+ }
18
+
19
+
20
+ class BaseWebSocketMessage(BaseModel):
21
+ ver: int = 11
22
+ cmd: int
23
+ seq: int
24
+ opcode: int
25
+ payload: dict[str, Any]
26
+
27
+
28
+ class RequestCodePayload(CamelModel):
29
+ phone: str
30
+ type: AuthType = AuthType.START_AUTH
31
+ language: str = "ru"
32
+
33
+
34
+ class SendCodePayload(CamelModel):
35
+ token: str
36
+ verify_code: str
37
+ auth_token_type: AuthType = AuthType.CHECK_CODE
38
+
39
+
40
+ class SyncPayload(CamelModel):
41
+ interactive: bool = True
42
+ token: str
43
+ chats_sync: int = 0
44
+ contacts_sync: int = 0
45
+ presence_sync: int = 0
46
+ drafts_sync: int = 0
47
+ chats_count: int = 40
48
+
49
+
50
+ class ReplyLink(CamelModel):
51
+ type: str = "REPLY"
52
+ message_id: str
53
+
54
+
55
+ class UploadPhotoPayload(CamelModel):
56
+ count: int = 1
57
+
58
+
59
+ class AttachPhotoPayload(CamelModel):
60
+ type: AttachType = Field(AttachType.PHOTO, alias="_type")
61
+ photo_token: str
62
+
63
+
64
+ class SendMessagePayloadMessage(CamelModel):
65
+ text: str
66
+ cid: int
67
+ elements: list[Any]
68
+ attaches: list[dict[str, Any]]
69
+ link: ReplyLink | None = None
70
+
71
+
72
+ class SendMessagePayload(CamelModel):
73
+ chat_id: int
74
+ message: SendMessagePayloadMessage
75
+ notify: bool = False
76
+
77
+
78
+ class EditMessagePayload(CamelModel):
79
+ chat_id: int
80
+ message_id: int
81
+ text: str
82
+ elements: list[Any]
83
+ attaches: list[Any]
84
+
85
+
86
+ class DeleteMessagePayload(CamelModel):
87
+ chat_id: int
88
+ message_ids: list[int]
89
+ for_me: bool = False
90
+
91
+
92
+ class FetchContactsPayload(CamelModel):
93
+ contact_ids: list[int]
94
+
95
+
96
+ class FetchHistoryPayload(CamelModel):
97
+ chat_id: int
98
+ from_time: int = Field(alias="from")
99
+ forward: int
100
+ backward: int = 200
101
+ get_messages: bool = True
102
+
103
+
104
+ class ChangeProfilePayload(CamelModel):
105
+ first_name: str
106
+ last_name: str | None = None
107
+ description: str | None = None
108
+
109
+
110
+ class ResolveLinkPayload(CamelModel):
111
+ link: str
112
+
113
+
114
+ class PinMessagePayload(CamelModel):
115
+ chat_id: int
116
+ notify_pin: bool
117
+ pin_message_id: int
118
+
119
+
120
+ class CreateGroupAttach(CamelModel):
121
+ type: Literal["CONTROL"] = Field("CONTROL", alias="_type")
122
+ event: str = "new"
123
+ chat_type: str = "CHAT"
124
+ title: str
125
+ user_ids: list[int]
126
+
127
+
128
+ class CreateGroupMessage(CamelModel):
129
+ cid: int
130
+ attaches: list[CreateGroupAttach]
131
+
132
+
133
+ class CreateGroupPayload(CamelModel):
134
+ message: CreateGroupMessage
135
+ notify: bool = True
136
+
137
+
138
+ class InviteUsersPayload(CamelModel):
139
+ chat_id: int
140
+ user_ids: list[int]
141
+ show_history: bool
142
+ operation: str = "add"
143
+
144
+
145
+ class RemoveUsersPayload(CamelModel):
146
+ chat_id: int
147
+ user_ids: list[int]
148
+ operation: str = "remove"
149
+ clean_msg_period: int
150
+
151
+
152
+ class ChangeGroupSettingsOptions(BaseModel):
153
+ ONLY_OWNER_CAN_CHANGE_ICON_TITLE: bool | None
154
+ ALL_CAN_PIN_MESSAGE: bool | None
155
+ ONLY_ADMIN_CAN_ADD_MEMBER: bool | None
156
+ ONLY_ADMIN_CAN_CALL: bool | None
157
+ MEMBERS_CAN_SEE_PRIVATE_LINK: bool | None
158
+
159
+
160
+ class ChangeGroupSettingsPayload(CamelModel):
161
+ chat_id: int
162
+ options: ChangeGroupSettingsOptions
163
+
164
+
165
+ class ChangeGroupProfilePayload(CamelModel):
166
+ chat_id: int
167
+ theme: str | None
168
+ description: str | None
169
+
170
+
171
+ class GetGroupMembersPayload(CamelModel):
172
+ type: str = "MEMBER"
173
+ marker: int
174
+ chat_id: int
175
+ count: int
176
+
177
+
178
+ class NavigationEventParams(BaseModel):
179
+ action_id: int
180
+ screen_to: int
181
+ screen_from: int | None = None
182
+ source_id: int
183
+ session_id: int
184
+
185
+
186
+ class NavigationEventPayload(CamelModel):
187
+ event: str
188
+ time: int
189
+ type: str = "NAV"
190
+ user_id: int
191
+ params: NavigationEventParams
192
+
193
+
194
+ class NavigationPayload(CamelModel):
195
+ events: list[NavigationEventPayload]