maxapi-python 0.1.3__py3-none-any.whl → 1.1.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/types.py CHANGED
@@ -1,434 +1,570 @@
1
- from typing import Any
2
-
3
- from typing_extensions import override
4
-
5
- from .static import (
6
- AccessType,
7
- AttachType,
8
- ChatType,
9
- ElementType,
10
- MessageStatus,
11
- MessageType,
12
- )
13
-
14
-
15
- class Names:
16
- def __init__(
17
- self, name: str, first_name: str, last_name: str | None, type: str
18
- ) -> None:
19
- self.name = name
20
- self.first_name = first_name
21
- self.last_name = last_name
22
- self.type = type
23
-
24
- @classmethod
25
- def from_dict(cls, data: dict[str, Any]) -> "Names":
26
- return cls(
27
- name=data["name"],
28
- first_name=data["firstName"],
29
- last_name=data.get("lastName"),
30
- type=data["type"],
31
- )
32
-
33
- @override
34
- def __repr__(self) -> str:
35
- return f"Names(name={self.name!r}, first_name={self.first_name!r}, last_name={self.last_name!r}, type={self.type!r})"
36
-
37
- @override
38
- def __str__(self) -> str:
39
- return self.name
40
-
41
-
42
- class Me:
43
- def __init__(
44
- self,
45
- id: int,
46
- account_status: int,
47
- phone: str,
48
- names: list[Names],
49
- update_time: int,
50
- options: list[str] | None = None,
51
- ) -> None:
52
- self.id = id
53
- self.account_status = account_status
54
- self.phone = phone
55
- self.update_time = update_time
56
- self.options = options
57
- self.names = names
58
-
59
- @classmethod
60
- def from_dict(cls, data: dict[str, Any]) -> "Me":
61
- return cls(
62
- id=data["id"],
63
- account_status=data["accountStatus"],
64
- phone=data["phone"],
65
- names=[Names.from_dict(n) for n in data["names"]],
66
- update_time=data["updateTime"],
67
- options=data.get("options"),
68
- )
69
-
70
- @override
71
- def __repr__(self) -> str:
72
- return f"Me(id={self.id!r}, account_status={self.account_status!r}, phone={self.phone!r}, names={self.names!r}, update_time={self.update_time!r}, options={self.options!r})"
73
-
74
- @override
75
- def __str__(self) -> str:
76
- return f"Me {self.id}: {', '.join(str(n) for n in self.names)}"
77
-
78
-
79
- class Element:
80
- def __init__(
81
- self, type: ElementType | str, length: int, from_: int | None = None
82
- ) -> None:
83
- self.type = type
84
- self.length = length
85
- self.from_ = from_
86
-
87
- @classmethod
88
- def from_dict(cls, data: dict[Any, Any]) -> "Element":
89
- return cls(type=data["type"], length=data["length"], from_=data.get("from"))
90
-
91
- @override
92
- def __repr__(self) -> str:
93
- return (
94
- f"Element(type={self.type!r}, length={self.length!r}, from_={self.from_!r})"
95
- )
96
-
97
- @override
98
- def __str__(self) -> str:
99
- return f"{self.type}({self.length})"
100
-
101
-
102
- class Message:
103
- def __init__(
104
- self,
105
- sender: int | None,
106
- elements: list[Element] | None,
107
- reaction_info: dict[str, Any] | None,
108
- options: int | None,
109
- id: int,
110
- time: int,
111
- text: str,
112
- status: MessageStatus | str | None,
113
- type: MessageType | str,
114
- attaches: list[Any],
115
- ) -> None:
116
- self.sender = sender
117
- self.elements = elements
118
- self.options = options
119
- self.id = id
120
- self.time = time
121
- self.text = text
122
- self.type = type
123
- self.attaches = attaches
124
- self.status = status
125
- self.reactionInfo = reaction_info
126
-
127
- @classmethod
128
- def from_dict(cls, data: dict[Any, Any]) -> "Message":
129
- return cls(
130
- sender=data.get("sender"),
131
- elements=[Element.from_dict(e) for e in data.get("elements", [])],
132
- options=data.get("options"),
133
- id=data["id"],
134
- time=data["time"],
135
- text=data["text"],
136
- type=data["type"],
137
- attaches=data.get("attaches", []),
138
- status=data.get("status"),
139
- reaction_info=data.get("reactionInfo"),
140
- )
141
-
142
- @override
143
- def __repr__(self) -> str:
144
- return (
145
- f"Message(id={self.id!r}, sender={self.sender!r}, text={self.text!r}, "
146
- f"type={self.type!r}, status={self.status!r}, elements={self.elements!r})"
147
- )
148
-
149
- @override
150
- def __str__(self) -> str:
151
- return f"Message {self.id} from {self.sender}: {self.text}"
152
-
153
-
154
- class Dialog:
155
- def __init__(
156
- self,
157
- cid: int | None,
158
- owner: int,
159
- has_bots: bool | None,
160
- join_time: int,
161
- created: int,
162
- last_message: Message | None,
163
- type: ChatType | str,
164
- last_fire_delayed_error_time: int,
165
- last_delayed_update_time: int,
166
- prev_message_id: str | None,
167
- options: dict[str, bool],
168
- modified: int,
169
- last_event_time: int,
170
- id: int,
171
- status: str,
172
- participants: dict[str, int],
173
- ) -> None:
174
- self.cid = cid
175
- self.owner = owner
176
- self.has_bots = has_bots
177
- self.join_time = join_time
178
- self.created = created
179
- self.last_message = last_message
180
- self.type = type
181
- self.last_fire_delayed_error_time = last_fire_delayed_error_time
182
- self.last_delayed_update_time = last_delayed_update_time
183
- self.prev_message_id = prev_message_id
184
- self.options = options
185
- self.modified = modified
186
- self.last_event_time = last_event_time
187
- self.id = id
188
- self.status = status
189
- self.participants = participants
190
-
191
- @classmethod
192
- def from_dict(cls, data: dict[Any, Any]) -> "Dialog":
193
- return cls(
194
- cid=data.get("cid"),
195
- owner=data["owner"],
196
- has_bots=data.get("hasBots"),
197
- join_time=data["joinTime"],
198
- created=data["created"],
199
- last_message=Message.from_dict(data["lastMessage"])
200
- if data.get("lastMessage")
201
- else None,
202
- type=ChatType(data["type"]),
203
- last_fire_delayed_error_time=data["lastFireDelayedErrorTime"],
204
- last_delayed_update_time=data["lastDelayedUpdateTime"],
205
- prev_message_id=data.get("prevMessageId"),
206
- options=data.get("options", {}),
207
- modified=data["modified"],
208
- last_event_time=data["lastEventTime"],
209
- id=data["id"],
210
- status=data["status"],
211
- participants=data["participants"],
212
- )
213
-
214
- @override
215
- def __repr__(self) -> str:
216
- return f"Dialog(id={self.id!r}, owner={self.owner!r}, type={self.type!r}, last_message={self.last_message!r})"
217
-
218
- @override
219
- def __str__(self) -> str:
220
- return f"Dialog {self.id} ({self.type})"
221
-
222
-
223
- class Chat:
224
- def __init__(
225
- self,
226
- participants_count: int,
227
- access: AccessType | str,
228
- invited_by: int | None,
229
- link: str | None,
230
- chat_type: ChatType | str,
231
- title: str | None,
232
- last_fire_delayed_error_time: int,
233
- last_delayed_update_time: int,
234
- options: dict[str, bool],
235
- base_raw_icon_url: str | None,
236
- base_icon_url: str | None,
237
- description: str | None,
238
- modified: int,
239
- id_: int,
240
- admin_participants: dict[int, dict[Any, Any]],
241
- participants: dict[int, int],
242
- owner: int,
243
- join_time: int,
244
- created: int,
245
- last_message: Message | None,
246
- prev_message_id: str | None,
247
- last_event_time: int,
248
- messages_count: int,
249
- admins: list[int],
250
- restrictions: int | None,
251
- status: str,
252
- cid: int,
253
- ) -> None:
254
- self.participants_count = participants_count
255
- self.access = access
256
- self.invited_by = invited_by
257
- self.link = link
258
- self.type = chat_type
259
- self.title = title
260
- self.last_fire_delayed_error_time = last_fire_delayed_error_time
261
- self.last_delayed_update_time = last_delayed_update_time
262
- self.options = options
263
- self.base_raw_icon_url = base_raw_icon_url
264
- self.base_icon_url = base_icon_url
265
- self.description = description
266
- self.modified = modified
267
- self.id = id_
268
- self.admin_participants = admin_participants
269
- self.participants = participants
270
- self.owner = owner
271
- self.join_time = join_time
272
- self.created = created
273
- self.last_message = last_message
274
- self.prev_message_id = prev_message_id
275
- self.last_event_time = last_event_time
276
- self.messages_count = messages_count
277
- self.admins = admins
278
- self.restrictions = restrictions
279
- self.status = status
280
- self.cid = cid
281
-
282
- @classmethod
283
- def from_dict(cls, data: dict[Any, Any]) -> "Chat":
284
- raw_admins = data.get("adminParticipants", {}) or {}
285
- admin_participants: dict[int, dict[Any, Any]] = {
286
- int(k): v for k, v in raw_admins.items()
287
- }
288
- raw_participants = data.get("participants", {}) or {}
289
- participants: dict[int, int] = {int(k): v for k, v in raw_participants.items()}
290
- last_msg = (
291
- Message.from_dict(data["lastMessage"]) if data.get("lastMessage") else None
292
- )
293
- return cls(
294
- participants_count=data.get("participantsCount", 0),
295
- access=AccessType(data.get("access", AccessType.PUBLIC.value)),
296
- invited_by=data.get("invitedBy"),
297
- link=data.get("link"),
298
- base_raw_icon_url=data.get("baseRawIconUrl"),
299
- base_icon_url=data.get("baseIconUrl"),
300
- description=data.get("description"),
301
- chat_type=ChatType(data.get("type", ChatType.CHAT.value)),
302
- title=data.get("title"),
303
- last_fire_delayed_error_time=data.get("lastFireDelayedErrorTime", 0),
304
- last_delayed_update_time=data.get("lastDelayedUpdateTime", 0),
305
- options=data.get("options", {}),
306
- modified=data.get("modified", 0),
307
- id_=data.get("id", 0),
308
- admin_participants=admin_participants,
309
- participants=participants,
310
- owner=data.get("owner", 0),
311
- join_time=data.get("joinTime", 0),
312
- created=data.get("created", 0),
313
- last_message=last_msg,
314
- prev_message_id=data.get("prevMessageId"),
315
- last_event_time=data.get("lastEventTime", 0),
316
- messages_count=data.get("messagesCount", 0),
317
- admins=data.get("admins", []),
318
- restrictions=data.get("restrictions"),
319
- status=data.get("status", ""),
320
- cid=data.get("cid", 0),
321
- )
322
-
323
- @override
324
- def __repr__(self) -> str:
325
- return f"Chat(id={self.id!r}, title={self.title!r}, type={self.type!r})"
326
-
327
- @override
328
- def __str__(self) -> str:
329
- return f"{self.title} ({self.type})"
330
-
331
-
332
- class Channel(Chat):
333
- @override
334
- def __repr__(self) -> str:
335
- return f"Channel(id={self.id!r}, title={self.title!r})"
336
-
337
- @override
338
- def __str__(self) -> str:
339
- return f"Channel: {self.title}"
340
-
341
-
342
- class User:
343
- def __init__(
344
- self,
345
- account_status: int,
346
- update_time: int,
347
- id: int,
348
- names: list[Names],
349
- options: list[str] | None = None,
350
- base_url: str | None = None,
351
- base_raw_url: str | None = None,
352
- photo_id: int | None = None,
353
- description: str | None = None,
354
- gender: int | None = None,
355
- link: str | None = None,
356
- web_app: str | None = None,
357
- menu_button: dict[str, Any] | None = None,
358
- ) -> None:
359
- self.account_status = account_status
360
- self.update_time = update_time
361
- self.id = id
362
- self.names = names
363
- self.options = options or []
364
- self.base_url = base_url
365
- self.base_raw_url = base_raw_url
366
- self.photo_id = photo_id
367
- self.description = description
368
- self.gender = gender
369
- self.link = link
370
- self.web_app = web_app
371
- self.menu_button = menu_button
372
-
373
- @classmethod
374
- def from_dict(cls, data: dict[str, Any]) -> "User":
375
- return cls(
376
- account_status=data["accountStatus"],
377
- update_time=data["updateTime"],
378
- id=data["id"],
379
- names=[Names.from_dict(n) for n in data.get("names", [])],
380
- options=data.get("options"),
381
- base_url=data.get("baseUrl"),
382
- base_raw_url=data.get("baseRawUrl"),
383
- photo_id=data.get("photoId"),
384
- description=data.get("description"),
385
- gender=data.get("gender"),
386
- link=data.get("link"),
387
- web_app=data.get("webApp"),
388
- menu_button=data.get("menuButton"),
389
- )
390
-
391
- @override
392
- def __repr__(self) -> str:
393
- return f"User(id={self.id!r}, names={self.names!r}, status={self.account_status!r})"
394
-
395
- @override
396
- def __str__(self) -> str:
397
- return f"User {self.id}: {', '.join(str(n) for n in self.names)}"
398
-
399
-
400
- class Attach:
401
- def __init__(
402
- self,
403
- _type: AttachType,
404
- video_id: int | None = None,
405
- photo_token: str | None = None,
406
- file_id: int | None = None,
407
- token: str | None = None,
408
- ) -> None:
409
- self.type = _type
410
- self.video_id = video_id
411
- self.photo_token = photo_token
412
- self.file_id = file_id
413
- self.token = token
414
-
415
- @classmethod
416
- def from_dict(cls, data: dict[str, Any]) -> "Attach":
417
- return cls(
418
- _type=AttachType(data["type"]),
419
- video_id=data.get("videoId"),
420
- photo_token=data.get("photoToken"),
421
- file_id=data.get("fileId"),
422
- token=data.get("token"),
423
- )
424
-
425
- @override
426
- def __repr__(self) -> str:
427
- return (
428
- f"Attach(type={self.type!r}, video_id={self.video_id!r}, "
429
- f"photo_token={self.photo_token!r}, file_id={self.file_id!r}, token={self.token!r})"
430
- )
431
-
432
- @override
433
- def __str__(self) -> str:
434
- return f"Attach: {self.type}"
1
+ from typing import Any
2
+
3
+ from typing_extensions import override
4
+
5
+ from .static import (
6
+ AccessType,
7
+ AttachType,
8
+ ChatType,
9
+ ElementType,
10
+ MessageStatus,
11
+ MessageType,
12
+ )
13
+
14
+
15
+ class Names:
16
+ def __init__(
17
+ self, name: str, first_name: str, last_name: str | None, type: str
18
+ ) -> None:
19
+ self.name = name
20
+ self.first_name = first_name
21
+ self.last_name = last_name
22
+ self.type = type
23
+
24
+ @classmethod
25
+ def from_dict(cls, data: dict[str, Any]) -> "Names":
26
+ return cls(
27
+ name=data["name"],
28
+ first_name=data["firstName"],
29
+ last_name=data.get("lastName"),
30
+ type=data["type"],
31
+ )
32
+
33
+ @override
34
+ def __repr__(self) -> str:
35
+ return f"Names(name={self.name!r}, first_name={self.first_name!r}, last_name={self.last_name!r}, type={self.type!r})"
36
+
37
+ @override
38
+ def __str__(self) -> str:
39
+ return self.name
40
+
41
+
42
+ class PhotoAttach:
43
+ def __init__(
44
+ self,
45
+ base_url: str,
46
+ height: int,
47
+ width: int,
48
+ photo_id: int,
49
+ photo_token: str,
50
+ preview_data: str,
51
+ type: AttachType,
52
+ ) -> None:
53
+ self.base_url = base_url
54
+ self.height = height
55
+ self.width = width
56
+ self.photo_id = photo_id
57
+ self.photo_token = photo_token
58
+ self.preview_data = preview_data
59
+ self.type = type
60
+
61
+ @classmethod
62
+ def from_dict(cls, data: dict[str, Any]) -> "PhotoAttach":
63
+ return cls(
64
+ base_url=data["baseUrl"],
65
+ height=data["height"],
66
+ width=data["width"],
67
+ photo_id=data["photoId"],
68
+ photo_token=data["photoToken"],
69
+ preview_data=data["previewData"],
70
+ type=AttachType(data["_type"]),
71
+ )
72
+
73
+ @override
74
+ def __repr__(self) -> str:
75
+ return (
76
+ f"PhotoAttach(photo_id={self.photo_id!r}, base_url={self.base_url!r}, "
77
+ f"height={self.height!r}, width={self.width!r}, photo_token={self.photo_token!r}, "
78
+ f"preview_data={self.preview_data!r}, type={self.type!r})"
79
+ )
80
+
81
+ @override
82
+ def __str__(self) -> str:
83
+ return f"PhotoAttach: {self.photo_id}"
84
+
85
+
86
+ class VideoAttach:
87
+ def __init__(
88
+ self,
89
+ height: int,
90
+ width: int,
91
+ video_id: int,
92
+ duration: int,
93
+ preview_data: str,
94
+ type: AttachType,
95
+ thumbnail: str,
96
+ token: str,
97
+ video_type: int,
98
+ ) -> None:
99
+ self.height = height
100
+ self.width = width
101
+ self.video_id = video_id
102
+ self.duration = duration
103
+ self.preview_data = preview_data
104
+ self.type = type
105
+ self.thumbnail = thumbnail
106
+ self.token = token
107
+ self.video_type = video_type
108
+
109
+ @classmethod
110
+ def from_dict(cls, data: dict[str, Any]) -> "VideoAttach":
111
+ return cls(
112
+ height=data["height"],
113
+ width=data["width"],
114
+ video_id=data["videoId"],
115
+ duration=data["duration"],
116
+ preview_data=data["previewData"],
117
+ type=AttachType(data["_type"]),
118
+ thumbnail=data["thumbnail"],
119
+ token=data["token"],
120
+ video_type=data["videoType"],
121
+ )
122
+
123
+ @override
124
+ def __repr__(self) -> str:
125
+ return (
126
+ f"VideoAttach(video_id={self.video_id!r}, height={self.height!r}, "
127
+ f"width={self.width!r}, duration={self.duration!r}, "
128
+ f"preview_data={self.preview_data!r}, type={self.type!r}, "
129
+ f"thumbnail={self.thumbnail!r}, token={self.token!r}, "
130
+ f"video_type={self.video_type!r})"
131
+ )
132
+
133
+ @override
134
+ def __str__(self) -> str:
135
+ return f"VideoAttach: {self.video_id}"
136
+
137
+
138
+ class FileAttach:
139
+ def __init__(
140
+ self, file_id: int, name: str, size: int, token: str, type: AttachType
141
+ ) -> None:
142
+ self.file_id = file_id
143
+ self.name = name
144
+ self.size = size
145
+ self.token = token
146
+ self.type = type
147
+
148
+ @classmethod
149
+ def from_dict(cls, data: dict[str, Any]) -> "FileAttach":
150
+ return cls(
151
+ file_id=data["fileId"],
152
+ name=data["name"],
153
+ size=data["size"],
154
+ token=data["token"],
155
+ type=AttachType(data["_type"]),
156
+ )
157
+
158
+ @override
159
+ def __repr__(self) -> str:
160
+ return (
161
+ f"FileAttach(file_id={self.file_id!r}, name={self.name!r}, "
162
+ f"size={self.size!r}, token={self.token!r}, type={self.type!r})"
163
+ )
164
+
165
+ @override
166
+ def __str__(self) -> str:
167
+ return f"FileAttach: {self.file_id}"
168
+
169
+
170
+ class Me:
171
+ def __init__(
172
+ self,
173
+ id: int,
174
+ account_status: int,
175
+ phone: str,
176
+ names: list[Names],
177
+ update_time: int,
178
+ options: list[str] | None = None,
179
+ ) -> None:
180
+ self.id = id
181
+ self.account_status = account_status
182
+ self.phone = phone
183
+ self.update_time = update_time
184
+ self.options = options
185
+ self.names = names
186
+
187
+ @classmethod
188
+ def from_dict(cls, data: dict[str, Any]) -> "Me":
189
+ return cls(
190
+ id=data["id"],
191
+ account_status=data["accountStatus"],
192
+ phone=data["phone"],
193
+ names=[Names.from_dict(n) for n in data["names"]],
194
+ update_time=data["updateTime"],
195
+ options=data.get("options"),
196
+ )
197
+
198
+ @override
199
+ def __repr__(self) -> str:
200
+ return f"Me(id={self.id!r}, account_status={self.account_status!r}, phone={self.phone!r}, names={self.names!r}, update_time={self.update_time!r}, options={self.options!r})"
201
+
202
+ @override
203
+ def __str__(self) -> str:
204
+ return f"Me {self.id}: {', '.join(str(n) for n in self.names)}"
205
+
206
+
207
+ class Element:
208
+ def __init__(
209
+ self, type: ElementType | str, length: int, from_: int | None = None
210
+ ) -> None:
211
+ self.type = type
212
+ self.length = length
213
+ self.from_ = from_
214
+
215
+ @classmethod
216
+ def from_dict(cls, data: dict[Any, Any]) -> "Element":
217
+ return cls(type=data["type"], length=data["length"], from_=data.get("from"))
218
+
219
+ @override
220
+ def __repr__(self) -> str:
221
+ return (
222
+ f"Element(type={self.type!r}, length={self.length!r}, from_={self.from_!r})"
223
+ )
224
+
225
+ @override
226
+ def __str__(self) -> str:
227
+ return f"{self.type}({self.length})"
228
+
229
+
230
+ class Message:
231
+ def __init__(
232
+ self,
233
+ sender: int | None,
234
+ elements: list[Element] | None,
235
+ reaction_info: dict[str, Any] | None,
236
+ options: int | None,
237
+ id: int,
238
+ time: int,
239
+ text: str,
240
+ status: MessageStatus | str | None,
241
+ type: MessageType | str,
242
+ attaches: list[PhotoAttach | VideoAttach | FileAttach],
243
+ ) -> None:
244
+ self.sender = sender
245
+ self.elements = elements
246
+ self.options = options
247
+ self.id = id
248
+ self.time = time
249
+ self.text = text
250
+ self.type = type
251
+ self.attaches = attaches
252
+ self.status = status
253
+ self.reactionInfo = reaction_info
254
+
255
+ @classmethod
256
+ def from_dict(cls, data: dict[Any, Any]) -> "Message":
257
+ attaches = []
258
+ for a in data.get("attaches", []):
259
+ if a["_type"] == AttachType.PHOTO:
260
+ attaches.append(PhotoAttach.from_dict(a))
261
+ elif a["_type"] == AttachType.VIDEO:
262
+ attaches.append(VideoAttach.from_dict(a))
263
+ elif a["_type"] == AttachType.FILE:
264
+ attaches.append(FileAttach.from_dict(a))
265
+ return cls(
266
+ sender=data.get("sender"),
267
+ elements=[Element.from_dict(e) for e in data.get("elements", [])],
268
+ options=data.get("options"),
269
+ id=data["id"],
270
+ time=data["time"],
271
+ text=data["text"],
272
+ type=data["type"],
273
+ attaches=attaches,
274
+ status=data.get("status"),
275
+ reaction_info=data.get("reactionInfo"),
276
+ )
277
+
278
+ @override
279
+ def __repr__(self) -> str:
280
+ return (
281
+ f"Message(id={self.id!r}, sender={self.sender!r}, text={self.text!r}, "
282
+ f"type={self.type!r}, status={self.status!r}, elements={self.elements!r})"
283
+ )
284
+
285
+ @override
286
+ def __str__(self) -> str:
287
+ return f"Message {self.id} from {self.sender}: {self.text}"
288
+
289
+
290
+ class Dialog:
291
+ def __init__(
292
+ self,
293
+ cid: int | None,
294
+ owner: int,
295
+ has_bots: bool | None,
296
+ join_time: int,
297
+ created: int,
298
+ last_message: Message | None,
299
+ type: ChatType | str,
300
+ last_fire_delayed_error_time: int,
301
+ last_delayed_update_time: int,
302
+ prev_message_id: str | None,
303
+ options: dict[str, bool],
304
+ modified: int,
305
+ last_event_time: int,
306
+ id: int,
307
+ status: str,
308
+ participants: dict[str, int],
309
+ ) -> None:
310
+ self.cid = cid
311
+ self.owner = owner
312
+ self.has_bots = has_bots
313
+ self.join_time = join_time
314
+ self.created = created
315
+ self.last_message = last_message
316
+ self.type = type
317
+ self.last_fire_delayed_error_time = last_fire_delayed_error_time
318
+ self.last_delayed_update_time = last_delayed_update_time
319
+ self.prev_message_id = prev_message_id
320
+ self.options = options
321
+ self.modified = modified
322
+ self.last_event_time = last_event_time
323
+ self.id = id
324
+ self.status = status
325
+ self.participants = participants
326
+
327
+ @classmethod
328
+ def from_dict(cls, data: dict[Any, Any]) -> "Dialog":
329
+ return cls(
330
+ cid=data.get("cid"),
331
+ owner=data["owner"],
332
+ has_bots=data.get("hasBots"),
333
+ join_time=data["joinTime"],
334
+ created=data["created"],
335
+ last_message=Message.from_dict(data["lastMessage"])
336
+ if data.get("lastMessage")
337
+ else None,
338
+ type=ChatType(data["type"]),
339
+ last_fire_delayed_error_time=data["lastFireDelayedErrorTime"],
340
+ last_delayed_update_time=data["lastDelayedUpdateTime"],
341
+ prev_message_id=data.get("prevMessageId"),
342
+ options=data.get("options", {}),
343
+ modified=data["modified"],
344
+ last_event_time=data["lastEventTime"],
345
+ id=data["id"],
346
+ status=data["status"],
347
+ participants=data["participants"],
348
+ )
349
+
350
+ @override
351
+ def __repr__(self) -> str:
352
+ return f"Dialog(id={self.id!r}, owner={self.owner!r}, type={self.type!r}, last_message={self.last_message!r})"
353
+
354
+ @override
355
+ def __str__(self) -> str:
356
+ return f"Dialog {self.id} ({self.type})"
357
+
358
+
359
+ class Chat:
360
+ def __init__(
361
+ self,
362
+ participants_count: int,
363
+ access: AccessType | str,
364
+ invited_by: int | None,
365
+ link: str | None,
366
+ chat_type: ChatType | str,
367
+ title: str | None,
368
+ last_fire_delayed_error_time: int,
369
+ last_delayed_update_time: int,
370
+ options: dict[str, bool],
371
+ base_raw_icon_url: str | None,
372
+ base_icon_url: str | None,
373
+ description: str | None,
374
+ modified: int,
375
+ id_: int,
376
+ admin_participants: dict[int, dict[Any, Any]],
377
+ participants: dict[int, int],
378
+ owner: int,
379
+ join_time: int,
380
+ created: int,
381
+ last_message: Message | None,
382
+ prev_message_id: str | None,
383
+ last_event_time: int,
384
+ messages_count: int,
385
+ admins: list[int],
386
+ restrictions: int | None,
387
+ status: str,
388
+ cid: int,
389
+ ) -> None:
390
+ self.participants_count = participants_count
391
+ self.access = access
392
+ self.invited_by = invited_by
393
+ self.link = link
394
+ self.type = chat_type
395
+ self.title = title
396
+ self.last_fire_delayed_error_time = last_fire_delayed_error_time
397
+ self.last_delayed_update_time = last_delayed_update_time
398
+ self.options = options
399
+ self.base_raw_icon_url = base_raw_icon_url
400
+ self.base_icon_url = base_icon_url
401
+ self.description = description
402
+ self.modified = modified
403
+ self.id = id_
404
+ self.admin_participants = admin_participants
405
+ self.participants = participants
406
+ self.owner = owner
407
+ self.join_time = join_time
408
+ self.created = created
409
+ self.last_message = last_message
410
+ self.prev_message_id = prev_message_id
411
+ self.last_event_time = last_event_time
412
+ self.messages_count = messages_count
413
+ self.admins = admins
414
+ self.restrictions = restrictions
415
+ self.status = status
416
+ self.cid = cid
417
+
418
+ @classmethod
419
+ def from_dict(cls, data: dict[Any, Any]) -> "Chat":
420
+ raw_admins = data.get("adminParticipants", {}) or {}
421
+ admin_participants: dict[int, dict[Any, Any]] = {
422
+ int(k): v for k, v in raw_admins.items()
423
+ }
424
+ raw_participants = data.get("participants", {}) or {}
425
+ participants: dict[int, int] = {int(k): v for k, v in raw_participants.items()}
426
+ last_msg = (
427
+ Message.from_dict(data["lastMessage"]) if data.get("lastMessage") else None
428
+ )
429
+ return cls(
430
+ participants_count=data.get("participantsCount", 0),
431
+ access=AccessType(data.get("access", AccessType.PUBLIC.value)),
432
+ invited_by=data.get("invitedBy"),
433
+ link=data.get("link"),
434
+ base_raw_icon_url=data.get("baseRawIconUrl"),
435
+ base_icon_url=data.get("baseIconUrl"),
436
+ description=data.get("description"),
437
+ chat_type=ChatType(data.get("type", ChatType.CHAT.value)),
438
+ title=data.get("title"),
439
+ last_fire_delayed_error_time=data.get("lastFireDelayedErrorTime", 0),
440
+ last_delayed_update_time=data.get("lastDelayedUpdateTime", 0),
441
+ options=data.get("options", {}),
442
+ modified=data.get("modified", 0),
443
+ id_=data.get("id", 0),
444
+ admin_participants=admin_participants,
445
+ participants=participants,
446
+ owner=data.get("owner", 0),
447
+ join_time=data.get("joinTime", 0),
448
+ created=data.get("created", 0),
449
+ last_message=last_msg,
450
+ prev_message_id=data.get("prevMessageId"),
451
+ last_event_time=data.get("lastEventTime", 0),
452
+ messages_count=data.get("messagesCount", 0),
453
+ admins=data.get("admins", []),
454
+ restrictions=data.get("restrictions"),
455
+ status=data.get("status", ""),
456
+ cid=data.get("cid", 0),
457
+ )
458
+
459
+ @override
460
+ def __repr__(self) -> str:
461
+ return f"Chat(id={self.id!r}, title={self.title!r}, type={self.type!r})"
462
+
463
+ @override
464
+ def __str__(self) -> str:
465
+ return f"{self.title} ({self.type})"
466
+
467
+
468
+ class Channel(Chat):
469
+ @override
470
+ def __repr__(self) -> str:
471
+ return f"Channel(id={self.id!r}, title={self.title!r})"
472
+
473
+ @override
474
+ def __str__(self) -> str:
475
+ return f"Channel: {self.title}"
476
+
477
+
478
+ class User:
479
+ def __init__(
480
+ self,
481
+ account_status: int,
482
+ update_time: int,
483
+ id: int,
484
+ names: list[Names],
485
+ options: list[str] | None = None,
486
+ base_url: str | None = None,
487
+ base_raw_url: str | None = None,
488
+ photo_id: int | None = None,
489
+ description: str | None = None,
490
+ gender: int | None = None,
491
+ link: str | None = None,
492
+ web_app: str | None = None,
493
+ menu_button: dict[str, Any] | None = None,
494
+ ) -> None:
495
+ self.account_status = account_status
496
+ self.update_time = update_time
497
+ self.id = id
498
+ self.names = names
499
+ self.options = options or []
500
+ self.base_url = base_url
501
+ self.base_raw_url = base_raw_url
502
+ self.photo_id = photo_id
503
+ self.description = description
504
+ self.gender = gender
505
+ self.link = link
506
+ self.web_app = web_app
507
+ self.menu_button = menu_button
508
+
509
+ @classmethod
510
+ def from_dict(cls, data: dict[str, Any]) -> "User":
511
+ return cls(
512
+ account_status=data["accountStatus"],
513
+ update_time=data["updateTime"],
514
+ id=data["id"],
515
+ names=[Names.from_dict(n) for n in data.get("names", [])],
516
+ options=data.get("options"),
517
+ base_url=data.get("baseUrl"),
518
+ base_raw_url=data.get("baseRawUrl"),
519
+ photo_id=data.get("photoId"),
520
+ description=data.get("description"),
521
+ gender=data.get("gender"),
522
+ link=data.get("link"),
523
+ web_app=data.get("webApp"),
524
+ menu_button=data.get("menuButton"),
525
+ )
526
+
527
+ @override
528
+ def __repr__(self) -> str:
529
+ return f"User(id={self.id!r}, names={self.names!r}, status={self.account_status!r})"
530
+
531
+ @override
532
+ def __str__(self) -> str:
533
+ return f"User {self.id}: {', '.join(str(n) for n in self.names)}"
534
+
535
+
536
+ class Attach: # УБРАТЬ ГАДА!!!
537
+ def __init__(
538
+ self,
539
+ _type: AttachType,
540
+ video_id: int | None = None,
541
+ photo_token: str | None = None,
542
+ file_id: int | None = None,
543
+ token: str | None = None,
544
+ ) -> None:
545
+ self.type = _type
546
+ self.video_id = video_id
547
+ self.photo_token = photo_token
548
+ self.file_id = file_id
549
+ self.token = token
550
+
551
+ @classmethod
552
+ def from_dict(cls, data: dict[str, Any]) -> "Attach":
553
+ return cls(
554
+ _type=AttachType(data["type"]),
555
+ video_id=data.get("videoId"),
556
+ photo_token=data.get("photoToken"),
557
+ file_id=data.get("fileId"),
558
+ token=data.get("token"),
559
+ )
560
+
561
+ @override
562
+ def __repr__(self) -> str:
563
+ return (
564
+ f"Attach(type={self.type!r}, video_id={self.video_id!r}, "
565
+ f"photo_token={self.photo_token!r}, file_id={self.file_id!r}, token={self.token!r})"
566
+ )
567
+
568
+ @override
569
+ def __str__(self) -> str:
570
+ return f"Attach: {self.type}"